Avoid a possible circular locking dependency by taking the softirq_ctrl.lock before taking dev_base_lock in netstat_show(), keeping locking order consistent. Lockdep splat: [ 106.529733] ====================================================== [ 106.529734] WARNING: possible circular locking dependency detected [ 106.529734] 5.10.65-rt53+ #1 Tainted: G W I [ 106.529736] ------------------------------------------------------ [ 106.529736] tuned/2760 is trying to acquire lock: [ 106.529737] ffffa0695ea18220 ((softirq_ctrl.lock).lock){+.+.}-{2:2}, at: __local_bh_disable_ip+0x116/0x2f0 [ 106.529746] but task is already holding lock: [ 106.529746] ffffffff844af760 (dev_base_lock){++.+}-{0:0}, at: netstat_show.isra.17+0x4a/0xb0 [ 106.529752] which lock already depends on the new lock. ... [ 106.529825] other info that might help us debug this: [ 106.529826] Possible unsafe locking scenario: [ 106.529826] CPU0 CPU1 [ 106.529827] ---- ---- [ 106.529827] lock(dev_base_lock); [ 106.529828] lock((softirq_ctrl.lock).lock); [ 106.529829] lock(dev_base_lock); [ 106.529829] lock((softirq_ctrl.lock).lock); [ 106.529830] *** DEADLOCK *** [ 106.529831] 6 locks held by tuned/2760: [ 106.529832] #0: ffffa062296a6670 (&f->f_pos_lock){+.+.}-{0:0}, at: __fdget_pos+0x4b/0x60 [ 106.529836] #1: ffffa062223ae310 (&p->lock){+.+.}-{0:0}, at: seq_read_iter+0x56/0x420 [ 106.529839] #2: ffffa06242ea1ab8 (&of->mutex){+.+.}-{0:0}, at: kernfs_seq_start+0x28/0x90 [ 106.529842] #3: ffffa06268f52008 (kn->active#285){++++}-{0:0}, at: kernfs_seq_start+0x30/0x90 [ 106.529844] #4: ffffffff844af760 (dev_base_lock){++.+}-{0:0}, at: netstat_show.isra.17+0x4a/0xb0 [ 106.529848] #5: ffffffff840c8fa0 (rcu_read_lock){....}-{1:2}, at: rt_read_lock+0x7d/0x1e0 Reported-by: Pei Zhang <pezhang@xxxxxxxxxx> Signed-off-by: Nitesh Narayan Lal <nilal@xxxxxxxxxx> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@xxxxxxxxxx> --- net/core/net-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index f6197774048b..7291ca052632 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -625,14 +625,14 @@ static ssize_t netstat_show(const struct device *d, WARN_ON(offset > sizeof(struct rtnl_link_stats64) || offset % sizeof(u64) != 0); - read_lock(&dev_base_lock); + read_lock_bh(&dev_base_lock); if (dev_isalive(dev)) { struct rtnl_link_stats64 temp; const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset)); } - read_unlock(&dev_base_lock); + read_unlock_bh(&dev_base_lock); return ret; }