From 2f38e34ea80f7c6525f518ff567c29f6e63266a6 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 3 Jan 2023 21:37:29 -0500 Subject: [PATCH] maple_tree: Add smp_rmb() to dead node detection Add an smp_rmb() before reading the parent pointer to ensure that anything read from the node prior to the parent pointer hasn't been reordered ahead of this check. The is necessary for RCU mode. Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 17a4fc3b1cc0..27d153dcbe34 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -530,9 +530,10 @@ static inline struct maple_node *mte_parent(const struct maple_enode *enode) */ static inline bool ma_dead_node(const struct maple_node *node) { - struct maple_node *parent = (void *)((unsigned long) - node->parent & ~MAPLE_NODE_MASK); + struct maple_node *parent; + smp_rmb(); + parent = (void *)((unsigned long) node->parent & ~MAPLE_NODE_MASK); return (parent == node); } @@ -547,6 +548,7 @@ static inline bool mte_dead_node(const struct maple_enode *enode) struct maple_node *parent, *node; node = mte_to_node(enode); + smp_rmb(); parent = mte_parent(enode); return (parent == node); } -- 2.50.1