bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Quentin Monnet <qmo@kernel.org>
Cc: bpf@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>,
	Cupertino Miranda <cupertino.miranda@oracle.com>,
	David Faust <david.faust@oss.qualcomm.com>,
	Ian Rogers <irogers@google.com>,
	"Jose E . Marchesi" <jose.marchesi@oracle.com>,
	Vineet Gupta <vineet.gupta@linux.dev>,
	Yonghong Song <yonghong.song@linux.dev>
Subject: [PATCH bpf-next v4 16/17] bpftool: Render the arena type tag as __bpf_arena
Date: Thu,  5 Nov 2026 10:58:44 -0700	[thread overview]
Message-ID: <20261105175845.30357-17-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20261105175845.30357-1-ihor.solodrai@linux.dev>

Kernel structs shared with BPF programs mark pointers into a BPF arena
with __arena, which kernel BTF carries as a plain "arena" type tag
that the verifier relies on. btf_dump prints the tag as
__attribute__((btf_type_tag("arena"))) on a pointer in the default
address space, so a program built against vmlinux.h has to cast such a
pointer to the arena address space before using it.

Attach a kflagged decl tag to each "arena" type tag in the dump split,
so that btf_dump prints __bpf_arena instead. In the generated header:

  #define __bpf_arena __attribute__((address_space(1))) __attribute__((btf_type_tag("arena")))

So the program gets an arena pointer and its BTF keeps the tag the
kernel expects. Programs can pre-define the macro.

Use __bpf_arena to avoid conflicts with unguarded __arena definitions
in libarena and sched_ext headers.

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
 tools/bpf/bpftool/Documentation/bpftool-btf.rst            | 6 ++++++
 tools/bpf/bpftool/btf.c                                    | 5 +++++
 .../testing/selftests/bpf/bpftool_btf_dump_sorted.expected | 4 ++++
 .../selftests/bpf/bpftool_btf_dump_unsorted.expected       | 4 ++++
 .../selftests/bpf/prog_tests/test_struct_ops_arena.c       | 2 +-
 .../selftests/bpf/progs/struct_ops_arena_member_render.c   | 7 +++----
 6 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/tools/bpf/bpftool/Documentation/bpftool-btf.rst b/tools/bpf/bpftool/Documentation/bpftool-btf.rst
index a3778f449d73..9fe035b80103 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-btf.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-btf.rst
@@ -123,6 +123,12 @@ a type marked ``__bpf_static_offset``, including through ``bpf_core_field_*``
 and the CO-RE bitfield helpers. Compile with ``-D__bpf_static_offset=`` to
 use these helpers with an affected compiler.
 
+Pointers carrying the ``arena`` type tag in kernel BTF are rendered with
+``__bpf_arena``. This macro expands to
+``__attribute__((address_space(1))) __attribute__((btf_type_tag("arena")))``,
+so programs can use the pointers without explicit casts. Define
+``__bpf_arena`` before including the header to override it.
+
 EXAMPLES
 ========
 **# bpftool btf dump id 1226**
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 1329745c5854..c06b01f2c5b3 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -1103,6 +1103,8 @@ static const struct {
 } btf_c_type_tags[] = {
 	/* the arena attribute in older kernel BTF */
 	{ true, "address_space(1)", "__attribute__((address_space(1)))" },
+	/* __arena in include/linux/bpf_compiler_types.h */
+	{ false, "arena", "__bpf_arena" },
 };
 
 static int btf_c_annotate_type_tags(struct btf *btf)
@@ -1276,6 +1278,9 @@ static int dump_btf_c(struct btf *btf,
 	printf("#define __bpf_static_offset\n");
 	printf("#endif\n");
 	printf("#endif\n\n");
+	printf("#ifndef __bpf_arena\n");
+	printf("#define __bpf_arena __attribute__((address_space(1))) __attribute__((btf_type_tag(\"arena\")))\n");
+	printf("#endif\n\n");
 	printf("#ifndef __ksym\n");
 	printf("#define __ksym __attribute__((section(\".ksyms\")))\n");
 	printf("#endif\n\n");
diff --git a/tools/testing/selftests/bpf/bpftool_btf_dump_sorted.expected b/tools/testing/selftests/bpf/bpftool_btf_dump_sorted.expected
index 190cf16e49a2..0ecf53b29042 100644
--- a/tools/testing/selftests/bpf/bpftool_btf_dump_sorted.expected
+++ b/tools/testing/selftests/bpf/bpftool_btf_dump_sorted.expected
@@ -17,6 +17,10 @@
 #endif
 #endif
 
+#ifndef __bpf_arena
+#define __bpf_arena __attribute__((address_space(1))) __attribute__((btf_type_tag("arena")))
+#endif
+
 #ifndef __ksym
 #define __ksym __attribute__((section(".ksyms")))
 #endif
diff --git a/tools/testing/selftests/bpf/bpftool_btf_dump_unsorted.expected b/tools/testing/selftests/bpf/bpftool_btf_dump_unsorted.expected
index 1a0a7b016c50..24a8db96eab0 100644
--- a/tools/testing/selftests/bpf/bpftool_btf_dump_unsorted.expected
+++ b/tools/testing/selftests/bpf/bpftool_btf_dump_unsorted.expected
@@ -17,6 +17,10 @@
 #endif
 #endif
 
+#ifndef __bpf_arena
+#define __bpf_arena __attribute__((address_space(1))) __attribute__((btf_type_tag("arena")))
+#endif
+
 #ifndef __ksym
 #define __ksym __attribute__((section(".ksyms")))
 #endif
diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
index e7580b9f0fc2..2e915b350cd2 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
@@ -259,7 +259,7 @@ static void arena_autobind_excl(void)
 	struct_ops_arena_autobind__destroy(skel);
 }
 
