public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Roman Gushchin <roman.gushchin@linux.dev>
To: Matt Bobrowski <mattbobrowski@google.com>
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>,
	Matt Bobrowski <mattbobrowski@google.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: Thu, 15 Jan 2026 20:54:42 -0800	[thread overview]
Message-ID: <87y0lyxilp.fsf@linux.dev> (raw)
In-Reply-To: Message-ID: <20260113083949.2502978-2-mattbobrowski@google.com>


> 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);

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.

Thanks

  parent reply	other threads:[~2026-01-16  4: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   ` Roman Gushchin [this message]
2026-01-16  7:55     ` Subject: " Matt Bobrowski
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=87y0lyxilp.fsf@linux.dev \
    --to=roman.gushchin@linux.dev \
    --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=mattbobrowski@google.com \
    --cc=memxor@gmail.com \
    --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