From: Emil Tsalapatis <emil@etsalapatis.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, memxor@gmail.com,
daniel@iogearbox.net, eddyz87@gmail.com,
nickolay.lysenko@gmail.com,
Emil Tsalapatis <emil@etsalapatis.com>
Subject: [PATCH bpf-next 1/5] bpf: Update is_range_tree_set to work for consecutive ranges
Date: Wed, 2 Sep 2026 03:02:35 -0400 [thread overview]
Message-ID: <20260902070239.16968-2-emil@etsalapatis.com> (raw)
In-Reply-To: <20260902070239.16968-1-emil@etsalapatis.com>
The arena range tree currently does not handle consecutive
ranges present in the tree. This is by design: Consecutive
ranges get merged into one by default. However, this design
only lets us track a single bit's worth of state for each
address range, encoded by whether the range is present in
the tree or not (i.e., is it allocated).
We require more fine-grained state tracking for each range.
This means possibly having in the tree consecutive ranges
that cannot be merged because they have different states.
However, existing code implicitly assumes that this scenario
is not possible in its logic.
Expand the logic of is_range_tree_set to handle consecutive
ranges in the tree. The logic change does not affect existing
users and amounts to a defensive check until we enable unmergeable
consecutive ranges in subsequent patches.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
---
kernel/bpf/range_tree.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/kernel/bpf/range_tree.c b/kernel/bpf/range_tree.c
index 2f28886f3ff7..6f6ba718887c 100644
--- a/kernel/bpf/range_tree.c
+++ b/kernel/bpf/range_tree.c
@@ -180,12 +180,21 @@ int range_tree_clear(struct range_tree *rt, u32 start, u32 len)
int is_range_tree_set(struct range_tree *rt, u32 start, u32 len)
{
u32 last = start + len - 1;
- struct range_node *left;
+ struct range_node *rn;
- /* Is this whole range set ? */
- left = range_it_iter_first(rt, start, last);
- if (left && left->rn_start <= start && left->rn_last >= last)
- return 0;
+ while ((rn = range_it_iter_first(rt, start, last))) {
+ /* Make sure the range covers the start */
+ if (rn->rn_start > start)
+ return -ESRCH;
+
+ /* If it covers the entire range we're done. */
+ if (rn->rn_last >= last)
+ return 0;
+
+ start = rn->rn_last + 1;
+ }
+
+ /* No range to cover [start, last] */
return -ESRCH;
}
--
2.55.0
next prev parent reply other threads:[~2026-09-02 7:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 7:02 [PATCH bpf-next 0/5] bpf: Fix arena memory incoherence Emil Tsalapatis
2026-09-02 7:02 ` Emil Tsalapatis [this message]
2026-09-02 8:01 ` [PATCH bpf-next 1/5] bpf: Update is_range_tree_set to work for consecutive ranges bot+bpf-ci
2026-09-02 7:02 ` [PATCH bpf-next 2/5] bpf: Track availability information for ranges in range tree Emil Tsalapatis
2026-09-02 8:20 ` bot+bpf-ci
2026-09-02 7:02 ` [PATCH bpf-next 3/5] bpf: Fix arena race between page free and alloc leading to incoherency Emil Tsalapatis
2026-09-02 8:20 ` bot+bpf-ci
2026-09-02 7:02 ` [PATCH bpf-next 4/5] bpf: Atomically update PTE and range tree in arena VM fault handler Emil Tsalapatis
2026-09-02 7:19 ` sashiko-bot
2026-09-02 7:02 ` [PATCH bpf-next 5/5] selftests/bpf: Add arena allocation race tests Emil Tsalapatis
2026-09-02 7:14 ` sashiko-bot
2026-09-02 8:20 ` bot+bpf-ci
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=20260902070239.16968-2-emil@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=memxor@gmail.com \
--cc=nickolay.lysenko@gmail.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