diff mbox

[v2] rhashtable: Kill harmless RCU warning in rhashtable_walk_init

Message ID 20151219024528.GA27814@gondor.apana.org.au
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Herbert Xu Dec. 19, 2015, 2:45 a.m. UTC
On Fri, Dec 18, 2015 at 04:27:31PM -0500, David Miller wrote:
> From: Herbert Xu <herbert@gondor.apana.org.au>
> Date: Fri, 18 Dec 2015 21:14:08 +0800
> 
> > On Fri, Dec 18, 2015 at 04:54:14AM -0800, Eric Dumazet wrote:
> >>
> >> You can avoid the comment by using the self documented and lockdep
> >> enabled primitive
> >> 
> >> iter->walker->tbl = rcu_dereference_protected(ht->tbl,
> >> 					      lockdep_is_held(&ht->lock));
> > 
> > That is just gross.  I think a comment is much better in this case.
> 
> Herbert, this macro was created exactly to handle this situation,
> and this is what we do everywhere else in the tree.

OK.

---8<---
The commit f9f51b8070be3e829100614a7372b219723b864f ("rhashtable:
Fix walker list corruption") causes a suspicious RCU usage warning
because we no longer hold ht->mutex when we dereference ht->tbl.

However, this is a false positive because we now hold ht->lock
which also guarantees that ht->tbl won't disppear from under us.

This patch kills the warning by using rcu_dereference_protected.

Reported-by: kernel test robot <ying.huang@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

David Miller Dec. 19, 2015, 4:42 a.m. UTC | #1
From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Sat, 19 Dec 2015 10:45:28 +0800

> On Fri, Dec 18, 2015 at 04:27:31PM -0500, David Miller wrote:
>> From: Herbert Xu <herbert@gondor.apana.org.au>
>> Date: Fri, 18 Dec 2015 21:14:08 +0800
>> 
>> > On Fri, Dec 18, 2015 at 04:54:14AM -0800, Eric Dumazet wrote:
>> >>
>> >> You can avoid the comment by using the self documented and lockdep
>> >> enabled primitive
>> >> 
>> >> iter->walker->tbl = rcu_dereference_protected(ht->tbl,
>> >> 					      lockdep_is_held(&ht->lock));
>> > 
>> > That is just gross.  I think a comment is much better in this case.
>> 
>> Herbert, this macro was created exactly to handle this situation,
>> and this is what we do everywhere else in the tree.
> 
> OK.
> 
> ---8<---
> The commit f9f51b8070be3e829100614a7372b219723b864f ("rhashtable:
> Fix walker list corruption") causes a suspicious RCU usage warning
> because we no longer hold ht->mutex when we dereference ht->tbl.
> 
> However, this is a false positive because we now hold ht->lock
> which also guarantees that ht->tbl won't disppear from under us.
> 
> This patch kills the warning by using rcu_dereference_protected.
> 
> Reported-by: kernel test robot <ying.huang@linux.intel.com>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

The correct commti SHA1 is c6ff5268293ef98e48a99597e765ffc417e39fa5.

Or at least, when I run:

	git show f9f51b8070be3e829100614a7372b219723b864f

I get:

	fatal: bad object f9f51b8070be3e829100614a7372b219723b864f

:-)

I fixed this up and applied this, thanks!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
kbuild test robot Dec. 19, 2015, 4:47 a.m. UTC | #2
On Fri, Dec 18, 2015 at 11:42:59PM -0500, David Miller wrote:
> From: Herbert Xu <herbert@gondor.apana.org.au>
> Date: Sat, 19 Dec 2015 10:45:28 +0800
> 
> > On Fri, Dec 18, 2015 at 04:27:31PM -0500, David Miller wrote:
> >> From: Herbert Xu <herbert@gondor.apana.org.au>
> >> Date: Fri, 18 Dec 2015 21:14:08 +0800
> >> 
> >> > On Fri, Dec 18, 2015 at 04:54:14AM -0800, Eric Dumazet wrote:
> >> >>
> >> >> You can avoid the comment by using the self documented and lockdep
> >> >> enabled primitive
> >> >> 
> >> >> iter->walker->tbl = rcu_dereference_protected(ht->tbl,
> >> >> 					      lockdep_is_held(&ht->lock));
> >> > 
> >> > That is just gross.  I think a comment is much better in this case.
> >> 
> >> Herbert, this macro was created exactly to handle this situation,
> >> and this is what we do everywhere else in the tree.
> > 
> > OK.
> > 
> > ---8<---
> > The commit f9f51b8070be3e829100614a7372b219723b864f ("rhashtable:
> > Fix walker list corruption") causes a suspicious RCU usage warning
> > because we no longer hold ht->mutex when we dereference ht->tbl.
> > 
> > However, this is a false positive because we now hold ht->lock
> > which also guarantees that ht->tbl won't disppear from under us.
> > 
> > This patch kills the warning by using rcu_dereference_protected.
> > 
> > Reported-by: kernel test robot <ying.huang@linux.intel.com>
> > Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> The correct commti SHA1 is c6ff5268293ef98e48a99597e765ffc417e39fa5.
> 
> Or at least, when I run:
> 
> 	git show f9f51b8070be3e829100614a7372b219723b864f
> 
> I get:
> 
> 	fatal: bad object f9f51b8070be3e829100614a7372b219723b864f
> 
> :-)

Oops, that commit comes from 0day robot :-)

> https://github.com/0day-ci/linux Herbert-Xu/rhashtable-Fix-walker-list-corruption/20151216-164833
> commit f9f51b8070be3e829100614a7372b219723b864f ("rhashtable: Fix walker list corruption")

        commit f9f51b8070be3e829100614a7372b219723b864f
        Author:     Herbert Xu <herbert@gondor.apana.org.au>
        AuthorDate: Wed Dec 16 16:45:54 2015 +0800
        Commit:     0day robot <fengguang.wu@intel.com>
        CommitDate: Wed Dec 16 16:48:36 2015 +0800

            rhashtable: Fix walker list corruption

Thanks,
Fengguang
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index eb9240c..51282f5 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -519,7 +519,8 @@  int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter)
 		return -ENOMEM;
 
 	spin_lock(&ht->lock);
-	iter->walker->tbl = rht_dereference(ht->tbl, ht);
+	iter->walker->tbl =
+		rcu_dereference_protected(ht->tbl, lockdep_is_held(&ht->lock));
 	list_add(&iter->walker->list, &iter->walker->tbl->walkers);
 	spin_unlock(&ht->lock);