From: bot+bpf-ci@kernel.org
To: chenyuan_fl@163.com,bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,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,emil@etsalapatis.com,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,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 2/3] bpf, arena: fix range_tree_set inconsistency on kmalloc_nolock failure
Date: Mon, 10 Aug 2026 10:59:59 +0000 (UTC) [thread overview]
Message-ID: <da5ec55c58dcd8997d2c5e1836e3b41289ebefe9be5328057fde62d8e7d8d5ad@mail.kernel.org> (raw)
In-Reply-To: <20260810094634.2723213-3-chenyuan_fl@163.com>
[-- Attachment #1: Type: text/plain, Size: 2203 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).
>
> Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
Should this include a Fixes: tag?
The commit message describes a concrete bug: on allocation failure the
range tree was left with overlapping free sub-ranges already removed,
permanently losing that arena free space.
The clear-then-allocate ordering has been present since
kernel/bpf/range_tree.c was introduced. The original code had exactly
the same structure, only with bpf_mem_alloc() instead of
kmalloc_nolock():
/* Clear out everything in the range we want to set. */
err = range_tree_clear(rt, start, len);
if (err)
return err;
...
} else {
left = bpf_mem_alloc(&bpf_global_ma, sizeof(struct range_node));
if (!left)
return -ENOMEM;
Concrete reproduction of the pre-patch bug: with the tree holding a
single free range {[10,20]} and a call to range_tree_set(rt, 5, 20)
(i.e. start=5, last=24), range_tree_clear() takes the 'in the middle of
the clearing range' branch, removing and freeing [10,20]. The subsequent
allocation then fails, range_tree_set() returns -ENOMEM, and the tree is
left empty -- the [10,20] free range is gone for the lifetime of the
arena.
Four of the five callers (arena_alloc_pages() rollback at
kernel/bpf/arena.c:774, arena_free_pages() at :884, arena_free_worker()
at :1011, arena_vm_fault() rollback at :523/:529) discard
range_tree_set()'s return value, so the loss is silent.
Should this include:
Fixes: b795379757eb ("bpf: Introduce range_tree data structure and use it in bpf arena")
---
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/31377360587
next prev parent reply other threads:[~2026-08-10 11:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 9:46 [PATCH bpf-next v2 0/3] bpf, arena: fix range_tree consistency on allocation failure chenyuan_fl
2026-08-10 9:46 ` [PATCH bpf-next v2 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure chenyuan_fl
2026-08-10 10:45 ` bot+bpf-ci
2026-08-10 9:46 ` [PATCH bpf-next v2 2/3] bpf, arena: fix range_tree_set " chenyuan_fl
2026-08-10 10:59 ` bot+bpf-ci [this message]
2026-08-10 9:46 ` [PATCH bpf-next v2 3/3] bpf, arena: check range_tree_set return in arena_free_pages and arena_free_worker chenyuan_fl
2026-08-10 10:59 ` 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=da5ec55c58dcd8997d2c5e1836e3b41289ebefe9be5328057fde62d8e7d8d5ad@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan@kylinos.cn \
--cc=chenyuan_fl@163.com \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.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=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®