[PATCH net] test_rhashtable: Add missing rcu_read_lock()

Subsystems: library code, rhashtable, the rest

STALE3142d

4 messages, 2 authors, 2018-03-09 · open the first message on its own page

[PATCH net] test_rhashtable: Add missing rcu_read_lock()

From: Paul Blakey <hidden>
Date: 2018-03-08 11:55:06

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 <redacted>
---
 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

Re: [PATCH net] test_rhashtable: Add missing rcu_read_lock()

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2018-03-08 15:58:55

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 <redacted>
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 [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Re: [PATCH net] test_rhashtable: Add missing rcu_read_lock()

From: Paul Blakey <hidden>
Date: 2018-03-08 17:11:02


On 08/03/2018 17:58, Herbert Xu wrote:
On Thu, Mar 08, 2018 at 01:54:57PM +0200, Paul Blakey wrote:
quoted
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 <redacted>
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) ]]

Re: [PATCH net] test_rhashtable: Add missing rcu_read_lock()

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2018-03-09 15:05:01

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 [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help