]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
util/interval-tree: Use qatomic_set_mb in rb_link_node
authorRichard Henderson <richard.henderson@linaro.org>
Sat, 22 Jul 2023 14:25:30 +0000 (15:25 +0100)
committerRichard Henderson <richard.henderson@linaro.org>
Mon, 31 Jul 2023 19:19:13 +0000 (12:19 -0700)
Ensure that the stores to rb_left and rb_right are complete before
inserting the new node into the tree.  Otherwise a concurrent reader
could see garbage in the new leaf.

Cc: qemu-stable@nongnu.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
util/interval-tree.c

index 5a0ad21b2d5ef7abcabe3000c62975ab8304cac3..759562db7da6f47bcc01cb9527a1e0214953fc5b 100644 (file)
@@ -128,7 +128,11 @@ static inline void rb_link_node(RBNode *node, RBNode *parent, RBNode **rb_link)
     node->rb_parent_color = (uintptr_t)parent;
     node->rb_left = node->rb_right = NULL;
 
-    qatomic_set(rb_link, node);
+    /*
+     * Ensure that node is initialized before insertion,
+     * as viewed by a concurrent search.
+     */
+    qatomic_set_mb(rb_link, node);
 }
 
 static RBNode *rb_next(RBNode *node)