BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/3] bpf, arena: keep range tree consistent on kmalloc_nolock failure
@ 2026-08-06  3:03 chenyuan_fl
  2026-08-06  3:03 ` [PATCH bpf-next v1 1/3] bpf, arena: fix range_tree_clear inconsistency " chenyuan_fl
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: chenyuan_fl @ 2026-08-06  3:03 UTC (permalink / raw)
  To: bpf
  Cc: linux-kernel, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Yuan Chen

From: Yuan Chen <chenyuan@kylinos.cn>

The arena range tree tracks free arena ranges.  range_tree_clear() and
range_tree_set() can fail when kmalloc_nolock() cannot allocate a node,
but both functions modified the tree before that allocation.  On
failure they returned -ENOMEM with part of the affected range already
removed from the tree, permanently losing those arena slots: they could
neither be allocated nor freed again.

Patch 1 pre-allocates the split node in range_tree_clear() so a failure
leaves the tree unmodified.  Patch 2 does the same for range_tree_set(),
allocating the new node only when the range has no adjacent free range
on either side.  Patch 3 makes arena_free_pages() and
arena_free_worker() check the range_tree_set() return value and skip
the free when the tree update fails, instead of unmapping and freeing
pages the tree still considers allocated.

The failure path requires kmalloc_nolock() to fail under memory
pressure, which is not feasible to trigger deterministically in a
selftest, so no regression test is included.

Yuan Chen (3):
  bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock
    failure
  bpf, arena: fix range_tree_set inconsistency on kmalloc_nolock failure
  bpf, arena: check range_tree_set return in arena_free_pages and
    arena_free_worker

 kernel/bpf/arena.c      | 17 +++++++++---
 kernel/bpf/range_tree.c | 60 ++++++++++++++++++++++++++++++-----------
 2 files changed, 58 insertions(+), 19 deletions(-)


base-commit: 11c1e836710dcba03e50454a4eedfdbaf8d3050e
-- 
2.54.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-08-06  3:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06  3:03 [PATCH bpf-next v1 0/3] bpf, arena: keep range tree consistent on kmalloc_nolock failure chenyuan_fl
2026-08-06  3:03 ` [PATCH bpf-next v1 1/3] bpf, arena: fix range_tree_clear inconsistency " chenyuan_fl
2026-08-06  3:14   ` sashiko-bot
2026-08-06  3:03 ` [PATCH bpf-next v1 2/3] bpf, arena: fix range_tree_set " chenyuan_fl
2026-08-06  3:03 ` [PATCH bpf-next v1 3/3] bpf, arena: check range_tree_set return in arena_free_pages and arena_free_worker chenyuan_fl
2026-08-06  3:19   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox