All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] test_rhashtable: Add missing rcu_read_lock()
@ 2018-03-08 11:54 Paul Blakey
  2018-03-08 15:58 ` Herbert Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Blakey @ 2018-03-08 11:54 UTC (permalink / raw)
  To: Thomas Graf, Herbert Xu, David Miller; +Cc: netdev, Paul Blakey

Suppress "suspicious rcu_dereference_protected() usage!" on duplicate
insertion test.

Fixes: 499ac3b60f65 ('test_rhashtable: add test case for rhl_table with duplicate objects')
Signed-off-by: Paul Blakey <paulb@mellanox.com>
---
 lib/test_rhashtable.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
index f4000c1..727d3ec 100644
--- a/lib/test_rhashtable.c
+++ b/lib/test_rhashtable.c
@@ -498,14 +498,16 @@ static unsigned int __init print_ht(struct rhltable *rhlt)
 	char buff[512] = "";
 	unsigned int i, cnt = 0;
 
+	rcu_read_lock();
+
 	ht = &rhlt->ht;
-	tbl = rht_dereference(ht->tbl, ht);
+	tbl = rht_dereference_rcu(ht->tbl, ht);
 	for (i = 0; i < tbl->size; i++) {
 		struct rhash_head *pos, *next;
 		struct test_obj_rhl *p;
 
-		pos = rht_dereference(tbl->buckets[i], ht);
-		next = !rht_is_a_nulls(pos) ? rht_dereference(pos->next, ht) : NULL;
+		pos = rht_dereference_rcu(tbl->buckets[i], ht);
+		next = !rht_is_a_nulls(pos) ? rht_dereference_rcu(pos->next, ht) : NULL;
 
 		if (!rht_is_a_nulls(pos)) {
 			sprintf(buff, "%s\nbucket[%d] -> ", buff, i);
@@ -516,7 +518,7 @@ static unsigned int __init print_ht(struct rhltable *rhlt)
 			sprintf(buff, "%s[[", buff);
 			do {
 				pos = &list->rhead;
-				list = rht_dereference(list->next, ht);
+				list = rht_dereference_rcu(list->next, ht);
 				p = rht_obj(ht, pos);
 
 				sprintf(buff, "%s val %d (tid=%d)%s", buff, p->value.id, p->value.tid,
@@ -526,13 +528,15 @@ static unsigned int __init print_ht(struct rhltable *rhlt)
 
 			pos = next,
 			next = !rht_is_a_nulls(pos) ?
-				rht_dereference(pos->next, ht) : NULL;
+				rht_dereference_rcu(pos->next, ht) : NULL;
 
 			sprintf(buff, "%s]]%s", buff, !rht_is_a_nulls(pos) ? " -> " : "");
 		}
 	}
 	printk(KERN_ERR "\n---- ht: ----%s\n-------------\n", buff);
 
+	rcu_read_unlock();
+
 	return cnt;
 }
 
-- 
1.8.4.3

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

* Re: [PATCH net] test_rhashtable: Add missing rcu_read_lock()
  2018-03-08 11:54 [PATCH net] test_rhashtable: Add missing rcu_read_lock() Paul Blakey
@ 2018-03-08 15:58 ` Herbert Xu
  2018-03-08 17:10   ` Paul Blakey
  0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2018-03-08 15:58 UTC (permalink / raw)
  To: Paul Blakey; +Cc: Thomas Graf, David Miller, netdev

On Thu, Mar 08, 2018 at 01:54:57PM +0200, Paul Blakey wrote:
> Suppress "suspicious rcu_dereference_protected() usage!" on duplicate
> insertion test.
> 
> Fixes: 499ac3b60f65 ('test_rhashtable: add test case for rhl_table with duplicate objects')
> Signed-off-by: Paul Blakey <paulb@mellanox.com>

This shouldn't be doing a table walk in the first place.

You should convert it to using the table walk interface.

Direct table walks are forbidden because they will break when
you hit a resize.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH net] test_rhashtable: Add missing rcu_read_lock()
  2018-03-08 15:58 ` Herbert Xu
@ 2018-03-08 17:10   ` Paul Blakey
  2018-03-09 15:04     ` Herbert Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Blakey @ 2018-03-08 17:10 UTC (permalink / raw)
  To: Herbert Xu; +Cc: paulb, Thomas Graf, David Miller, netdev



On 08/03/2018 17:58, Herbert Xu wrote:
> On Thu, Mar 08, 2018 at 01:54:57PM +0200, Paul Blakey wrote:
>> Suppress "suspicious rcu_dereference_protected() usage!" on duplicate
>> insertion test.
>>
>> Fixes: 499ac3b60f65 ('test_rhashtable: add test case for rhl_table with duplicate objects')
>> Signed-off-by: Paul Blakey <paulb@mellanox.com>
> 
> This shouldn't be doing a table walk in the first place.
> 
> You should convert it to using the table walk interface.
> 
> Direct table walks are forbidden because they will break when
> you hit a resize.
> 
> Cheers,
> 


I know but I wanted to show the inner structure for the failure case, 
iirc walk doesn't provide this.

                ---- ht: ----
                bucket[1] -> [[ val 1 (tid=0) ]] -> [[ val 21 (tid=1) ]]
                -------------
[ 3599.715501]
                ---- ht: ----
                bucket[1] -> [[ val 1 (tid=2),  val 1 (tid=0) ]] -> [[ 
val 21 (tid=1) ]]
                -------------
[ 3599.738600]
                ---- ht: ----
                bucket[1] -> [[ val 21 (tid=1) ]] -> [[ val 1 (tid=0) ]]
                -------------
[ 3599.759443]
                ---- ht: ----
                bucket[1] -> [[ val 21 (tid=1) ]] -> [[ val 1 (tid=2), 
val 1 (tid=0) ]]

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

* Re: [PATCH net] test_rhashtable: Add missing rcu_read_lock()
  2018-03-08 17:10   ` Paul Blakey
@ 2018-03-09 15:04     ` Herbert Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2018-03-09 15:04 UTC (permalink / raw)
  To: Paul Blakey; +Cc: Thomas Graf, David Miller, netdev

On Thu, Mar 08, 2018 at 07:10:47PM +0200, Paul Blakey wrote:
>
> I know but I wanted to show the inner structure for the failure case, iirc
> walk doesn't provide this.

Fair enough.

Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2018-03-09 15:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-08 11:54 [PATCH net] test_rhashtable: Add missing rcu_read_lock() Paul Blakey
2018-03-08 15:58 ` Herbert Xu
2018-03-08 17:10   ` Paul Blakey
2018-03-09 15:04     ` Herbert Xu

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.