net: no longer acquire RTNL in threaded_show()
Subsystems (2)
PATCH 1/1 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 Eric Dumazet <[email protected]>
--- include/linux/netdevice.h | 2 +- net/core/dev.c | 4 ++-- net/core/net-sysfs.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
include/linux/netdevice.h +1 -1
@@ -2370,8 +2370,8 @@ struct net_device {struct sfp_bus *sfp_bus;struct lock_class_key *qdisc_tx_busylock;bool proto_down; +bool threaded; unsigned wol_enabled:1; - unsigned threaded:1;struct list_head net_notifier_list;
net/core/dev.c +2 -2
@@ -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 * is set.
@@ -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(). */ if (dev->threaded &&napi_kthread_create (napi)) - dev->threaded =0 ; + dev->threaded = false;netif_napi_set_irq (napi,-1 ); }EXPORT_SYMBOL (netif_napi_add_weight);
net/core/net-sysfs.c +4 -4
@@ -605,13 +605,13 @@ static ssize_t threaded_show(struct device *dev,struct net_device *netdev =to_net_dev (dev);ssize_t ret = -EINVAL ; -if (!rtnl_trylock ()) -return restart_syscall (); +rcu_read_lock ();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; }
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Thu, 2 May 2024 17:39:26 +0000 you wrote:
dev->threadedcan be read locklessly, if we add corresponding READ_ONCE()/WRITE_ONCE() annotations.Signed-off-by Eric Dumazet <[email protected]>--- include/linux/netdevice.h | 2 +- net/core/dev.c | 4 ++-- net/core/net-sysfs.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
Here is the summary with links:
- [net-next] net: no longer acquire RTNL in threaded_show()
https://git.kernel.org/netdev/net-next/c/c1742dcb6bda
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html