qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] util/interval-tree: Avoid race conditions without optimization
@ 2023-07-07 10:30 Richard Henderson
  2023-07-13 11:32 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2023-07-07 10:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, qemu-stable

Read the left and right trees once, so that the gating
tests are meaningful.  This was only a problem at -O0,
where the compiler didn't CSE the two reads.

Cc: qemu-stable@nongnu.org
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 util/interval-tree.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/util/interval-tree.c b/util/interval-tree.c
index 4c0baf108f..31978c32ac 100644
--- a/util/interval-tree.c
+++ b/util/interval-tree.c
@@ -741,12 +741,15 @@ static IntervalTreeNode *interval_tree_subtree_search(IntervalTreeNode *node,
                                                       uint64_t last)
 {
     while (true) {
+        RBNode *rb_tmp;
+
         /*
          * Loop invariant: start <= node->subtree_last
          * (Cond2 is satisfied by one of the subtree nodes)
          */
-        if (node->rb.rb_left) {
-            IntervalTreeNode *left = rb_to_itree(node->rb.rb_left);
+        rb_tmp = node->rb.rb_left;
+        if (rb_tmp) {
+            IntervalTreeNode *left = rb_to_itree(rb_tmp);
 
             if (start <= left->subtree_last) {
                 /*
@@ -765,8 +768,10 @@ static IntervalTreeNode *interval_tree_subtree_search(IntervalTreeNode *node,
             if (start <= node->last) {     /* Cond2 */
                 return node; /* node is leftmost match */
             }
-            if (node->rb.rb_right) {
-                node = rb_to_itree(node->rb.rb_right);
+
+            rb_tmp = node->rb.rb_right;
+            if (rb_tmp) {
+                node = rb_to_itree(rb_tmp);
                 if (start <= node->subtree_last) {
                     continue;
                 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-13 15:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-07 10:30 [PATCH] util/interval-tree: Avoid race conditions without optimization Richard Henderson
2023-07-13 11:32 ` Peter Maydell
2023-07-13 15:42   ` Richard Henderson

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).