From: bot+bpf-ci@kernel.org
To: chenyuan_fl@163.com,bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,alexei.starovoitov@gmail.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,ihor.solodrai@linux.dev,chenyuan@kylinos.cn,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v7 2/2] bpf, arena: fix range_tree_set inconsistency on kmalloc_nolock failure
Date: Wed, 23 Sep 2026 09:34:29 +0000 (UTC) [thread overview]
Message-ID: <2b8ec13b3f1928edb5cd898ae1a3be2b195680f433cc456941501b4371b30698@mail.kernel.org> (raw)
In-Reply-To: <20260923085817.365930-3-chenyuan_fl@163.com>
[-- Attachment #1: Type: text/plain, Size: 4089 bytes --]
> bpf, arena: fix range_tree_set inconsistency on kmalloc_nolock failure
>
> range_tree_set() pre-allocates the node needed for a brand-new range
> before calling range_tree_clear(), so an allocation failure returns
> -ENOMEM without having modified the tree (previously the overlapping
> nodes were already removed by range_tree_clear() before the allocation
> was attempted, permanently losing the cleared sub-ranges).
>
> The adjacency lookups done before the clear already return the nodes
> that the merge below needs: range_tree_clear() frees only the nodes
> that lie entirely inside [start, last], trims the overlapping ones in
> place, and the split case cannot happen because of the 'already set'
> check above. Do the lookup once and drop the unreachable -EFAULT
> checks.
>
> Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
This looks like a bug fix for the clear-before-allocate ordering in
range_tree_set(). Should this include:
Fixes: b795379757eb ("bpf: Introduce range_tree data structure and use it in bpf arena")
> diff --git a/kernel/bpf/range_tree.c b/kernel/bpf/range_tree.c
> index 15b588377a76..2460e78d6a55 100644
> --- a/kernel/bpf/range_tree.c
> +++ b/kernel/bpf/range_tree.c
> @@ -199,6 +199,7 @@ int is_range_tree_set(struct range_tree *rt, u32 start, u32 len)
> int range_tree_set(struct range_tree *rt, u32 start, u32 len)
> {
> u32 last = start + len - 1;
> + struct range_node *new_rn = NULL;
> struct range_node *right;
> struct range_node *left;
> int err;
> @@ -208,20 +209,19 @@ int range_tree_set(struct range_tree *rt, u32 start, u32 len)
> if (left && left->rn_start <= start && left->rn_last >= last)
> return 0;
>
> + left = range_it_iter_first(rt, start - 1, start - 1);
> + right = range_it_iter_first(rt, last + 1, last + 1);
This isn't a bug, but could a short comment above these lookups record
why they are still valid after range_tree_clear() runs, the way the
changelog explains it? The correctness now rests on a non-obvious
argument: range_tree_clear() only trims a node overlapping start-1 or
last+1 in place (never frees it), so these pointers and their endpoints
are still the ones the merge branches below need. Every other decision
point in this function carries a one-line comment, so the two bare
lookups are the odd ones out, and the rationale currently lives only in
the changelog.
> + if (!left && !right) {
> + new_rn = kmalloc_nolock(sizeof(struct range_node),
> + __GFP_ACCOUNT, NUMA_NO_NODE);
> + if (!new_rn)
> + return -ENOMEM;
> + }
> +
> /* Clear out everything in the range we want to set. */
> err = range_tree_clear(rt, start, len);
> if (err)
> - return err;
This isn't a bug, but since the changelog argues range_tree_clear()
cannot fail here (the split path is unreachable because of the 'already
set' check), is the new out_free_new path kept deliberately as
future-proofing, or could it go the same way as the -EFAULT checks? The
asymmetry is what reads oddly: the patch removes two unreachable checks
precisely for being unreachable, while keeping error propagation from an
int-returning helper that the changelog says cannot fail.
> + goto out_free_new;
>
[ ... ]
> @@ -241,14 +241,16 @@ int range_tree_set(struct range_tree *rt, u32 start, u32 len)
> right->rn_start = start;
> range_it_insert(right, rt);
> } else {
> - left = kmalloc_nolock(sizeof(struct range_node), __GFP_ACCOUNT, NUMA_NO_NODE);
> - if (!left)
> - return -ENOMEM;
> - left->rn_start = start;
> - left->rn_last = last;
> - range_it_insert(left, rt);
> + /* No adjacent ranges; use the pre-allocated node */
> + new_rn->rn_start = start;
> + new_rn->rn_last = last;
> + range_it_insert(new_rn, rt);
> }
> return 0;
> +
> +out_free_new:
> + kfree_nolock(new_rn);
> + return err;
> }
>
> void range_tree_destroy(struct range_tree *rt)
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35841441642
next prev parent reply other threads:[~2026-09-23 9:34 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 13:40 [PATCH bpf-next v4 0/3] bpf, arena: fix range_tree consistency on allocation failure chenyuan_fl
2026-08-24 13:40 ` [PATCH bpf-next v4 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure chenyuan_fl
2026-08-24 14:35 ` bot+bpf-ci
2026-08-24 13:40 ` [PATCH bpf-next v4 2/3] bpf, arena: fix range_tree_set " chenyuan_fl
2026-08-24 14:35 ` bot+bpf-ci
2026-08-27 2:56 ` Alexei Starovoitov
2026-09-01 7:01 ` chenyuan
2026-09-02 9:37 ` [PATCH bpf-next v5 0/3] bpf, arena: fix range_tree consistency on allocation failure chenyuan_fl
2026-09-02 9:37 ` [PATCH bpf-next v5 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure chenyuan_fl
2026-09-02 9:37 ` [PATCH bpf-next v5 2/3] bpf, arena: fix range_tree_set " chenyuan_fl
2026-09-02 9:37 ` [PATCH bpf-next v5 3/3] bpf, arena: handle range_tree_set failures in alloc/free paths chenyuan_fl
2026-09-08 15:53 ` Emil Tsalapatis
2026-09-22 6:58 ` [PATCH bpf-next v6 0/3] bpf, arena: fix range_tree consistency on allocation failure chenyuan_fl
2026-09-22 7:20 ` [PATCH bpf-next v6 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure chenyuan_fl
2026-09-22 7:21 ` [PATCH bpf-next v6 2/3] bpf, arena: fix range_tree_set " chenyuan_fl
2026-09-22 8:24 ` bot+bpf-ci
2026-09-23 2:02 ` Alexei Starovoitov
2026-09-22 7:21 ` [PATCH bpf-next v6 3/3] bpf, arena: check range_tree_set return in arena_free_pages and arena_free_worker chenyuan_fl
2026-09-23 2:02 ` Alexei Starovoitov
2026-09-23 8:58 ` [PATCH bpf-next v7 0/2] bpf, arena: fix range_tree consistency on allocation failure chenyuan_fl
2026-09-23 8:58 ` [PATCH bpf-next v7 1/2] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure chenyuan_fl
2026-09-23 9:34 ` bot+bpf-ci
2026-09-23 8:58 ` [PATCH bpf-next v7 2/2] bpf, arena: fix range_tree_set " chenyuan_fl
2026-09-23 9:34 ` bot+bpf-ci [this message]
2026-09-24 2:00 ` [PATCH bpf-next v7 0/2] bpf, arena: fix range_tree consistency on allocation failure patchwork-bot+netdevbpf
2026-08-24 13:40 ` [PATCH bpf-next v4 3/3] bpf, arena: check range_tree_set return in arena_free_pages and arena_free_worker chenyuan_fl
2026-08-24 14:35 ` 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=2b8ec13b3f1928edb5cd898ae1a3be2b195680f433cc456941501b4371b30698@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan@kylinos.cn \
--cc=chenyuan_fl@163.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®