BPF List
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Alan Maguire" <alan.maguire@oracle.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	<dwarves@vger.kernel.org>
Cc: <bpf@vger.kernel.org>, "Andrii Nakryiko" <andrii@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Tejun Heo" <tj@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>
Subject: Re: [PATCH dwarves] btf_encoder: Infer arena kfunc arguments from suffixes
Date: Tue, 04 Aug 2026 21:27:31 +0200	[thread overview]
Message-ID: <DKGENYO9FITK.1M51V4BULBSYT@gmail.com> (raw)
In-Reply-To: <4cb8bb30-1f01-4b78-a6b1-4ade3b965039@linux.dev>

On Tue Aug 4, 2026 at 8:43 PM CEST, Ihor Solodrai wrote:
> On 8/3/26 5:55 AM, Kumar Kartikeya Dwivedi wrote:
>> The kernel verifier recognizes __arena and __arena_nullable parameter
>> suffixes for registered kfuncs. These arguments need the matching
>> address_space(1) BTF type attribute so bpftool emits usable declarations.
>
> Hi Kartikeya,
>
> +cc: Emil, Tejun
>
> This patch is certainly a no-go, because of the ongoing effort to move
> decl/type tag BTF generation from pahole to resolve_btfids [1][2]. I'm
> going to send the last unlanded bits of that soon.
>
> *If* we decide to make this change, it shouldn't be done in pahole.
>

Ah, I was unaware. Once you share those changes I'd be happy to rework this
support for resolve_btfids instead (i.e., tack it wherever we do
KF_ARENA_ARGS<N> handling right now).

> But even setting that aside:
>
>> The kernel verifier recognizes __arena and __arena_nullable
>> parameter suffixes for registered kfuncs.
>
> This is not true. The only way the kernel can recognize an arena
> argument is via one of the three kfunc flags: KF_ARENA_RET,
> KF_ARENA_ARG1 and KF_ARENA_ARG2. No __arena suffix support exist:
>
>   $ git log --oneline -n1
>   7f333f85f83d (HEAD -> bpf-next, origin/for-next, origin/bpf-next, bpf-next/master, bpf-next/for-next, bpf-next/HEAD) Merge branch 'bpf-invalidate-rcu-pointers-after-final-spin-unlock'
>   $ grep -r --include="*.[ch]" __arena  kernel/bpf/
>     # ...nothing
>

Yeah, I worded it poorly, I meant it was supposed to gain support for those
soon^TM, by way of the series here:
https://lore.kernel.org/bpf/20260803125115.2264733-1-memxor@gmail.com

> __arena symbol is only used in sched_ext, libarena and selftests code
> as an alias to __atrribute__((address_space(1))) or a type tag:
>
>   $ grep -r --include="*.[ch]" 'define __arena '
>   tools/sched_ext/include/scx/bpf_arena_common.bpf.h:#define __arena __attribute__((address_space(1)))
>   tools/testing/selftests/bpf/libarena/include/bpf_arena_common.h:#define __arena __attribute__((address_space(1))) __attribute__((btf_type_tag("arena")))
>   tools/testing/selftests/bpf/libarena/include/bpf_arena_common.h:#define __arena __attribute__((btf_type_tag("arena")))
>
> AFAIR prior discussions that led to KF_ARENA_* flags implementation,
> we decided to *not* add an __arena arg suffix support. We were talking
> about getting rid of this suffix-annotation mechanism completely.
>
> What we want long term is proper decl/type tags support from
> compilers, so that in the kernel we could have and use:
>
>   #define __arena __attribute__((btf_type_tag("arena")))
>
> At the time KF_ARENA_* flags were introduced, this wasn't feasible
> because GCC compiler didn't support the tags. I think it does since
> recently, but even so we'll have to support older compiler builds for
> quite a while.

I wasn't involved in the discussion for choosing the flag, so I do not remember
the nuance involved in making the choices back then. But please correct me or
provide context in case I do not capture something accurately below.

>
> So while I understand the reluctance to add KF_ARENA_ARG3..N, I don't
> think we want to introduce and support yet another mechanism for arena
> argument annotations. If we do, we'll be stuck with a mess of
> supporting two/three ways of doing the same thing for the foreseeable future.

I think one major difference is that KF_ARENA_ARG* things were mostly for
annotating the vmlinux.h with the right address space label before, but didn't
carry any semantic meaning for the kfunc's type checks.

That changes with these suffixes though. The pointer will be translated when
passed into the kfunc. IMO it would be odd to diverge for this particular case,
since we use suffixes for every other case where we constrain the input type of
the kfunc argument or give it special meaning.

We also want to have similar annotation on struct_ops callbacks, where we also
use suffixes, so it seemed better to keep it consistent.

I agree that all of these should be using type tags, but we're not there yet.

It is on my list of things to explore whether we can convert existing users of
KF_ARENA_ARG<N> flags (bpf_arena_alloc_pages(), etc.). We will have to modify
the implementation, and ensure we don't break compatibility by moving from
ignoring the type of input register to something we constrain to PTR_TO_ARENA
and SCALAR.

At that point, it should be possible to drop the kfunc flags, esp. if we are
worried about fragmenting ways of achieving the same thing (annotation of
vmlinux.h prototypes).

In functional terms, the only change on resolve_btfids side should be to use the
BTF parameter's emitted name for deciding whether it should trigger behavior
equivalent to the current KF_ARENA_ARG flags.

For better or worse, we need to be in this state of supporting suffixes until we
can declare bankruptcy of supporting GCC versions without type tags support.

> [...]

  reply	other threads:[~2026-08-04 19:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 12:55 [PATCH dwarves] btf_encoder: Infer arena kfunc arguments from suffixes Kumar Kartikeya Dwivedi
2026-08-04 18:43 ` Ihor Solodrai
2026-08-04 19:27   ` Kumar Kartikeya Dwivedi [this message]
2026-08-04 20:22     ` Eduard Zingerman
2026-08-04 21:19       ` Ihor Solodrai
2026-08-04 21:34         ` Eduard Zingerman
2026-08-04 21:46           ` Kumar Kartikeya Dwivedi
2026-08-04 21:51             ` Eduard Zingerman
2026-08-04 21:57               ` Kumar Kartikeya Dwivedi
2026-08-04 22:57               ` Ihor Solodrai
2026-08-04 23:17                 ` Kumar Kartikeya Dwivedi
2026-08-04 21:55           ` Ihor Solodrai
2026-08-04 22:05             ` Eduard Zingerman
2026-08-04 22:13               ` Ihor Solodrai
2026-08-04 21:36         ` Kumar Kartikeya Dwivedi

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=DKGENYO9FITK.1M51V4BULBSYT@gmail.com \
    --to=memxor@gmail.com \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox