From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CD042BEFE8 for ; Mon, 2 Feb 2026 04:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770007758; cv=none; b=dPyjPx52M9UPsjgqzZAM6rfhG9YhEhRd6/p/XqPTQjODAOswgXe4BZR8bzsVtMQJCVnQP+4wh4l6vuRGciqJ1ovtWklzI15rnA8EWpTHDL/MrO/CiuADy00dXn4iYh7bMDmQAzGzfreDkihWvC5d5eKcuFtJJjHnnMT13lFNkgQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770007758; c=relaxed/simple; bh=riFaidnk/OLlPdzxwI2+yuXF9ybDODW3OZnO3ACZn8Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eEtRYW7zHybnawsgI7JtsfhkZLfL4cR4OWkOB+VAmrl8tdgqBBvAaYG6pqstSnh56W1UfrMRf+ew0HmdG/c53pRtTyAXc73KVccrd0iXo5blRFcVWhmx7W2UG7Ydy9R2sEBKVcTZQDrvNWE97UeS1Mqlrk2b1an6NGiA6m6f+Jg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=US1f3KK4; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="US1f3KK4" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-658b6757f7fso7346290a12.1 for ; Sun, 01 Feb 2026 20:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770007754; x=1770612554; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iI1Ccr3tQDh02EONmID1TL3UlMW3pFDSOrDm5zM+CFg=; b=US1f3KK4YBsmzBFjCbj95DIAzr0k4SslpOhqQJgnzDOrxNIyvoaGia7EBugGTAghCC uv1mISiom7DVpDU4Qw6JiGI1YoygJIKRBbsWjo1FcW1H52ZCEaSDC59IiHOZ513vtB7q nP/ZC+buO4eq/zUUER/o8LZ1zShyohO8gBQoa0e8sfW0es9W24FhyoR2jIsBNnqqN9j5 44syNa26OmZ7j9uhHP42aprRkxD8XJJ/sjJ+n40XLb1ouzbWy9BIMi7k9dknM0GXGkXr 7kp1UP+ivrbqZL8Xzw6juDlOI7xz3WWK3lvoUUJll06Q3giJUvwfHouUYr06vECpglxo RjlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770007754; x=1770612554; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iI1Ccr3tQDh02EONmID1TL3UlMW3pFDSOrDm5zM+CFg=; b=N/M8It43fj9MSE9Rjq37X70FRrmBv52JNBpYcxyfqYXrfcLyxnnfJN0OB0SnY4iRrW AcgIx3zTTwN6yNSYVzanQdgnehzQ/bqbeEpF3FIqbZlbRxtSput7962ADPeIah4Gq9Su tzlA3JTY7X2etCiOvdeyMEhDAqwRNpU6zgh7cabhmAcG4CrDRKu+C7JLMmAD7XXDetGm uVD+PA+NLcW0v3KhaelSq8UdBlBuUiyPuixJ+rbql7u5sgkJjg/ImPwbqgdHyW6f0qHW qytuwwQIb1rViBf+UPMbQT4TZvOChY7i8937REUVPnJotDLKzPg7UeoWWDa19AvVt9DL QCiQ== X-Forwarded-Encrypted: i=1; AJvYcCWvMD7l6ANZmHEb92SuEXl3NBgvXbz+4Z9ECrr4E9rTxnDqxtA2EM9NTjpalQolLHzyVJneNU1xJo3//No=@vger.kernel.org X-Gm-Message-State: AOJu0Yyw4cWaPC9ihVOZmvWO6u/95dTMd0BvDnX0M/eHRVOlxwCA94Gt QMFcY6yz/Qlc1jMLFJC+3ScaUq8ygFpamiRVBnR3ctV/QMeRXEEPFSOIQZAj3zqTfw== X-Gm-Gg: AZuq6aK3xYT7RDy41wW7nFE5Em+MnceEvGGCRJqdgENEahG/lkBPpIZ1Ui0zAP36PZp lMrylTh6x24nqJOwTlrOM4Hb/I0bgkAo+lXxGkpMtnCSQt42aaKjYFh+Uq61RZjLoOTpsNgw3HD YWyXHH4+tHK87BQmaSYytKtt8cX96pyyVIn0uMvNkxDwEyX1Wa6yEaKCwBsxXH/4txjN36tM53o uoeOiUH5CDgKNHKrpSZ2nHFC2EUsx7pfrqzgcB8NW4HBeV0tcjkA0ER4SsmFCMiq0uu9rpgKmrl 8dW9yKOKeoQ+9Td8SBvHNXEVjh5miB6SQ8SNkHIfrscpY3smke+UB9ugwjgztxy2V1AXhy20WAD izXFOIbbW/Jitb+WJWsJSZ4gWdntyyWnPW067maq0Y9LES9TmKdDhxjTCHdSGcJIgJGPcq4O4fs +tCeTPZ0W5PEpf3d8qcm6PELVOoDYa8wYDJ9ErGwYKbClPwV7ed/I= X-Received: by 2002:a05:6402:1646:b0:64a:86db:526a with SMTP id 4fb4d7f45d1cf-658cb1cc407mr6482647a12.4.1770007754306; Sun, 01 Feb 2026 20:49:14 -0800 (PST) Received: from google.com (93.50.90.34.bc.googleusercontent.com. [34.90.50.93]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-658b42563dbsm7592239a12.3.2026.02.01.20.49.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Feb 2026 20:49:13 -0800 (PST) Date: Mon, 2 Feb 2026 04:49:09 +0000 From: Matt Bobrowski To: Roman Gushchin Cc: bpf@vger.kernel.org, Michal Hocko , Alexei Starovoitov , Shakeel Butt , JP Kobryn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Suren Baghdasaryan , Johannes Weiner , Andrew Morton Subject: Re: [PATCH bpf-next v3 08/17] mm: introduce bpf_oom_kill_process() bpf kfunc Message-ID: References: <20260127024421.494929-1-roman.gushchin@linux.dev> <20260127024421.494929-9-roman.gushchin@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260127024421.494929-9-roman.gushchin@linux.dev> On Mon, Jan 26, 2026 at 06:44:11PM -0800, Roman Gushchin wrote: > Introduce bpf_oom_kill_process() bpf kfunc, which is supposed > to be used by BPF OOM programs. It allows to kill a process > in exactly the same way the OOM killer does: using the OOM reaper, > bumping corresponding memcg and global statistics, respecting > memory.oom.group etc. > > On success, it sets the oom_control's bpf_memory_freed field to true, > enabling the bpf program to bypass the kernel OOM killer. > > Signed-off-by: Roman Gushchin > --- > mm/oom_kill.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 80 insertions(+) > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 44bbcf033804..09897597907f 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -46,6 +46,7 @@ > #include > #include > #include > +#include > > #include > #include "internal.h" > @@ -1290,3 +1291,82 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags) > return -ENOSYS; > #endif /* CONFIG_MMU */ > } > + > +#ifdef CONFIG_BPF_SYSCALL > + > +__bpf_kfunc_start_defs(); > +/** > + * bpf_oom_kill_process - Kill a process as OOM killer > + * @oc: pointer to oom_control structure, describes OOM context > + * @task: task to be killed > + * @message__str: message to print in dmesg > + * > + * Kill a process in a way similar to the kernel OOM killer. > + * This means dump the necessary information to dmesg, adjust memcg > + * statistics, leverage the oom reaper, respect memory.oom.group etc. > + * > + * bpf_oom_kill_process() marks the forward progress by setting > + * oc->bpf_memory_freed. If the progress was made, the bpf program > + * is free to decide if the kernel oom killer should be invoked. > + * Otherwise it's enforced, so that a bad bpf program can't > + * deadlock the machine on memory. > + */ > +__bpf_kfunc int bpf_oom_kill_process(struct oom_control *oc, > + struct task_struct *task, > + const char *message__str) > +{ > + if (oom_unkillable_task(task)) > + return -EPERM; > + > + if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MIN) > + return -EINVAL; task->signal->oom_score_adj == OOM_SCORE_ADJ_MIN is also representative of an unkillable task, so why not fold this up into the above conditional? Also, why not bother checking states like mm_flags_test(MMF_OOM_SKIP, task->mm) and in_vfork() here too? In all fairness I'm a little surprised about constraints like task->signal->oom_score_adj == OOM_SCORE_ADJ_MIN being enforced here. You could argue that the whole purpose of BPF OOM is such that you can implement your own victim selection algorithms entirely in BPF using your own set of heuristics and what not without needing to strictly respect properties like oom_score_adj. In any case, I think we should at least clearly document such constraints. > + /* paired with put_task_struct() in oom_kill_process() */ > + get_task_struct(task); > + > + oc->chosen = task; > + > + oom_kill_process(oc, message__str); > + > + oc->chosen = NULL; > + oc->bpf_memory_freed = true; > + > + return 0; > +} > + > +__bpf_kfunc_end_defs(); > + > +BTF_KFUNCS_START(bpf_oom_kfuncs) > +BTF_ID_FLAGS(func, bpf_oom_kill_process, KF_SLEEPABLE) > +BTF_KFUNCS_END(bpf_oom_kfuncs) > + > +BTF_ID_LIST_SINGLE(bpf_oom_ops_ids, struct, bpf_oom_ops) > + > +static int bpf_oom_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id) > +{ > + if (prog->type != BPF_PROG_TYPE_STRUCT_OPS || > + prog->aux->attach_btf_id != bpf_oom_ops_ids[0]) > + return -EACCES; > + return 0; > +} > + > +static const struct btf_kfunc_id_set bpf_oom_kfunc_set = { > + .owner = THIS_MODULE, > + .set = &bpf_oom_kfuncs, > + .filter = bpf_oom_kfunc_filter, > +}; > + > +static int __init bpf_oom_init(void) > +{ > + int err; > + > + err = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, > + &bpf_oom_kfunc_set); > + if (err) > + pr_warn("error while registering bpf oom kfuncs: %d", err); > + > + return err; > +} > +late_initcall(bpf_oom_init); > + > +#endif > -- > 2.52.0 >