From 0fd271230891ad741b8a2f9ea814d584032afac9 Mon Sep 17 00:00:00 2001 From: Dimitris Charisis Date: Mon, 5 Oct 2026 12:47:28 +0000 Subject: [PATCH] test_maple_tree: test maple_range_64 node in RCU mode This commit adds a test that builds two maple_range_64 trees in RCU mode. The first tree has a root that is a full maple_range_64 node and ensures that the destruction under RCU does not misinterpret the last slot as metadata. 226 insertions produce such a root on a 64-bit build. The second tree is a height 3 tree whose root holds 15 child pointers and metadata in its last slot, so every slot is non-zero and ensures that the destruction under RCU does not descend into the metadata slot. 3166 insertions produce such a tree on a 64-bit build. Link: https://lore.kernel.org/20261005-fix-maple-tree-range64-rcu-v3-2-ebe7fb278e20@cslab.ece.ntua.gr Signed-off-by: Dimitris Charisis Signed-off-by: Andrew Morton Reviewed-by: Liam R. Howlett (Google) Cc: Alice Ryhl Cc: Andrew Ballance Cc: Suren Baghdasaryan Cc: Matthew Wilcox (Oracle) Cc: Florian Schmaus --- lib/test_maple_tree.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index b9367c61e8b5..fb40e193a3cb 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -3710,6 +3710,36 @@ static noinline void __init alloc_cyclic_testing(struct maple_tree *mt) MT_BUG_ON(mt, ret != 1); } +static noinline void __init check_range64_in_rcu(struct maple_tree *mt) +{ + unsigned long i; + unsigned long nr_entries = 226; /* Build a full maple_range_64 root node */ + + MT_BUG_ON(mt, !mtree_empty(mt)); + mt_init_flags(mt, MT_FLAGS_USE_RCU); + + for (i = 0; i < nr_entries; i++) { + MT_BUG_ON(mt, mtree_test_insert_range(mt, i*10, i*10 + 9, + xa_mk_value(i))); + } + + mtree_destroy(mt); + rcu_barrier(); + + nr_entries = 3166; /* Height 3. Root has 15 children + metadata */ + + MT_BUG_ON(mt, !mtree_empty(mt)); + mt_init_flags(mt, MT_FLAGS_USE_RCU); + + for (i = 0; i < nr_entries; i++) { + MT_BUG_ON(mt, mtree_test_insert_range(mt, i*10, i*10 + 9, + xa_mk_value(i))); + } + + mtree_destroy(mt); + rcu_barrier(); +} + static DEFINE_MTREE(tree); static int __init maple_tree_seed(void) { @@ -3999,6 +4029,8 @@ static int __init maple_tree_seed(void) alloc_cyclic_testing(&tree); mtree_destroy(&tree); + check_range64_in_rcu(&tree); + #if defined(BENCH) skip: