Message ID | 20230722214422.118743-3-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | util/interval-tree: Avoid race conditions without optimization | expand |
On Sat, 22 Jul 2023 at 22:44, Richard Henderson <richard.henderson@linaro.org> wrote: > > 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 > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- Reviewed-by: Peter Maydell <peter.maydell@linaro.org> thanks -- PMM
diff --git a/util/interval-tree.c b/util/interval-tree.c index 5a0ad21b2d..759562db7d 100644 --- a/util/interval-tree.c +++ b/util/interval-tree.c @@ -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)
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 Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- util/interval-tree.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)