From: Sasha Levin <sasha.levin@oracle.com>
To: Michel Lespinasse <walken@google.com>
Cc: Pekka Enberg <penberg@kernel.org>,
Asias He <asias.hejun@gmail.com>, Ingo Molnar <mingo@elte.hu>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Is augmented rbtree propagation broken?
Date: Thu, 22 Nov 2012 12:14:33 -0500 [thread overview]
Message-ID: <50AE5D79.8040803@oracle.com> (raw)
Hi Michel,
I've noticed a bug regarding search of ioports in the KVM tool. Since the KVM tool is
using kernel's augmented rbtree implementation to represent an interval rbtree I dug a
bit into the new implementation in the kernel, and noticed the following odd behaviour.
Let's take a simple case where we have 2 intervals with the 3rd parameter being the
'max_high' field used by interval rbtrees: (1,2,0) , (3,4,0). Let's add them one by one:
1. (1,2,2)
/ \
NULL NULL
2. (1,2,4)
/ \
NULL (3,4,4)
On the 2nd stage we'd expect that the new (3,4) interval will be added to the right
subtree (which happens correctly), and that the insertion will be propagated to the
root of the tree to update max_high (which doesn't happen).
Basically, at stage 2, the tree we're left with is:
(1,2,2)
/ \
NULL (3,4,4)
Which is wrong.
I suspect that this happens because we never propagate upon insertion, which sounds
quite odd to me, but I might be missing something.
The following patch fixed the problem for me:
diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
index 214caa3..5cfdca6 100644
--- a/include/linux/rbtree_augmented.h
+++ b/include/linux/rbtree_augmented.h
@@ -47,6 +47,7 @@ rb_insert_augmented(struct rb_node *node, struct rb_root *root,
const struct rb_augment_callbacks *augment)
{
__rb_insert_augmented(node, root, augment->rotate);
+ augment->propagate(node, NULL);
}
Thanks,
Sasha
next reply other threads:[~2012-11-22 21:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-22 17:14 Sasha Levin [this message]
2012-11-23 5:49 ` Is augmented rbtree propagation broken? Michel Lespinasse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50AE5D79.8040803@oracle.com \
--to=sasha.levin@oracle.com \
--cc=asias.hejun@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=walken@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox