On Thu, Aug 28, 2025 at 6:51 PM Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx> wrote: > > On Wed, Aug 27, 2025 at 02:50:36PM -0700, Andrii Nakryiko wrote: > > On Wed, Aug 27, 2025 at 8:48 AM Lorenzo Stoakes > > <lorenzo.stoakes@xxxxxxxxxx> wrote: > > > > > > On Tue, Aug 26, 2025 at 03:19:41PM +0800, Yafang Shao wrote: > > > > We will utilize this new kfunc bpf_mm_get_task() to retrieve the > > > > associated task_struct from the given @mm. The obtained task_struct must > > > > be released by calling bpf_task_release() as a paired operation. > > > > > > You're basically describing the patch you're not saying why - yeah you're > > > getting a task struct from an mm (only if CONFIG_MEMCG which you don't > > > mention here), but not for what purpose you intend to use this? > > > > > > > > > > > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx> > > > > --- > > > > mm/bpf_thp.c | 34 ++++++++++++++++++++++++++++++++++ > > > > 1 file changed, 34 insertions(+) > > > > > > > > diff --git a/mm/bpf_thp.c b/mm/bpf_thp.c > > > > index b757e8f425fd..46b3bc96359e 100644 > > > > --- a/mm/bpf_thp.c > > > > +++ b/mm/bpf_thp.c > > > > @@ -205,11 +205,45 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg) > > > > #endif > > > > } > > > > > > > > +/** > > > > + * bpf_mm_get_task - Get the task struct associated with a mm_struct. > > > > + * @mm: The mm_struct to query > > > > + * > > > > + * The obtained task_struct must be released by calling bpf_task_release(). > > > > > > Hmmm so now bpf programs can cause kernel bugs by keeping a reference around? > > > > BPF verifier will reject any program that cannot guarantee that > > bpf_task_release() will always be called. So there shouldn't be any > > problem here. > > Ah that's nice! > > What specifically here is enforcing that? Apologies again - BPF is new to me. The KF_ACQUIRE and KF_RELEASE flags enforce resource management. If a BPF helper function (e.g., bpf_mm_get_task()) is marked with KF_ACQUIRE, the pointer it returns must be released by a corresponding helper marked with KF_RELEASE (e.g., bpf_task_release()). The BPF verifier will reject any program that fails to pair these calls correctly. -- Regards Yafang