netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net-next v2] sched: sch_api: add missing rcu read lock to silence the warning
@ 2020-07-20  8:10 Jiri Pirko
  2020-07-21 18:57 ` Cong Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Pirko @ 2020-07-20  8:10 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jhs, xiyou.wangcong, idosch, mlxsw

From: Jiri Pirko <jiri@mellanox.com>

In case the qdisc_match_from_root function() is called from non-rcu path
with rtnl mutex held, a suspiciout rcu usage warning appears:

[  241.504354] =============================
[  241.504358] WARNING: suspicious RCU usage
[  241.504366] 5.8.0-rc4-custom-01521-g72a7c7d549c3 #32 Not tainted
[  241.504370] -----------------------------
[  241.504378] net/sched/sch_api.c:270 RCU-list traversed in non-reader section!!
[  241.504382]
               other info that might help us debug this:
[  241.504388]
               rcu_scheduler_active = 2, debug_locks = 1
[  241.504394] 1 lock held by tc/1391:
[  241.504398]  #0: ffffffff85a27850 (rtnl_mutex){+.+.}-{3:3}, at: rtnetlink_rcv_msg+0x49a/0xbd0
[  241.504431]
               stack backtrace:
[  241.504440] CPU: 0 PID: 1391 Comm: tc Not tainted 5.8.0-rc4-custom-01521-g72a7c7d549c3 #32
[  241.504446] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-2.fc32 04/01/2014
[  241.504453] Call Trace:
[  241.504465]  dump_stack+0x100/0x184
[  241.504482]  lockdep_rcu_suspicious+0x153/0x15d
[  241.504499]  qdisc_match_from_root+0x293/0x350

Fix this by passing the rtnl held lockdep condition down to
hlist_for_each_entry_rcu()

Reported-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
v1->v2:
- reworked to use the lockdep condition passing suggested by Ido.
---
 include/linux/hashtable.h | 4 ++--
 net/sched/sch_api.c       | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/linux/hashtable.h b/include/linux/hashtable.h
index 78b6ea5fa8ba..f6c666730b8c 100644
--- a/include/linux/hashtable.h
+++ b/include/linux/hashtable.h
@@ -173,9 +173,9 @@ static inline void hash_del_rcu(struct hlist_node *node)
  * @member: the name of the hlist_node within the struct
  * @key: the key of the objects to iterate over
  */
-#define hash_for_each_possible_rcu(name, obj, member, key)		\
+#define hash_for_each_possible_rcu(name, obj, member, key, cond...)	\
 	hlist_for_each_entry_rcu(obj, &name[hash_min(key, HASH_BITS(name))],\
-		member)
+		member, ## cond)
 
 /**
  * hash_for_each_possible_rcu_notrace - iterate over all possible objects hashing
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 11ebba60da3b..2a76a2f5ed88 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -267,7 +267,8 @@ static struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle)
 	    root->handle == handle)
 		return root;
 
-	hash_for_each_possible_rcu(qdisc_dev(root)->qdisc_hash, q, hash, handle) {
+	hash_for_each_possible_rcu(qdisc_dev(root)->qdisc_hash, q, hash, handle,
+				   lockdep_rtnl_is_held()) {
 		if (q->handle == handle)
 			return q;
 	}
-- 
2.21.3


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

* Re: [patch net-next v2] sched: sch_api: add missing rcu read lock to silence the warning
  2020-07-20  8:10 [patch net-next v2] sched: sch_api: add missing rcu read lock to silence the warning Jiri Pirko
@ 2020-07-21 18:57 ` Cong Wang
  2020-07-22 10:53   ` Jiri Pirko
  0 siblings, 1 reply; 3+ messages in thread
From: Cong Wang @ 2020-07-21 18:57 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: Linux Kernel Network Developers, David Miller, Jakub Kicinski,
	Jamal Hadi Salim, Ido Schimmel, mlxsw

On Mon, Jul 20, 2020 at 1:10 AM Jiri Pirko <jiri@resnulli.us> wrote:
> diff --git a/include/linux/hashtable.h b/include/linux/hashtable.h
> index 78b6ea5fa8ba..f6c666730b8c 100644
> --- a/include/linux/hashtable.h
> +++ b/include/linux/hashtable.h
> @@ -173,9 +173,9 @@ static inline void hash_del_rcu(struct hlist_node *node)
>   * @member: the name of the hlist_node within the struct
>   * @key: the key of the objects to iterate over
>   */

I think you need to update the doc here too, that is adding @cond.

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

* Re: [patch net-next v2] sched: sch_api: add missing rcu read lock to silence the warning
  2020-07-21 18:57 ` Cong Wang
@ 2020-07-22 10:53   ` Jiri Pirko
  0 siblings, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2020-07-22 10:53 UTC (permalink / raw)
  To: Cong Wang
  Cc: Linux Kernel Network Developers, David Miller, Jakub Kicinski,
	Jamal Hadi Salim, Ido Schimmel, mlxsw

Tue, Jul 21, 2020 at 08:57:45PM CEST, xiyou.wangcong@gmail.com wrote:
>On Mon, Jul 20, 2020 at 1:10 AM Jiri Pirko <jiri@resnulli.us> wrote:
>> diff --git a/include/linux/hashtable.h b/include/linux/hashtable.h
>> index 78b6ea5fa8ba..f6c666730b8c 100644
>> --- a/include/linux/hashtable.h
>> +++ b/include/linux/hashtable.h
>> @@ -173,9 +173,9 @@ static inline void hash_del_rcu(struct hlist_node *node)
>>   * @member: the name of the hlist_node within the struct
>>   * @key: the key of the objects to iterate over
>>   */
>
>I think you need to update the doc here too, that is adding @cond.

Ah, sure, will send v3. Thanks!

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

end of thread, other threads:[~2020-07-22 10:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  8:10 [patch net-next v2] sched: sch_api: add missing rcu read lock to silence the warning Jiri Pirko
2020-07-21 18:57 ` Cong Wang
2020-07-22 10:53   ` Jiri Pirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).