From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796248751; b=3n+lRVskqPQeILuIc18miIvcR1vpBOXVpKL8cQR+Hf2+3lC81TBHV83/7jNyZSarFfmp LjNUuCXbAfl/ls4SgvFUoTOhfbu6uspN+l6Svihr11VX9bngZjwAadjy1JNK9rrDpQwzL YBz3mIEfk5DWDMXRRyWTIMAWadfAsll7W+HaQtUe0fZy44zWbPDuG5Wf9oYPOshN0nNRu WTnT41yyeaHt6++7UogICh/F0kx2Zv5IWb6nRm5fS/DPrV2We+tCGJa7/4tWVjazzH1z3 TtnaC/dikJDcEk5EMale07lYz1wE6Xo17RL6SeaKateHp0DpOseO6t3yPrOC1tyQEOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796248751; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=aVgg9g9GTO+TWkUoW4p7mW1upvVutS+5Ykjwos2Vys0=; b=RO7684teRKjCjSryPnY4h/Hdau6MKPTlt17X2BgW7x4jRtIZLprfF2WW7aPTys5otkkW G1XqP3OqQHHSsJFuzhtxivZVuCJQFR7CTB96Fp3DbW4fdfX8YUSLft5DCSOyx32yDqroA QCm/Z9y8lSSu1UzsLJrmO7s6uCF1QNqCcbC+1ikAbv1EGaxzvY6fSW/LkpAQE/bixKCPu NqQT+dORMhtio2A1YT8sPrCPNNYNADWsua9b9wA4fMg/U1Cc54NdND2QDocGCD7UU5YU+ di5RPLCiMhysxK8WlcAYfPFz9W4O3gtvcR8zohNgE7pxsPwGMP7vMZu/m4nu77F6Flw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gDvsIEyV; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C58BF606A330; Wed, 2 Dec 2026 21:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gDvsIEyV Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC7BE1F00893; Wed, 2 Dec 2026 21:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796248751; bh=aVgg9g9GTO+TWkUoW4p7mW1upvVutS+5Ykjwos2Vys0=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=gDvsIEyVzIn3/WlE/7XCxHzI4tGTRyxRYqVYNOmW8Sh2uQP65OtWROde9v4uOPYhR 4n1vmCgWc09AOnbvt3G22lP7NnBiljko76u37kQ6fZtFpaW5GlsmoEwOg+DB4S4bT1 C34OvcEddxd89sm46tQN9YTW1yayDI8ZxHTCmAzqhekkk4j+/tmzyY+aHt8X8AKCKm RWZHn7lYHY/LkWI6s5u2Lijuq4kD3U+sqhsIXRA2KHfsXwqOO9RTpsSdlblpFO8LpS TFuUFNMydv0O53NXz0PN4TZypkjXMJI386vqf2tDAeyvIciRbLN6MAGiL8KNVVZ6DQ I9zFh1gkDRPTQ== Content-Type: multipart/mixed; boundary="===============6742239364527120735==" X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: In-Reply-To: <20261202210415.517651-5-bgardon@google.com> References: <20261202210415.517651-5-bgardon@google.com> Subject: Re: [PATCH bpf-next v4 04/17] mm, bpf: introduce bpf_out_of_memory() BPF kfunc From: bot+bpf-ci@kernel.org To: bgardon@google.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,akpm@linux-foundation.org,hannes@cmpxchg.org,mhocko@kernel.org,shakeel.butt@linux.dev,roman.gushchin@linux.dev,tj@kernel.org Cc: jp.kobryn@linux.dev,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,rientjes@google.com,surenb@google.com,joshdon@google.com,sweettea-kernel@dorminy.me,zhouchuyi@bytedance.com,laoar.shao@gmail.com,benbwgardon@gmail.com,bpf@vger.kernel.org,linux-mm@kvack.org,cgroups@vger.kernel.org,linux-kernel@vger.kernel.org,bgardon@google.com,mhocko@suse.com,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 Date: Wed, 2 Dec 2026 21:59:07 +0000 (UTC) --===============6742239364527120735== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit > mm, bpf: introduce bpf_out_of_memory() BPF kfunc TL;DR: - bpf_out_of_memory() needs only CAP_BPF, so a SYSCALL program may SIGKILL the largest host process; KF_PERFMON gate? - May ignore cgroup v1 oom_kill_disable - Questions about the retained WAIT_ON_OOM_LOCK flag > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c [ ... ] > +__bpf_kfunc int bpf_out_of_memory(struct mem_cgroup *memcg__nullable, > + int order, u64 flags) > +{ [ ... ] > + oc.memcg = memcg__nullable; > + > + if (flags & BPF_OOM_FLAGS_WAIT_ON_OOM_LOCK) { > + ret = mutex_lock_killable(&oom_lock); > + if (ret) > + return ret; > + } else if (!mutex_trylock(&oom_lock)) { > + return -EBUSY; > + } Michal Hocko suggested in an earlier version that oom_lock be taken based on oc->memcg, so the behavior is transparent to BPF handlers, instead of adding the BPF_OOM_FLAGS_WAIT_ON_OOM_LOCK flag: "this OOM invocation is no different from the global one from the locking perspective. Adding an external flag to control the behavior might be slightly more flexible but it adds a new element. Unless there is a very strong reason for that I would go with the existing locking model." The flag is still present here. Is there a reason to keep it rather than using the existing locking model? Matt Bobrowski also commented on this path: "If contended and we end up waiting here, some forward progress could have been made in the interim. Enough such that this pending OOM event initiated by the call into bpf_out_of_memory() may no longer even be warranted. What do you think about adding an escape hatch here, which could simply be in the form of a user-defined function callback?" After mutex_lock_killable() returns, out_of_memory() is invoked unconditionally. Was this suggestion considered? > + > + if (oc.memcg) > + memcg_memory_event(oc.memcg, MEMCG_OOM); > + > + ret = out_of_memory(&oc); For a memcg-scoped declaration this calls out_of_memory() directly and skips memcg1_oom_prepare(). The in-kernel memcg OOM path goes through mem_cgroup_oom() -> memcg1_oom_prepare() -> mem_cgroup_out_of_memory(), and that is where cgroup v1 handles memory.oom_control: if (READ_ONCE(memcg->oom_kill_disable)) { ... return false; /* no in-kernel OOM kill */ } mem_cgroup_mark_under_oom(memcg); *locked = mem_cgroup_oom_trylock(memcg); if (*locked) mem_cgroup_oom_notify(memcg); Consider a v1 memcg with 1 written to memory.oom_control, with OOM handling left to userspace via the eventfd notification. A SYSCALL program can get that memcg with bpf_task_get_cgroup1() and bpf_get_mem_cgroup(&cgrp->self) and call bpf_out_of_memory(memcg, 0, 0). Would select_bad_process() -> mem_cgroup_scan_tasks() -> oom_kill_process() then SIGKILL a task in that memcg despite oom_kill_disable, without setting under_oom or calling mem_cgroup_oom_notify()? The only other caller that skips memcg1_oom_prepare() is memory_max_write(), which exists only on cgroup v2, and the series handles v1 elsewhere (bpf_oom_cgroup() has a v1 fallback, bpf_mem_cgroup_raise_max() handles v1). Should bpf_out_of_memory() honor oom_kill_disable, or reject v1 memcgs? No later commit in the series appears to address this. [ ... ] > +BTF_KFUNCS_START(bpf_declare_oom_kfuncs) > +BTF_ID_FLAGS(func, bpf_out_of_memory, KF_SLEEPABLE) > +BTF_KFUNCS_END(bpf_declare_oom_kfuncs) Should bpf_out_of_memory() carry KF_PERFMON or a stronger gate? It is registered for BPF_PROG_TYPE_SYSCALL with only KF_SLEEPABLE and its body has no capability check. Loading a SYSCALL program needs only CAP_BPF (or a BPF token delegating the type). In bpf_prog_load(), BPF_PROG_TYPE_SYSCALL is in neither is_perfmon_prog_type() nor is_net_admin_prog_type(), and bpf_prog_test_run() adds no further check. With that alone a task can call bpf_out_of_memory(NULL, 0, 0): bpf_prog_test_run_syscall() -> bpf_out_of_memory() -> mutex_trylock(&oom_lock) -> out_of_memory(&oc) -> select_bad_process() /* for_each_process, highest badness */ -> oom_kill_process() -> __oom_kill_process() -> do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID) That sends SIGKILL to the largest killable process on the host regardless of owner. Repeated calls kill one process after another, the kill path ignores panic_on_oom, and no real memory pressure is needed. Commit 3e03955a6518 ("bpf: Require CAP_PERFMON for kfuncs that leak pointers or touch tasks") says that "Syscall, tc, XDP and cgroup programs load without CAP_PERFMON and can call kfuncs that give more than CAP_BPF stands for: ... bpf_send_signal_task() and the kfuncs of task work act on any task", and marked bpf_send_signal_task() with KF_PERFMON. bpf_out_of_memory() acts on arbitrary tasks in the same way. The struct_ops path that kills through bpf_oom_kill_process() is stricter, since BPF_PROG_TYPE_STRUCT_OPS is a perfmon program type. The commit message explains the SYSCALL-only registration as deadlock avoidance and says nothing about privilege. No later commit in the series adds a gate. bpf_oom_proactive_kill(), added in 3beb2d6e2e66 in the same set, has the same exposure. --- 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/46974333971 --===============6742239364527120735==--