Skip to content

Commit c1742dc

Browse files
edumazetkuba-moo
authored andcommitted
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 <edumazet@google.com> Link: https://lore.kernel.org/r/20240502173926.2010646-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3e51f2c commit c1742dc

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,8 +2370,8 @@ struct net_device {
23702370
struct sfp_bus *sfp_bus;
23712371
struct lock_class_key *qdisc_tx_busylock;
23722372
bool proto_down;
2373+
bool threaded;
23732374
unsigned wol_enabled:1;
2374-
unsigned threaded:1;
23752375

23762376
struct list_head net_notifier_list;
23772377

net/core/dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6531,7 +6531,7 @@ int dev_set_threaded(struct net_device *dev, bool threaded)
65316531
}
65326532
}
65336533

6534-
dev->threaded = threaded;
6534+
WRITE_ONCE(dev->threaded, threaded);
65356535

65366536
/* Make sure kthread is created before THREADED bit
65376537
* is set.
@@ -6622,7 +6622,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
66226622
* threaded mode will not be enabled in napi_enable().
66236623
*/
66246624
if (dev->threaded && napi_kthread_create(napi))
6625-
dev->threaded = 0;
6625+
dev->threaded = false;
66266626
netif_napi_set_irq(napi, -1);
66276627
}
66286628
EXPORT_SYMBOL(netif_napi_add_weight);

net/core/net-sysfs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,13 @@ static ssize_t threaded_show(struct device *dev,
605605
struct net_device *netdev = to_net_dev(dev);
606606
ssize_t ret = -EINVAL;
607607

608-
if (!rtnl_trylock())
609-
return restart_syscall();
608+
rcu_read_lock();
610609

611610
if (dev_isalive(netdev))
612-
ret = sysfs_emit(buf, fmt_dec, netdev->threaded);
611+
ret = sysfs_emit(buf, fmt_dec, READ_ONCE(netdev->threaded));
612+
613+
rcu_read_unlock();
613614

614-
rtnl_unlock();
615615
return ret;
616616
}
617617

0 commit comments

Comments
 (0)