All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC RT v5.10] [rt] repair usage of dev_base_lock in netstat_show()
@ 2021-10-05  1:51 Luis Claudio R. Goncalves
  2021-10-11 13:56 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 12+ messages in thread
From: Luis Claudio R. Goncalves @ 2021-10-05  1:51 UTC (permalink / raw)
  To: linux-rt-users, Steven Rostedt, stable-rt
  Cc: Sebastian Andrzej Siewior, Nitesh Narayan Lal, Pei Zhang

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@redhat.com>
Signed-off-by: Nitesh Narayan Lal <nilal@redhat.com>
Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
---
 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;
 }
 


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-11-29 13:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05  1:51 [RFC RT v5.10] [rt] repair usage of dev_base_lock in netstat_show() Luis Claudio R. Goncalves
2021-10-11 13:56 ` Sebastian Andrzej Siewior
2021-10-11 16:36   ` Sebastian Andrzej Siewior
2021-10-18 15:42     ` Luis Goncalves
2021-11-04 18:58       ` Luis Goncalves
2021-11-25  1:39         ` Luis Goncalves
2021-11-25 10:01           ` Sebastian Andrzej Siewior
2021-11-25 11:11             ` Sebastian Andrzej Siewior
2021-11-26 12:09               ` Luis Goncalves
2021-11-26 13:24                 ` Luis Goncalves
2021-11-26 16:15                   ` [PATCH net-next] net: Write lock dev_base_lock without disabling bottom halves Sebastian Andrzej Siewior
2021-11-29 12:20                     ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.