From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07D70606A322 for ; Wed, 2 Dec 2026 21:18:23 +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=m4GhPhgX Received: by kanga.kvack.org (Postfix) id 2A22E6B05C5; Wed, 2 Dec 2026 16:18:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 279656B05C6; Wed, 2 Dec 2026 16:18:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B7366B05CE; Wed, 2 Dec 2026 16:18:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 980686B05C5 for ; Wed, 2 Dec 2026 16:18:21 -0500 (EST) Received: from smtpin26.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 310861404E5 for ; Wed, 2 Dec 2026 21:18:21 +0000 (UTC) X-FDA: 85500306402.26.ADC3AC7 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf29.hostedemail.com (Postfix) with ESMTP id 85E9E120008 for ; Wed, 2 Dec 2026 21:18:19 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=m4GhPhgX; spf=pass (imf29.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796246299; b=3hxLwzJhFxyBi82rxFd66zI95oiXm8faYsnp+CQc1BYxN41NO3Vg1rcAvcvzddljkwz4I7 hYfW9CIodOAlP8N6CoC7pbYmcf0zLeLNx1zuItm36Kob2CLEsEc/xYM/Fih544Q6TVE4DT nIW6TjI1X2xOVhUlVzaCKMfdP1O3QAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796246299; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oRxrs62QXzjv8LRjNHDZjIhth33nSPJE58/W2FMZoJo=; b=N2rq2u4el+7C/aHlDBDISVy6QuWm+uqkd99g0wW5uxfVTr0FsUQPA0ounMYbCmgW51KnCM DIn0JicDnNkqgsqPK9rCuAT5JaTNRyQ0Td1PqS7ewqIdaxVvMJn/wvwkqVBnztjkQy1ULj GO4xcxZfhMygrNzZ39CCcN/otlee+5c= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=m4GhPhgX; spf=pass (imf29.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 097F760623; Wed, 2 Dec 2026 21:18:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7888B1F00893; Wed, 2 Dec 2026 21:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796246298; bh=oRxrs62QXzjv8LRjNHDZjIhth33nSPJE58/W2FMZoJo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=m4GhPhgX1+ug75gEhRVDRMDE5RvnQt6P4ZKrlU2emEgYHtxbAI3My0/GcfRD0Q4LG Pz8oT7v/zeToSSRqnYQkKEmUs6VYVww4MVds6ZT5orh0CmDlXPv9TXg5SIBRp26HbL /S1rwLJWDX5d5GE2raPapqW3XSFaPBD23omotSEEvMF/+flXkU8bLx8kcZbge1CH/i 8btWpBTedxuwFotoEIZvQYyhE4W0xlnqztqYyS7RIN5tSj5Q/+fXDuOVy0YBP1USg+ oegfsHRr8rX4zscnlXlkyjweALb+8ftnnkBSRo7fWpDH9sZzEVc9sT1DRS9Lp0D3lm 0asG//hca+nRg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next v4 04/17] mm, bpf: introduce bpf_out_of_memory() BPF kfunc Reply-To: sashiko-reviews@lists.linux.dev To: "Ben Gardon" , "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Andrew Morton" , "Johannes Weiner" , "Michal Hocko" , "Shakeel Butt" , "Roman Gushchin" , "Tejun Heo" Cc: "JP Kobryn" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "Ihor Solodrai" , "David Rientjes" , "Suren Baghdasaryan" , "Josh Don" , "Sweet Tea Dorminy" , "Chuyi Zhou" , "Yafang Shao" , benbwgardon@gmail.com, bpf@vger.kernel.org, linux-mm@kvack.org, "Michal Hocko" , mkoutny@suse.com In-Reply-To: <20261202210415.517651-5-bgardon@google.com> References: <20261202210415.517651-1-bgardon@google.com> <20261202210415.517651-5-bgardon@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 21:18:17 +0000 X-Rspamd-Server: rspam08 X-Rspam-User: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolear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5pgkDKvhrYoiq idkrsRvu gV2EsyA/sYOAj8+ci6xxuY6VcxkY57IMzZhUF1s6iKLR097JTfdW7KP8qztURvClOkmUgbd3X6xRUl28x6lKZExBVX4oGAJu68NW+I9xWZscqRGvkpa9tEGlR73CyQA+dIpXdKUBvEwyBHZe0sBqeLF4ZmzoIYOXvkBDILPYyVF9H2dmhEAepVL4DYkmkPr+hRc4sDhqhXmVhg4nDUCYpMmlls7a8O705XceXVnisOyY1gld40sqK0y6BesP09D7hZrdpxuoV33f+hPvjabaDck4TQpAOVBgubKruzQrUmNqOb5gIkSU7H6nFOc3IX+xxWibhyhc58YRoWLpgt9HJG/VIndMS88ljIx1je0SrqpPykwaFZxSiFxqj0J2u8bSxEMNFi6LlyKp0cgxkBX648X3VTwCv/qaZsvTaHzTIU5fbzoKXEFKsZhasugFmqKN3EpD0Q6TQqmT7YDWNFna9PrqU+6wp4lc2ySFGwB9+UYZT1MTbGBiby1+gF0tDGK7n3vtgyA1IM7RHB/M7p4z+96zk9RmYixHmGr1pHqEMhOIl5UbNt96gMT/c/AUvOHJkgMHQvL/DokkUJJnTsRt6II1DjmvUqciNP1oR26Imjyf9jZ1Mea95qdJlnd1i9uRvRU2Jntq0zkL4nirI01XYuGVwlHByRp6z5cTO9Nug1KnG2qeZOF1rBayelk09FzdIA1AwV7mts3B4IdckilNgG4vPLNNc8Y4GVO+VjVKrYybJhYomo6OTmLUyJ1PWFd810Lku3npiuvO3ItrWMYH7rRfqP6LwcOQ5jDIfBcnL3NTy5a23Du7ey0opGpKPIKypuCNTjLAzHuhWhE+zw81SyZbegaQsxFAzbypiwkJFQaETOzfYSLQECi+FAPAByeIKn6vmMfHzciiLbCSN6Q+mWzFl2lAtfFpx1zRmCsX86q7pophjmkW0N7ZcGA== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] mm: unguarded task_will_free_mem() in out_of_memory() for BPF-declared OOMs - [Medium] mm: oom_cpuset_eligible() filters global BPF OOM victims by current cpuset - [Low] mm, bpf: inconsistent dump_header() handling for BPF-declared OOMs -- commit 9e727626010671020de30395390afd2758b2e296 Author: Roman Gushchin mm, bpf: introduce bpf_out_of_memory() BPF kfunc This commit introduces the bpf_out_of_memory() kfunc to allow BPF programs to proactively declare an OOM condition and invoke OOM handling. > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 85da2a39e18a1..9b5df00f98abd 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c [ ... ] > @@ -1024,7 +1026,8 @@ static void oom_kill_process(struct oom_control *oc= , const char *message) > task_unlock(victim); > =20 > if (__ratelimit(&oom_rs)) { > - dump_header(oc); > + if (!is_bpf_declared_oom(oc)) > + dump_header(oc); > dump_oom_victim(oc, victim); > } > =20 [ ... ] > @@ -1138,7 +1141,8 @@ bool out_of_memory(struct oom_control *oc) > oc->nodemask =3D NULL; > check_panic_on_oom(oc); > =20 > - if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task && > + if (!is_memcg_oom(oc) && !is_bpf_declared_oom(oc) && > + sysctl_oom_kill_allocating_task && > current->mm && !oom_unkillable_task(current) && > oom_cpuset_eligible(current, oc) && > current->signal->oom_score_adj !=3D OOM_SCORE_ADJ_MIN) { [Severity: Medium] Should the task_will_free_mem(current) shortcut earlier in out_of_memory() also check !is_bpf_declared_oom(oc)? mm/oom_kill.c:out_of_memory() { ... if (task_will_free_mem(current)) { mark_oom_victim(current); queue_oom_reaper(current); return true; } ... } If the task calling bpf_out_of_memory() has a pending fatal signal or is in a concurrent group exit (when BPF_OOM_FLAGS_WAIT_ON_OOM_LOCK is unset, when oom_lock is acquired on the uncontended fastpath, or when SIGKILL arrives after taking oom_lock), out_of_memory() treats current as an allocating task, marks and reaps it as the OOM victim, and returns true without running OOM handling on the target domain. > @@ -1165,7 +1169,8 @@ bool out_of_memory(struct oom_control *oc) > * system level, we cannot survive this and will enter > * an endless loop in the allocator. Bail out now. > */ > - if (!is_sysrq_oom(oc) && !is_memcg_oom(oc)) > + if (!is_sysrq_oom(oc) && !is_memcg_oom(oc) && > + !is_bpf_declared_oom(oc)) > panic("System is deadlocked on memory\n"); > } > if (oc->chosen && oc->chosen !=3D (void *)-1UL) [Severity: Low] Should dump_header(oc) in the !oc->chosen path right above this check also be skipped (or ratelimited) when is_bpf_declared_oom(oc) is true? Repeated bpf_out_of_memory() calls on a domain with no killable tasks will otherwise emit unratelimited stack traces, meminfo, and task dumps for current. Conversely, because oom_handler_name(oc) is only logged inside dump_header(), skipping dump_header() in oom_kill_process() for BPF-declared OOMs suppresses logging the active bpf_oom_ops handler name when a victim is killed. > @@ -1319,6 +1324,66 @@ __bpf_kfunc int bpf_oom_kill_process(struct oom_co= ntrol *oc, > return 0; > } > =20 > +/** > + * bpf_out_of_memory() - Declare an OOM condition and invoke OOM handling > + * @memcg__nullable: target memory cgroup, or NULL for system-wide OOM > + * @order: allocation page order (0..MAX_PAGE_ORDER), passed through to > + * bpf_oom_ops handlers as a memory-reclaim size hint > + * @flags: bitmask of &enum bpf_oom_flags > + * > + * Synchronizes on oom_lock: waits (interruptible by fatal signals) when > + * BPF_OOM_FLAGS_WAIT_ON_OOM_LOCK is set, or returns -EBUSY immediately = if > + * oom_lock is contended. Root @memcg__nullable is normalized to NULL > + * (system-wide OOM); dying memory cgroups are rejected with -EINVAL. > + * > + * Return: 1 if forward progress was made, 0 if no process was terminate= d, or a > + * negative errno on failure. > + */ > +__bpf_kfunc int bpf_out_of_memory(struct mem_cgroup *memcg__nullable, > + int order, u64 flags) > +{ > + struct oom_control oc =3D { > + .gfp_mask =3D GFP_KERNEL, > + .order =3D order, > + .bpf_declared =3D true, > + }; > + int ret; > + > + if (flags & ~BPF_OOM_FLAGS_ALL) > + return -EINVAL; > + > + /* > + * Keep order so callers can signal a higher-order memory need to > + * reactive bpf_oom_ops handlers (or exercise high-order OOM policies). > + */ > + if (oc.order < 0 || oc.order > MAX_PAGE_ORDER) > + return -EINVAL; > + > + if (memcg__nullable && mem_cgroup_is_root(memcg__nullable)) > + memcg__nullable =3D NULL; > + > + if (memcg__nullable && memcg_is_dying(memcg__nullable)) > + return -EINVAL; > + > + oc.memcg =3D memcg__nullable; > + > + if (flags & BPF_OOM_FLAGS_WAIT_ON_OOM_LOCK) { > + ret =3D mutex_lock_killable(&oom_lock); > + if (ret) > + return ret; > + } else if (!mutex_trylock(&oom_lock)) { > + return -EBUSY; > + } > + > + if (oc.memcg) > + memcg_memory_event(oc.memcg, MEMCG_OOM); > + > + ret =3D out_of_memory(&oc); > + > + mutex_unlock(&oom_lock); > + return ret; > +} [Severity: Medium] On a system-wide BPF-declared OOM (oc.memcg =3D=3D NULL and oc.nodemask =3D= =3D NULL), if execution falls back to select_bad_process(), does oom_evaluate_task() -> oom_cpuset_eligible() unintentionally filter candidate victims against current's cpuset? mm/oom_kill.c:oom_cpuset_eligible() { ... if (mask) { ret =3D mempolicy_in_oom_domain(tsk, mask); } else { ret =3D cpuset_mems_allowed_intersects(current, tsk); } ... } Under CONFIG_NUMA, if the task calling bpf_out_of_memory() is confined to a cpuset covering a subset of NUMA nodes, tasks on disjoint NUMA nodes will be skipped as ineligible even though the declared OOM is unconstrained acro= ss the whole system. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202210415.5176= 51-1-bgardon@google.com?part=3D4