From: Khawar Ahemad <ahemadkhawar123@gmail.com>
To: bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
jiayuan.chen@linux.dev, emil@etsalapatis.com,
martin.lau@linux.dev, yonghong.song@linux.dev, clm@meta.com,
ihor.solodrai@linux.dev, ahemadkhawar123@gmail.com
Subject: Re: [PATCH bpf-next v6 4/4] selftests/bpf: Add a test for arena fault-in under memory.max
Date: Tue, 25 Aug 2026 16:13:11 +0530 [thread overview]
Message-ID: <20260825104311.84038-1-ahemadkhawar123@gmail.com> (raw)
In-Reply-To: <20260825094955.83240-5-ahemadkhawar123@gmail.com>
Addressing the three CI review comments on the v6 series:
---
[Patch 4/4] max_entries comment
---
> could the 50000 carry a short note that it just has to outrun
> ARENA_BUDGET on the smallest page size
Accepted. Will be fixed in v7 as a proper preceding block comment:
/*
* 50000 pages must exceed ARENA_BUDGET / PAGE_SIZE (64M / 4k = 16384)
* so the fault loop hits memory.max before exhausting the arena itself.
*/
__uint(max_entries, 50000);
---
[Patch 1/4] bpf_map_alloc_page_sleepable() reentrancy documentation
---
> Michal Hocko asked how bpf_map_alloc_page_sleepable() achieves safety
> from mm reentrancy, noting that sleepable context alone doesn't
> guarantee safety.
Accepted. Michal's concern is correct: "sleepable" does not automatically
imply "non-reentrant with respect to mm". The comment will be expanded in
v7 to document the reentrancy contract explicitly:
The only current caller is arena_vm_fault(), which is invoked from
handle_mm_fault() before taking arena->spinlock and before any BPF
subsystem lock. mmap_lock is held shared by the fault path, but the
allocator only needs it for vma lookup which it does not perform here.
No BPF-internal lock is held at the call site, so allocator reentrancy
through mm is not possible.
---
[Patch 2/4] Lockless probe race and non-blocking fallback
---
> Doesn't this reintroduce the exact problem the patch aims to solve?
No. The residual race is intentional, bounded, and qualitatively different
from the bug being fixed. Here is why:
The original bug was on the NORMAL, non-racy path: every arena fault where
no page existed would unconditionally use the non-blocking allocator, so
any routine memory.max event killed the process. The fix eliminates that
by preallocating with the sleepable allocator before the spinlock.
The fallback path (!new_page under the lock) is reached only when ALL of
the following are simultaneously true:
(a) The lockless probe saw a page (a BPF program allocated one).
(b) That page was freed between the probe and the lock acquisition.
(c) The resulting non-blocking allocation also fails (memory.max hit
in that same narrow window).
For (c) to occur independently of (a)+(b), the system must be under
memory pressure severe enough that a non-blocking atomic allocation fails
at the exact same moment the BPF program is freeing a page. A BPF program
that frees arena pages by definition had successfully allocated them
moments earlier, so available memory exists nearby. The likelihood of the
non-blocking allocator failing in this window is therefore extremely low.
More importantly, moving the probe inside the locked region is not
architecturally possible: the purpose of the probe is to decide WHETHER to
preallocate with the sleepable allocator. That decision must happen before
the lock is taken, because sleeping is not allowed inside the spinlock. The
probe-then-preallocate-then-lock sequence is the same pattern used by
do_anonymous_page() and do_cow_fault() in mm/memory.c.
On failure in the race path, VM_FAULT_SIGBUS is returned (not
VM_FAULT_SIGSEGV), which is the correct signal for a resource failure as
opposed to an addressing violation. The commit message's claim ("prevents
a routine memory.max into a fake segfault") refers to the normal path and
remains accurate.
Will add an additional sentence to the !new_page comment in v7 making
clear that this path cannot be sleepable by design.
Khawar Ahemad <ahemadkhawar123@gmail.com>
next prev parent reply other threads:[~2026-08-25 10:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 9:49 [PATCH bpf-next v6 0/4] bpf: arena: handle memory.max on fault-in with reclaim/OOM Khawar Ahemad
2026-08-25 9:49 ` [PATCH bpf-next v6 1/4] bpf: Add a sleepable page allocator for map memory Khawar Ahemad
2026-08-25 10:11 ` sashiko-bot
2026-08-25 10:22 ` Khawar Ahemad
2026-08-25 10:32 ` bot+bpf-ci
2026-08-25 9:49 ` [PATCH bpf-next v6 2/4] bpf: arena: allocate the fault-in page outside the lock Khawar Ahemad
2026-08-25 10:32 ` bot+bpf-ci
2026-08-25 9:49 ` [PATCH bpf-next v6 3/4] selftests/bpf: Add read_cgroup_file() to cgroup_helpers Khawar Ahemad
2026-08-25 9:49 ` [PATCH bpf-next v6 4/4] selftests/bpf: Add a test for arena fault-in under memory.max Khawar Ahemad
2026-08-25 10:32 ` bot+bpf-ci
2026-08-25 10:43 ` Khawar Ahemad [this message]
2026-08-25 11:19 ` Jiayuan Chen
2026-08-25 12:23 ` Kumar Kartikeya Dwivedi
2026-08-25 11:28 ` Khawar Ahemad
2026-08-25 9:55 ` [PATCH bpf-next v6 0/4] bpf: arena: handle memory.max on fault-in with reclaim/OOM Jiayuan Chen
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=20260825104311.84038-1-ahemadkhawar123@gmail.com \
--to=ahemadkhawar123@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jiayuan.chen@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--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