* [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root leaf node
@ 2025-06-24 19:18 Liam R. Howlett
2025-06-24 19:18 ` [PATCH 2/2] maple_tree: assert retrieving new value on a tree containing just a " Liam R. Howlett
2025-06-25 5:15 ` [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root " Dev Jain
0 siblings, 2 replies; 3+ messages in thread
From: Liam R. Howlett @ 2025-06-24 19:18 UTC (permalink / raw)
To: Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, Wei Yang, Liam R. Howlett,
stable, Liam R. Howlett
From: Wei Yang <richard.weiyang@gmail.com>
On destroy, we should set each node dead. But current code miss this
when the maple tree has only the root node.
The reason is mt_destroy_walk() leverage mte_destroy_descend() to set
node dead, but this is skipped since the only root node is a leaf.
Fixes this by setting the node dead if it is a leaf.
Link: https://lore.kernel.org/all/20250407231354.11771-1-richard.weiyang@gmail.com/
Fixes: 54a611b60590 ("Maple Tree: add new data structure")
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
lib/maple_tree.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 6b0fc6ebbe363..85d17d943753d 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -5319,6 +5319,7 @@ static void mt_destroy_walk(struct maple_enode *enode, struct maple_tree *mt,
struct maple_enode *start;
if (mte_is_leaf(enode)) {
+ mte_set_node_dead(enode);
node->type = mte_node_type(enode);
goto free_leaf;
}
--
2.47.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] maple_tree: assert retrieving new value on a tree containing just a leaf node
2025-06-24 19:18 [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root leaf node Liam R. Howlett
@ 2025-06-24 19:18 ` Liam R. Howlett
2025-06-25 5:15 ` [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root " Dev Jain
1 sibling, 0 replies; 3+ messages in thread
From: Liam R. Howlett @ 2025-06-24 19:18 UTC (permalink / raw)
To: Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, Wei Yang, Liam R. Howlett,
Liam R. Howlett
From: Wei Yang <richard.weiyang@gmail.com>
Original code may not get the new value after overwriting the whole
range on a maple tree containing just a leaf node. The reason is we didn't
set the only root node dead during destroy.
Add a test case to ensure the new value is returned when overwriting a
tree containing just a leaf node.
Link: https://lore.kernel.org/all/20250407231354.11771-1-richard.weiyang@gmail.com/
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
[Liam.Howlett@oracle.com: Use mtree_destroy, mas_set, and set val]
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
tools/testing/radix-tree/maple.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c
index 172700fb7784d..2f6dcdc7a38f6 100644
--- a/tools/testing/radix-tree/maple.c
+++ b/tools/testing/radix-tree/maple.c
@@ -35257,6 +35257,32 @@ static noinline void __init check_rcu_simulated(struct maple_tree *mt)
MT_BUG_ON(mt, mas_prev(&mas_reader, 0) != xa_mk_value(val));
rcu_read_unlock();
+ /* Clear out tree & create one with only root node */
+ mtree_destroy(mt);
+ mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_USE_RCU);
+ mas_pause(&mas_writer);
+ mas_lock(&mas_writer);
+ for (i = 0; i <= 5; i++) {
+ mas_writer.index = i * 10;
+ mas_writer.last = i * 10 + 5;
+ mas_store_gfp(&mas_writer, xa_mk_value(i), GFP_KERNEL);
+ }
+ mas_unlock(&mas_writer);
+ target = 10;
+ val = 20;
+ mas_set(&mas_reader, target);
+ rcu_read_lock();
+ MT_BUG_ON(mt, mas_walk(&mas_reader) != xa_mk_value(target/10));
+ MT_BUG_ON(mt, mte_is_leaf(mas_reader.node) != true);
+
+ /* Overwrite the whole range */
+ mas_lock(&mas_writer);
+ mas_set_range(&mas_writer, 0, ULONG_MAX);
+ mas_store_gfp(&mas_writer, xa_mk_value(val), GFP_KERNEL);
+ mas_unlock(&mas_writer);
+ MT_BUG_ON(mt, mas_walk(&mas_reader) != xa_mk_value(val));
+ rcu_read_unlock();
+
rcu_unregister_thread();
}
--
2.47.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root leaf node
2025-06-24 19:18 [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root leaf node Liam R. Howlett
2025-06-24 19:18 ` [PATCH 2/2] maple_tree: assert retrieving new value on a tree containing just a " Liam R. Howlett
@ 2025-06-25 5:15 ` Dev Jain
1 sibling, 0 replies; 3+ messages in thread
From: Dev Jain @ 2025-06-25 5:15 UTC (permalink / raw)
To: Liam R. Howlett, Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, Wei Yang, stable
On 25/06/25 12:48 am, Liam R. Howlett wrote:
> From: Wei Yang <richard.weiyang@gmail.com>
>
> On destroy, we should set each node dead. But current code miss this
> when the maple tree has only the root node.
>
> The reason is mt_destroy_walk() leverage mte_destroy_descend() to set
> node dead, but this is skipped since the only root node is a leaf.
>
> Fixes this by setting the node dead if it is a leaf.
>
> Link: https://lore.kernel.org/all/20250407231354.11771-1-richard.weiyang@gmail.com/
> Fixes: 54a611b60590 ("Maple Tree: add new data structure")
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> ---
> lib/maple_tree.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 6b0fc6ebbe363..85d17d943753d 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -5319,6 +5319,7 @@ static void mt_destroy_walk(struct maple_enode *enode, struct maple_tree *mt,
> struct maple_enode *start;
>
> if (mte_is_leaf(enode)) {
> + mte_set_node_dead(enode);
> node->type = mte_node_type(enode);
> goto free_leaf;
> }
FWIW I have been reading the maple tree code and this looks good to me.
Reviewed-by: Dev Jain <dev.jain@arm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-25 5:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 19:18 [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root leaf node Liam R. Howlett
2025-06-24 19:18 ` [PATCH 2/2] maple_tree: assert retrieving new value on a tree containing just a " Liam R. Howlett
2025-06-25 5:15 ` [PATCH 1/2] maple_tree: Fix mt_destroy_walk() on root " Dev Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).