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=1796246299; b=ONu/werabQTcMfisVIv24m9o3AbByUdtS97Dzgci461ZoCIGINPpAEV780MWTVxiJd0E XExn4V0fH8NPTvOYL8u5DA8omKiMX+JDLkYuIG+2F0M1ZAdNYFya5oCDVUrGz724JHdHO 5NpUImkuZ2rPcCIXp0NIZAyLCvXx+7vlmkEahfy7liza8nqqibP9GOjk6TD1z8HUdFLY8 ixCVzil9oD1h4aFfmi7Jh7+QL3pWByT3XLi7QvxD+SkGElOLxqSrHpitzxZoltEZfSvHk iikxfXRK3XVLDifRAkXLhL7Lxw1TdonqSdjn2HANBXyjbwirjibniIGUTO+p60UiEJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796246299; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=oRxrs62QXzjv8LRjNHDZjIhth33nSPJE58/W2FMZoJo=; b=EDApY8xH23VPANM+XAiP0HkzFaj2XY5XGNG6N5MmZV7CaeGliOxS9/frdP2emvvpa2ax JETBJatEXE3yUbBzXOBzIG1+8FNXv5XZzk3T3cVtVMaPn5qTttY1fs8RLDNbC9MmULSIn SUIoHtPYjesUN5DkTmoFl0jagP7BIkYVQuRrx/fszc5fLPU4SPiDjkEJjcFUPka5QFDfs 2KDebDl7s43GmHYN+Q6qs+9QBwQQ6KXCKZniOJVvOujVyAxu+Ib+y08kuu1ahJpOQ39B8 1yoAVXD7dHuxkjjdLcgArc/GoeKE5ZMOjQqH27a6g/6cUadOicpiKvIYTSOjwyGwUrg== 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=m4GhPhgX; 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 2F62D606A322 for ; Wed, 2 Dec 2026 21:18:18 +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 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-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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