Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424351AbcKPWlO (ORCPT ); Wed, 16 Nov 2016 17:41:14 -0500 Received: from p3plsmtps2ded02.prod.phx3.secureserver.net ([208.109.80.59]:59520 "EHLO p3plsmtps2ded02.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941046AbcKPWfY (ORCPT ); Wed, 16 Nov 2016 17:35:24 -0500 x-originating-ip: 72.167.245.219 From: Matthew Wilcox To: linux-kernel@vger.kernel.org, Andrew Morton , Konstantin Khlebnikov , Ross Zwisler Cc: linux-fsdevel@vger.kernel.org, Matthew Wilcox , linux-mm@kvack.org, "Kirill A . Shutemov" Subject: [PATCH 19/29] radix tree test suite: iteration test misuses RCU Date: Wed, 16 Nov 2016 16:17:22 -0800 Message-Id: <1479341856-30320-58-git-send-email-mawilcox@linuxonhyperv.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> References: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> X-CMAE-Envelope: MS4wfC7gyTSeBxx+x4f2XL9XwexeU1IrJs4MMrfTSoDLLEB7MYdCsaqYWRCfdzZaGx67u9KAKrpDFT3rcTAG2kVFZJ5lRYc3N4sSyNC/CpSWb5PmkSJ4QHHq dmYPJqPM9lJh475rX7Ww8k5HcsQ7PlbZKHpzJn0CGefKRvoqfdMJysusIIFbD7Go3R1cllGS+wV2MK42gJkl0zh0o0PVMSXaJpwpYjzQO6W/02ucnqAJIFKw lnymGa0KQR5crmc8OplxRhqui7ZJ1aFPDxuNa0vAptuJ/htJLZpTykxtRyWp+C72ZG0O4dRV0w9szERz0dLOPvjuCuB8oW4yWNp/6Kx9b3/rSXNSapRrToAn VnY748XfU08XFcSZh5N5lUj/0egCyR/WbswpjBEcCvFKTMd7kGe1iNnv6OxwuhX5nh65hbveuJhcJ2atKFPG25VZzZyYAhnvkRzvXTsDLdKMfVFu5uE= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2553 Lines: 111 From: Matthew Wilcox 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 --- tools/testing/radix-tree/iteration_check.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/testing/radix-tree/iteration_check.c b/tools/testing/radix-tree/iteration_check.c index 11d570c..df71cb8 100644 --- a/tools/testing/radix-tree/iteration_check.c +++ b/tools/testing/radix-tree/iteration_check.c @@ -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 *arg) struct 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 *arg) continue; } - 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(void *arg) struct 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(void *arg) continue; } - 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 *arg) */ 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 *arg) pthread_mutex_unlock(&tree_lock); } + rcu_unregister_thread(); + return NULL; } -- 2.10.2