public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Bobrowski <mattbobrowski@google.com>
To: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	ohn Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Jiri Olsa <jolsa@kernel.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	bpf <bpf@vger.kernel.org>
Subject: Re: Subject: [PATCH bpf-next 2/3] bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()
Date: Fri, 16 Jan 2026 07:55:37 +0000	[thread overview]
Message-ID: <aWnu-b0dlm0xZFDS@google.com> (raw)
In-Reply-To: <87y0lyxilp.fsf@linux.dev>

On Thu, Jan 15, 2026 at 08:54:42PM -0800, Roman Gushchin wrote:
> 
> > With the BPF verifier now treating pointers to struct types returned
> > from BPF kfuncs as implicitly trusted by default, there is no need for
> > bpf_get_root_mem_cgroup() to be annotated with the KF_ACQUIRE flag.
> 
> > bpf_get_root_mem_cgroup() does not acquire any references, but rather
> > simply returns a NULL pointer or a pointer to a struct mem_cgroup
> > object that is valid for the entire lifetime of the kernel.
> 
> > This simplifies BPF programs using this kfunc by removing the
> > requirement to pair the call with bpf_put_mem_cgroup().
> 
> It's actually the opposite: having the get semantics (which is also
> suggested by the name) allows to treat the root memory cgroup exactly
> as any other. And it makes the code much simpler, otherwise you
> need to have these ugly checks across the codebase:
> 	if (memcg != root_mem_cgroup)
> 		css_put(&memcg->css);

I mean, you're certainly not forced to do this. But, I do also see
what you mean.

> This is why __all__ memcg && cgroup code follows this principle and the
> hides the special handling of the root memory cgroup within
> css_get()/css_put().
>
> I wasn't cc'ed on this series, otherwise I'd nack this patch.
> If the overhead of an extra kfunc call is a concern here (which I
> doubt), we can introduce a non-acquire bpf_root_mem_cgroup()
> version.
> 
> And I strongly suggest to revert this change.

Apologies, I honestly thought I did CC you on this series. Don't know
what happened with that. Anyway, I'm totally OK with reverting this
patch and keeping bpf_get_root_mem_cgroup() with KF_ACQUIRE
semantics. bpf_get_root_mem_cgroup() was selected as it was the very
first BPF kfunc that came to mind where implicit trusted pointer
semantics should be applied by the BPF verifier.

Notably, the follow up selftest patch [0] will also need to be
reverted if so as it relies on bpf_get_root_mem_cgroup() without
KF_ACQUIRE. We can probably 

[0] https://lore.kernel.org/bpf/20260113083949.2502978-2-mattbobrowski@google.com/T/#mfa14fb83b3350c25f961fd43dc4df9b25d00c5f5

  reply	other threads:[~2026-01-16  7:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-13  8:39 [PATCH bpf-next 1/3] bpf: return PTR_TO_BTF_ID | PTR_TRUSTED from BPF kfuncs by default Matt Bobrowski
2026-01-13  8:39 ` [PATCH bpf-next 2/3] bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup() Matt Bobrowski
2026-01-13  9:25   ` Kumar Kartikeya Dwivedi
2026-01-16  4:54   ` Subject: " Roman Gushchin
2026-01-16  7:55     ` Matt Bobrowski [this message]
2026-01-16 15:22       ` Alexei Starovoitov
2026-01-16 16:12         ` Alexei Starovoitov
2026-01-16 21:18           ` Roman Gushchin
2026-01-20  1:29             ` Alexei Starovoitov
2026-01-20  6:52               ` Matt Bobrowski
2026-01-20  9:19                 ` Matt Bobrowski
2026-01-21  1:00               ` Roman Gushchin
2026-01-21  1:14                 ` Alexei Starovoitov
2026-01-21  9:05                   ` Matt Bobrowski
2026-01-13  8:39 ` [PATCH bpf-next 3/3] selftests/bpf: assert BPF kfunc default trusted pointer semantics Matt Bobrowski
2026-01-13  9:26   ` Kumar Kartikeya Dwivedi
2026-01-13  9:22 ` [PATCH bpf-next 1/3] bpf: return PTR_TO_BTF_ID | PTR_TRUSTED from BPF kfuncs by default Kumar Kartikeya Dwivedi
2026-01-14  3:30 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aWnu-b0dlm0xZFDS@google.com \
    --to=mattbobrowski@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox