Commit c1742dcb authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

net: no longer acquire RTNL in threaded_show()

dev->threaded can be read locklessly, if we add
corresponding READ_ONCE()/WRITE_ONCE() annotations.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20240502173926.2010646-1-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 3e51f2cb
...@@ -2370,8 +2370,8 @@ struct net_device { ...@@ -2370,8 +2370,8 @@ struct net_device {
struct sfp_bus *sfp_bus; struct sfp_bus *sfp_bus;
struct lock_class_key *qdisc_tx_busylock; struct lock_class_key *qdisc_tx_busylock;
bool proto_down; bool proto_down;
bool threaded;
unsigned wol_enabled:1; unsigned wol_enabled:1;
unsigned threaded:1;
struct list_head net_notifier_list; struct list_head net_notifier_list;
......
...@@ -6531,7 +6531,7 @@ int dev_set_threaded(struct net_device *dev, bool threaded) ...@@ -6531,7 +6531,7 @@ int dev_set_threaded(struct net_device *dev, bool threaded)
} }
} }
dev->threaded = threaded; WRITE_ONCE(dev->threaded, threaded);
/* Make sure kthread is created before THREADED bit /* Make sure kthread is created before THREADED bit
* is set. * is set.
...@@ -6622,7 +6622,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, ...@@ -6622,7 +6622,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
* threaded mode will not be enabled in napi_enable(). * threaded mode will not be enabled in napi_enable().
*/ */
if (dev->threaded && napi_kthread_create(napi)) if (dev->threaded && napi_kthread_create(napi))
dev->threaded = 0; dev->threaded = false;
netif_napi_set_irq(napi, -1); netif_napi_set_irq(napi, -1);
} }
EXPORT_SYMBOL(netif_napi_add_weight); EXPORT_SYMBOL(netif_napi_add_weight);
......
...@@ -605,13 +605,13 @@ static ssize_t threaded_show(struct device *dev, ...@@ -605,13 +605,13 @@ static ssize_t threaded_show(struct device *dev,
struct net_device *netdev = to_net_dev(dev); struct net_device *netdev = to_net_dev(dev);
ssize_t ret = -EINVAL; ssize_t ret = -EINVAL;
if (!rtnl_trylock()) rcu_read_lock();
return restart_syscall();
if (dev_isalive(netdev)) if (dev_isalive(netdev))
ret = sysfs_emit(buf, fmt_dec, netdev->threaded); ret = sysfs_emit(buf, fmt_dec, READ_ONCE(netdev->threaded));
rcu_read_unlock();
rtnl_unlock();
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment