All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Bobrowski <mattbobrowski@google.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, g@google.com
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Tejun Heo <tj@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	bpf <bpf@vger.kernel.org>, linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	JP Kobryn <inwardvessel@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Michal Hocko <mhocko@kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
Date: Wed, 7 Jan 2026 09:29:16 +0000	[thread overview]
Message-ID: <aV4nbCaMfIoM0awM@google.com> (raw)
In-Reply-To: <CAP01T75ATFb_gjy5_fSwt6=QMxt7kGSS+12SJN9rz9SfJQ7Qyg@mail.gmail.com>

On Tue, Jan 06, 2026 at 04:13:24PM +0100, Kumar Kartikeya Dwivedi wrote:
> On Mon, 5 Jan 2026 at 22:04, Matt Bobrowski <mattbobrowski@google.com> wrote:
> >
> > On Mon, Jan 05, 2026 at 08:05:54AM -0800, Alexei Starovoitov wrote:
> > > On Sun, Jan 4, 2026 at 11:49 PM Matt Bobrowski <mattbobrowski@google.com> wrote:
> > > >
> > > > >
> > > > > No need for a new KF flag. Any struct returned by kfunc should be
> > > > > trusted or trusted_or_null if KF_RET_NULL was specified.
> > > > > I don't remember off the top of my head, but this behavior
> > > > > is already implemented or we discussed making it this way.
> > > >
> > > > Hm, I do not see any evidence of this kind of semantic currently
> > > > implemented, so perhaps it was only discussed at some point. Would you
> > > > like me to put forward a patch that introduces this kind of implicit
> > > > trust semantic for BPF kfuncs returning pointer to struct types?
> > >
> > > Hmm. What about these:
> > > BTF_ID_FLAGS(func, scx_bpf_cpu_rq)
> > > BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_RET_NULL)
> > > BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_RET_NULL | KF_RCU_PROTECTED)
> > >
> > > I thought they're returning a trusted pointer without acquiring it.
> > > iirc the last one returns trusted in RCU CS,
> > > but the first two return just a legacy ptr_to_btf_id ?
> > > This is something to fix asap then.
> >
> > No, AFAIU they do not. These simply return a regular pointer to BTF ID
> > (PTR_TO_BTF_ID), rather than a formally "trusted" pointer (which would
> > carry the PTR_TRUSTED flag or a ref_obj_id). scx_bpf_cpu_curr returns
> > a MEM_RCU pointer (via KF_RCU_PROTECTED), which is somewhat considered
> > to be trusted within a RCU read-side critical section *ONLY*.
> >
> > Kumar/Tejun,
> 
> Yeah, they don't return a trusted pointer. I think it would make sense
> to change the behavior here by default.

Thanks for chiming in and confirming this Kumar! I also agree that any
BPF kfunc returning a pointer should be treated as being implicitly
trusted by default. I can't think of any scenario whereby a BPF kfunc
would want to return a pointer that'd fundamentally be untrusted, but
there always could be some exceptions. Anyway, I will work on this and
send something through for review soon.

> A non-trusted pointer cannot be passed to kfuncs taking trusted
> arguments, so hopefully it will only make things more permissive and
> doesn't break anything.

We can only hope! ;)

  reply	other threads:[~2026-01-07  9:29 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-23  4:41 [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data Roman Gushchin
2025-12-23  4:41 ` [PATCH bpf-next v4 1/6] mm: declare memcg_page_state_output() in memcontrol.h Roman Gushchin
2025-12-23  4:41 ` [PATCH bpf-next v4 2/6] mm: introduce BPF kfuncs to deal with memcg pointers Roman Gushchin
2025-12-23  4:41 ` [PATCH bpf-next v4 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc Roman Gushchin
2025-12-30 20:27   ` Matt Bobrowski
2025-12-30 21:00     ` Roman Gushchin
2025-12-31  7:41       ` Matt Bobrowski
2025-12-31 17:02         ` Roman Gushchin
2025-12-31 17:32         ` Alexei Starovoitov
2026-01-05  7:49           ` Matt Bobrowski
2026-01-05 16:05             ` Alexei Starovoitov
2026-01-05 21:04               ` Matt Bobrowski
2026-01-06 15:13                 ` Kumar Kartikeya Dwivedi
2026-01-07  9:29                   ` Matt Bobrowski [this message]
2025-12-23  4:41 ` [PATCH bpf-next v4 4/6] mm: introduce BPF kfuncs to access memcg statistics and events Roman Gushchin
2025-12-23  4:41 ` [PATCH bpf-next v4 5/6] bpf: selftests: selftests for memcg stat kfuncs Roman Gushchin
2025-12-23  4:41 ` [PATCH bpf-next v4 6/6] MAINTAINERS: add an entry for MM BPF extensions Roman Gushchin
2025-12-23 19:25 ` [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data Alexei Starovoitov
2025-12-23 19:57   ` Roman Gushchin
2025-12-24  3:41   ` Konstantin Ryabitsev
2025-12-23 19:46 ` Shakeel Butt
2025-12-24  3:01 ` Yafang Shao
2025-12-25  1:16   ` Roman Gushchin

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=aV4nbCaMfIoM0awM@google.com \
    --to=mattbobrowski@google.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=g@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=inwardvessel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=memxor@gmail.com \
    --cc=mhocko@kernel.org \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.