radix tree test suite: iteration test misuses RCU
PATCH 85/114 radix tree test suite: iteration test misuses RCU
From: Matthew Wilcox <[email protected]>
Subject: radix tree test suite: iteration test misuses RCU
Each thread needs to register itself with RCU, otherwise the reading thread's read lock has no effect and the freeing thread will free the memory in the tree without waiting for the read lock to be dropped.
Signed-off-by Matthew Wilcox <[email protected]>
Tested-by Kirill A. Shutemov <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Matthew Wilcox <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
tools/testing/radix-tree/iteration_check.c | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
tools/testing/radix-tree/iteration_check.c renamed from tools/testing/radix-tree/iteration_check.c~radix-tree-test-suite-iteration-test-misuses-rcu +26 -2
@@ -29,6 +29,8 @@ static void *add_entries_fn(void *arg) {int pgoff; +rcu_register_thread (); +while (!test_complete) {for (pgoff =0 ; pgoff <100 ; pgoff++) {pthread_mutex_lock (&tree_lock);
@@ -38,6 +40,8 @@ static void *add_entries_fn(void *arg) } } +rcu_unregister_thread (); +return NULL ; }
@@ -53,6 +57,8 @@ static void *tagged_iteration_fn(void *astruct radix_tree_iter iter;void **slot; +rcu_register_thread (); +while (!test_complete) {rcu_read_lock ();radix_tree_for_each_tagged (slot, &tree, &iter,0 ,TAG ) {
@@ -72,12 +78,18 @@ static void *tagged_iteration_fn(void *acontinue ; } -if (rand_r (&seeds[0 ]) %50 ==0 ) +if (rand_r (&seeds[0 ]) %50 ==0 ) { slot =radix_tree_iter_next (&iter); +rcu_read_unlock (); +rcu_barrier (); +rcu_read_lock (); + } }rcu_read_unlock (); } +rcu_unregister_thread (); +return NULL ; }
@@ -93,6 +105,8 @@ static void *untagged_iteration_fn(voidstruct radix_tree_iter iter;void **slot; +rcu_register_thread (); +while (!test_complete) {rcu_read_lock ();radix_tree_for_each_slot (slot, &tree, &iter,0 ) {
@@ -112,12 +126,18 @@ static void *untagged_iteration_fn(voidcontinue ; } -if (rand_r (&seeds[1 ]) %50 ==0 ) +if (rand_r (&seeds[1 ]) %50 ==0 ) { slot =radix_tree_iter_next (&iter); +rcu_read_unlock (); +rcu_barrier (); +rcu_read_lock (); + } }rcu_read_unlock (); } +rcu_unregister_thread (); +return NULL ; }
@@ -127,6 +147,8 @@ static void *untagged_iteration_fn(void*/ static void *remove_entries_fn (void *arg) { +rcu_register_thread (); +while (!test_complete) {int pgoff;
@@ -137,6 +159,8 @@ static void *remove_entries_fn(void *argpthread_mutex_unlock (&tree_lock); } +rcu_unregister_thread (); +return NULL ; }
_