Re: [PATCH bpf-next v2 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure

From: bot+bpf-ci

Date: Mon Aug 10 2026 - 06:50:51 EST


> diff --git a/kernel/bpf/range_tree.c b/kernel/bpf/range_tree.c
> index 2f28886f3ff7..15b588377a76 100644
> --- a/kernel/bpf/range_tree.c
> +++ b/kernel/bpf/range_tree.c
> @@ -143,16 +143,22 @@ int range_tree_clear(struct range_tree *rt, u32 start, u32 len)
> if (rn->rn_start < start && rn->rn_last > last) {
> u32 old_last = rn->rn_last;
>
> + /*
> + * Pre-allocate the right-half node before modifying
> + * the tree. If allocation fails we return -ENOMEM
> + * without altering the range tree.
> + */
> + new_rn = kmalloc_nolock(sizeof(struct range_node),
> + __GFP_ACCOUNT, NUMA_NO_NODE);
> + if (!new_rn)
> + return -ENOMEM;
> +
> /* Overlaps with the entire clearing range */
> range_it_remove(rn, rt);
> rn->rn_last = start - 1;
> range_it_insert(rn, rt);
>
> - /* Add a range */
> - new_rn = kmalloc_nolock(sizeof(struct range_node), __GFP_ACCOUNT,
> - NUMA_NO_NODE);
> - if (!new_rn)
> - return -ENOMEM;
> + /* Add right-half range */
> new_rn->rn_start = last + 1;
> new_rn->rn_last = old_last;
> range_it_insert(new_rn, rt);

This isn't a bug, but could the changelog also state what went wrong
with the old ordering? The sibling patch d453da244bfd ("bpf, arena:
fix range_tree_set inconsistency on kmalloc_nolock failure") spells
out the consequence ("previously the overlapping nodes were already
removed by range_tree_clear() before the allocation was attempted,
permanently losing the cleared sub-ranges"), while this changelog only
describes the new behavior. Without explaining that the right sub-range
[last + 1, old_last] was permanently lost from the free tree when
kmalloc_nolock() failed after the left half had already been shrunk,
the two changelogs read inconsistently.

This looks like a bug fix for the original range_tree implementation.
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