Skip to content

Commit 8792515

Browse files
Edward Creekuba-moo
authored andcommitted
net: ethtool: add a mutex protecting RSS contexts
While this is not needed to serialise the ethtool entry points (which are all under RTNL), drivers may have cause to asynchronously access dev->ethtool->rss_ctx; taking dev->ethtool->rss_lock allows them to do this safely without needing to take the RTNL. Signed-off-by: Edward Cree <[email protected]> Reviewed-by: Przemek Kitszel <[email protected]> Link: https://patch.msgid.link/7f9c15eb7525bf87af62c275dde3a8570ee8bf0a.1719502240.git.ecree.xilinx@gmail.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 30a32cd commit 8792515

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

include/linux/ethtool.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,10 +1104,13 @@ int ethtool_virtdev_set_link_ksettings(struct net_device *dev,
11041104
/**
11051105
* struct ethtool_netdev_state - per-netdevice state for ethtool features
11061106
* @rss_ctx: XArray of custom RSS contexts
1107+
* @rss_lock: Protects entries in @rss_ctx. May be taken from
1108+
* within RTNL.
11071109
* @wol_enabled: Wake-on-LAN is enabled
11081110
*/
11091111
struct ethtool_netdev_state {
11101112
struct xarray rss_ctx;
1113+
struct mutex rss_lock;
11111114
unsigned wol_enabled:1;
11121115
};
11131116

net/core/dev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10338,6 +10338,7 @@ int register_netdevice(struct net_device *dev)
1033810338

1033910339
/* rss ctx ID 0 is reserved for the default context, start from 1 */
1034010340
xa_init_flags(&dev->ethtool->rss_ctx, XA_FLAGS_ALLOC1);
10341+
mutex_init(&dev->ethtool->rss_lock);
1034110342

1034210343
spin_lock_init(&dev->addr_list_lock);
1034310344
netdev_set_addr_lockdep_class(dev);
@@ -11243,6 +11244,7 @@ static void netdev_rss_contexts_free(struct net_device *dev)
1124311244
struct ethtool_rxfh_context *ctx;
1124411245
unsigned long context;
1124511246

11247+
mutex_lock(&dev->ethtool->rss_lock);
1124611248
xa_for_each(&dev->ethtool->rss_ctx, context, ctx) {
1124711249
struct ethtool_rxfh_param rxfh;
1124811250

@@ -11262,6 +11264,7 @@ static void netdev_rss_contexts_free(struct net_device *dev)
1126211264
kfree(ctx);
1126311265
}
1126411266
xa_destroy(&dev->ethtool->rss_ctx);
11267+
mutex_unlock(&dev->ethtool->rss_lock);
1126511268
}
1126611269

1126711270
/**
@@ -11374,6 +11377,8 @@ void unregister_netdevice_many_notify(struct list_head *head,
1137411377
if (dev->netdev_ops->ndo_uninit)
1137511378
dev->netdev_ops->ndo_uninit(dev);
1137611379

11380+
mutex_destroy(&dev->ethtool->rss_lock);
11381+
1137711382
if (skb)
1137811383
rtmsg_ifinfo_send(skb, dev, GFP_KERNEL, portid, nlh);
1137911384

net/ethtool/ioctl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
12851285
struct netlink_ext_ack *extack = NULL;
12861286
struct ethtool_rxnfc rx_rings;
12871287
struct ethtool_rxfh rxfh;
1288+
bool locked = false; /* dev->ethtool->rss_lock taken */
12881289
u32 indir_bytes = 0;
12891290
bool create = false;
12901291
u8 *rss_config;
@@ -1380,6 +1381,10 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
13801381
}
13811382
}
13821383

1384+
if (rxfh.rss_context) {
1385+
mutex_lock(&dev->ethtool->rss_lock);
1386+
locked = true;
1387+
}
13831388
if (create) {
13841389
if (rxfh_dev.rss_delete) {
13851390
ret = -EINVAL;
@@ -1495,6 +1500,8 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
14951500
}
14961501

14971502
out:
1503+
if (locked)
1504+
mutex_unlock(&dev->ethtool->rss_lock);
14981505
kfree(rss_config);
14991506
return ret;
15001507
}

0 commit comments

Comments
 (0)