From: Yonghong Song <yonghong.song@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
kernel-team@fb.com
Subject: [PATCH bpf-next v2 09/10] selftests/bpf: Test global functions returning arena pointers by value
Date: Tue, 25 Aug 2026 13:54:58 -0700 [thread overview]
Message-ID: <20260825205458.1325916-1-yonghong.song@linux.dev> (raw)
In-Reply-To: <20260825205412.1320099-1-yonghong.song@linux.dev>
Cover the by-value struct returns a global function may now make: two
arena pointers filling R0:R2, an arena pointer beside a scalar, an array
of them, and an eight byte struct returned in R0 alone. The existing
cases for a struct and a union carrying a plain pointer stay rejected.
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
.../selftests/bpf/progs/aggregate_ret_func.c | 118 ++++++++++++++++++
.../selftests/bpf/progs/verifier_arena.c | 37 ++++++
2 files changed, 155 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/aggregate_ret_func.c b/tools/testing/selftests/bpf/progs/aggregate_ret_func.c
index 6f66fc822ced..237adb8e5ee1 100644
--- a/tools/testing/selftests/bpf/progs/aggregate_ret_func.c
+++ b/tools/testing/selftests/bpf/progs/aggregate_ret_func.c
@@ -2,6 +2,7 @@
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
+#include <bpf_arena_common.h>
#include "bpf_misc.h"
typedef unsigned __int128 u128;
@@ -234,4 +235,121 @@ __naked int aggregate_ret_global_union_ptr_fail(void)
#endif
+/*
+ * gcc returns a by-value struct through a hidden pointer, and emits the
+ * 'r0 = r1' returning it after the __naked body's exit, leaving the
+ * subprogram falling through. Build these with clang only.
+ */
+#if defined(__clang__)
+
+struct arena_pair {
+ void __arena *lo;
+ void __arena *hi;
+};
+
+struct arena_and_scalar {
+ void __arena *p;
+ __u64 x;
+};
+
+struct arena_array {
+ void __arena *p[2];
+};
+
+struct arena_single {
+ void __arena *p;
+};
+
+__naked struct arena_pair global_ret_arena_pair(void)
+{
+ asm volatile (
+ "r0 = 0;"
+ "r2 = 0;"
+ "exit;"
+ );
+}
+
+SEC("tc")
+__load_if_JITed()
+__success __retval(0)
+__naked int aggregate_ret_global_arena_pair(void)
+{
+ asm volatile (
+ "call %[global_ret_arena_pair];"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(global_ret_arena_pair)
+ : __clobber_all);
+}
+
+__naked struct arena_and_scalar global_ret_arena_and_scalar(void)
+{
+ asm volatile (
+ "r0 = 0;"
+ "r2 = 0;"
+ "exit;"
+ );
+}
+
+SEC("tc")
+__load_if_JITed()
+__success __retval(0)
+__naked int aggregate_ret_global_arena_and_scalar(void)
+{
+ asm volatile (
+ "call %[global_ret_arena_and_scalar];"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(global_ret_arena_and_scalar)
+ : __clobber_all);
+}
+
+__naked struct arena_array global_ret_arena_array(void)
+{
+ asm volatile (
+ "r0 = 0;"
+ "r2 = 0;"
+ "exit;"
+ );
+}
+
+SEC("tc")
+__load_if_JITed()
+__success __retval(0)
+__naked int aggregate_ret_global_arena_array(void)
+{
+ asm volatile (
+ "call %[global_ret_arena_array];"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(global_ret_arena_array)
+ : __clobber_all);
+}
+
+__naked struct arena_single global_ret_arena_single(void)
+{
+ asm volatile (
+ "r0 = 0;"
+ "exit;"
+ );
+}
+
+SEC("tc")
+__success __retval(0)
+__naked int aggregate_ret_global_arena_single(void)
+{
+ asm volatile (
+ "call %[global_ret_arena_single];"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(global_ret_arena_single)
+ : __clobber_all);
+}
+
+#endif
+
char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_arena.c b/tools/testing/selftests/bpf/progs/verifier_arena.c
index 815f342eb4b0..d37424d1161a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_arena.c
+++ b/tools/testing/selftests/bpf/progs/verifier_arena.c
@@ -734,4 +734,41 @@ int check_arena_arg_ret(void *ctx)
return 0;
}
+#if defined(__clang_major__) && __clang_major__ >= 23
+
+struct arena_page_pair {
+ u32 __arena *first;
+ u32 __arena *second;
+};
+
+__weak struct arena_page_pair split_arena_page(u32 __arena *page)
+{
+ struct arena_page_pair pair;
+
+ pair.first = page;
+ pair.second = page + 1;
+
+ return pair;
+}
+
+SEC("syscall")
+__load_if_JITed()
+__success __retval(0)
+int check_arena_struct_ret(void *ctx)
+{
+ u32 __arena *page = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
+ struct arena_page_pair pair;
+
+ if (!page)
+ return 1;
+
+ pair = split_arena_page(page);
+ if (!pair.first || !pair.second)
+ return 2;
+
+ return 0;
+}
+
+#endif
+
char _license[] SEC("license") = "GPL";
--
2.53.0-Meta
next prev parent reply other threads:[~2026-08-25 20:55 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 20:54 [PATCH bpf-next v2 00/10] bpf: Allow arena pointers in by-value returns Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 01/10] bpf: Record each half of a paired return value in verifier diagnostics Yonghong Song
2026-08-25 21:59 ` bot+bpf-ci
2026-08-26 17:08 ` Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 02/10] bpf: Drop the recursion depth argument of btf_type_is_scalar_struct() Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 03/10] bpf: Add btf_type_is_arena_ptr() Yonghong Song
2026-08-25 21:59 ` bot+bpf-ci
2026-08-26 17:28 ` Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 04/10] bpf: Let the by-value struct walk take the kinds of member it accepts Yonghong Song
2026-08-25 21:59 ` bot+bpf-ci
2026-08-26 17:39 ` Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 05/10] bpf: Report which member makes a kfunc return type unsupported Yonghong Song
2026-08-25 21:59 ` bot+bpf-ci
2026-08-26 17:59 ` Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 06/10] bpf: Allow a global function to return arena pointers by value Yonghong Song
2026-08-25 21:12 ` sashiko-bot
2026-08-26 18:40 ` Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 07/10] bpf: Allow arena pointers in a by-value kfunc return Yonghong Song
2026-08-25 22:13 ` bot+bpf-ci
2026-08-26 18:57 ` Yonghong Song
2026-08-25 20:54 ` [PATCH bpf-next v2 08/10] selftests/bpf: Check the member named for an unsupported kfunc return type Yonghong Song
2026-08-25 20:54 ` Yonghong Song [this message]
2026-08-25 21:59 ` [PATCH bpf-next v2 09/10] selftests/bpf: Test global functions returning arena pointers by value bot+bpf-ci
2026-08-27 3:46 ` Yonghong Song
2026-08-25 20:55 ` [PATCH bpf-next v2 10/10] selftests/bpf: Test kfuncs " Yonghong Song
2026-08-25 21:59 ` bot+bpf-ci
2026-08-27 3:58 ` Yonghong Song
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=20260825205458.1325916-1-yonghong.song@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
/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