Skip to content

Commit

Permalink
util/interval-tree: Use qatomic_set_mb in rb_link_node
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rth7680 committed Jul 31, 2023
1 parent 055b86e commit 4c8baa0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion util/interval-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4c8baa0

Please sign in to comment.