RADIX_TREE() uses the static XArray initializer. Enforce static storage for this declaration wrapper, consistently with DEFINE_XARRAY_FLAGS() and DEFINE_IDR(). Leave RADIX_TREE_INIT() unchanged for embedded objects.
Normal radix-tree operations use external synchronization rather than the embedded XArray lock, so this is declaration-contract enforcement rather than a fix for a lockdep failure in normal radix-tree operations. Convert the thirteen automatic roots in the userspace tests and benchmark to plain declarations followed by INIT_RADIX_TREE(), preserving their allocation flags. Assisted-by: OpenAI Codex Signed-off-by: Yury Norov <[email protected]> --- include/linux/radix-tree.h | 4 +++- tools/testing/radix-tree/benchmark.c | 4 +++- tools/testing/radix-tree/main.c | 16 +++++++++++---- tools/testing/radix-tree/regression3.c | 4 +++- tools/testing/radix-tree/tag_check.c | 28 +++++++++++++++++++------- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h index 057edc4cbb6e..dc3795f4cb1f 100644 --- a/include/linux/radix-tree.h +++ b/include/linux/radix-tree.h @@ -8,6 +8,7 @@ #ifndef _LINUX_RADIX_TREE_H #define _LINUX_RADIX_TREE_H +#include <linux/compiler.h> #include <linux/bitops.h> #include <linux/gfp_types.h> #include <linux/list.h> @@ -79,7 +80,8 @@ static inline bool radix_tree_is_internal_node(void *ptr) #define RADIX_TREE_INIT(name, mask) XARRAY_INIT(name, mask) #define RADIX_TREE(name, mask) \ - struct radix_tree_root name = RADIX_TREE_INIT(name, mask) + struct radix_tree_root name = RADIX_TREE_INIT(name, mask); \ + ASSERT_STATIC_STORAGE(name) #define INIT_RADIX_TREE(root, mask) xa_init_flags(root, mask) diff --git a/tools/testing/radix-tree/benchmark.c b/tools/testing/radix-tree/benchmark.c index 523c79f22ed3..57ab92e6cd77 100644 --- a/tools/testing/radix-tree/benchmark.c +++ b/tools/testing/radix-tree/benchmark.c @@ -114,9 +114,11 @@ static void benchmark_delete(struct radix_tree_root *root, static void benchmark_size(unsigned long size, unsigned long step) { - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; long long normal, tagged; + INIT_RADIX_TREE(&tree, GFP_KERNEL); + benchmark_insert(&tree, size, step); benchmark_tagging(&tree, size, step); diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c index f2cbc8e5b97c..6f0f8eaa044d 100644 --- a/tools/testing/radix-tree/main.c +++ b/tools/testing/radix-tree/main.c @@ -15,7 +15,9 @@ void __gang_check(unsigned long middle, long down, long up, int chunk, int hop) { long idx; - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); middle = 1 << 30; @@ -78,7 +80,9 @@ void big_gang_check(bool long_run) void add_and_check(void) { - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); item_insert(&tree, 44); item_check_present(&tree, 44); @@ -89,7 +93,9 @@ void add_and_check(void) void dynamic_height_check(void) { int i; - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); tree_verify_min_height(&tree, 0); item_insert(&tree, 42); @@ -155,11 +161,13 @@ void check_copied_tags(struct radix_tree_root *tree, unsigned long start, unsign void copy_tag_check(void) { - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; unsigned long idx[ITEMS]; unsigned long start, end, count = 0, tagged, cur, tmp; int i; + INIT_RADIX_TREE(&tree, GFP_KERNEL); + // printf("generating radix tree indices...\n"); start = rand(); end = rand(); diff --git a/tools/testing/radix-tree/regression3.c b/tools/testing/radix-tree/regression3.c index 9f9a3b280f56..dc235bff0063 100644 --- a/tools/testing/radix-tree/regression3.c +++ b/tools/testing/radix-tree/regression3.c @@ -28,13 +28,15 @@ void regression3_test(void) { - RADIX_TREE(root, GFP_KERNEL); + struct radix_tree_root root; void *ptr0 = (void *)4ul; void *ptr = (void *)8ul; struct radix_tree_iter iter; void **slot; bool first; + INIT_RADIX_TREE(&root, GFP_KERNEL); + printv(1, "running regression test 3 (should take milliseconds)\n"); radix_tree_insert(&root, 0, ptr0); diff --git a/tools/testing/radix-tree/tag_check.c b/tools/testing/radix-tree/tag_check.c index f898957b1a19..51c0f0d6152c 100644 --- a/tools/testing/radix-tree/tag_check.c +++ b/tools/testing/radix-tree/tag_check.c @@ -42,7 +42,9 @@ __simple_checks(struct radix_tree_root *tree, unsigned long index, int tag) void simple_checks(void) { unsigned long index; - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); for (index = 0; index < 10000; index++) { __simple_checks(&tree, index, 0); @@ -61,7 +63,9 @@ void simple_checks(void) */ static void extend_checks(void) { - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); item_insert(&tree, 43); assert(item_tag_get(&tree, 43, 0) == 0); @@ -90,7 +94,9 @@ static void contract_checks(void) { struct item *item; int tmp; - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); tmp = 1<<RADIX_TREE_MAP_SHIFT; item_insert(&tree, tmp); @@ -271,9 +277,11 @@ static void do_thrash(struct radix_tree_root *tree, char *thrash_state, int tag) static void thrash_tags(void) { - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; char *thrash_state; + INIT_RADIX_TREE(&tree, GFP_KERNEL); + thrash_state = malloc(THRASH_SIZE); memset(thrash_state, 0, THRASH_SIZE); @@ -286,7 +294,9 @@ static void thrash_tags(void) static void leak_check(void) { - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); item_insert(&tree, 1000000); item_delete(&tree, 1000000); @@ -295,7 +305,9 @@ static void leak_check(void) static void __leak_check(void) { - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; + + INIT_RADIX_TREE(&tree, GFP_KERNEL); printv(2, "%d: nr_allocated=%d\n", __LINE__, nr_allocated); item_insert(&tree, 1000000); @@ -309,10 +321,12 @@ static void __leak_check(void) static void single_check(void) { struct item *items[BATCH]; - RADIX_TREE(tree, GFP_KERNEL); + struct radix_tree_root tree; int ret; unsigned long first = 0; + INIT_RADIX_TREE(&tree, GFP_KERNEL); + item_insert(&tree, 0); item_tag_set(&tree, 0, 0); ret = radix_tree_gang_lookup_tag(&tree, (void **)items, 0, BATCH, 0); -- 2.53.0