-/* The same through the vmlinux.h rendering of the members, which takes casts. */
+/* The same through an older bpftool's vmlinux.h rendering of the members, which takes casts. */
 static void arena_member_render(void)
 {
 	struct struct_ops_arena_member_render *skel;
diff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c b/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c
index 253ffdd86d32..b6b66934266b 100644
--- a/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c
+++ b/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c
@@ -11,10 +11,9 @@
 char _license[] SEC("license") = "GPL";
 
 /*
- * The module types as vmlinux.h renders them: the tag is an attribute on a
- * pointer in the kernel address space, so the program has to cast the member
- * to the arena address space before using it. That is what a program built
- * against vmlinux.h sees for a kernel struct with an __arena member.
+ * The module types as an older bpftool renders them in vmlinux.h: the tag is
+ * an attribute on a pointer in the kernel address space, so the program has
+ * to cast the member to the arena address space before using it.
  */
 #define __arena_tag	__attribute__((btf_type_tag("arena")))
 #define __nullable_tag	__attribute__((btf_type_tag("nullable")))
-- 
2.56.0


  parent reply	other threads:[~2026-11-05 18:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 17:58 [PATCH bpf-next v4 00/17] bpftool: Per-record CO-RE attributes in the C dump Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 01/17] Revert "libbpf: Render the arena type tag with its address space" Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 02/17] libbpf: Look up BTF strings without making BTF modifiable Ihor Solodrai
2026-11-05 18:41   ` bot+bpf-ci
2026-11-05 17:58 ` [PATCH bpf-next v4 03/17] bpftool: Dump C through a split BTF Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 04/17] selftests/bpf: Build BTF fixtures in btf_to_tmpfile() Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 05/17] selftests/bpf: Cover unknown BTF header-extension bytes in bpftool C dumps Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 06/17] libbpf: Let decl tags override how btf_dump renders type tags Ihor Solodrai
2026-11-06  0:24   ` Andrii Nakryiko
2026-11-05 17:58 ` [PATCH bpf-next v4 07/17] libbpf, bpftool, resolve_btfids: Dump kflagged BTF tags as is Ihor Solodrai
2026-11-05 18:16   ` sashiko-bot
2026-11-06  0:25   ` Andrii Nakryiko
2026-11-05 17:58 ` [PATCH bpf-next v4 08/17] selftests/bpf: Cover type tag rendering overrides in btf_dump Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 09/17] selftests/bpf: Cover legacy arena type tags in bpftool C dumps Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 10/17] bpftool: Apply __bpf_relocatable per record on BTF dump Ihor Solodrai
2026-11-05 18:41   ` bot+bpf-ci
2026-11-05 17:58 ` [PATCH bpf-next v4 11/17] bpftool: Skip __bpf_relocatable on verifier-rewritten context types Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 12/17] bpftool: Emit __bpf_static_offset " Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 13/17] selftests/bpf: Cover record attributes in bpftool BTF dumps Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 14/17] selftests/bpf: Cover context and socket accesses through vmlinux.h Ihor Solodrai
2026-11-05 17:58 ` [PATCH bpf-next v4 15/17] bpftool: Document __bpf_relocatable and __bpf_static_offset Ihor Solodrai
2026-11-05 17:58 ` Ihor Solodrai [this message]
2026-11-05 17:58 ` [PATCH bpf-next v4 17/17] selftests/bpf: Cover the arena type tag in bpftool C dumps Ihor Solodrai
2026-11-06  0:30 ` [PATCH bpf-next v4 00/17] bpftool: Per-record CO-RE attributes in the C dump 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=20261105175845.30357-17-ihor.solodrai@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cupertino.miranda@oracle.com \
    --cc=daniel@iogearbox.net \
    --cc=david.faust@oss.qualcomm.com \
    --cc=eddyz87@gmail.com \
    --cc=irogers@google.com \
    --cc=jose.marchesi@oracle.com \
    --cc=memxor@gmail.com \
    --cc=qmo@kernel.org \
    --cc=vineet.gupta@linux.dev \
    --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;
as well as URLs for NNTP newsgroup(s).