From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
yonghong.song@linux.dev, leon.hwang@linux.dev,
kernel-patches-bot@fb.com
Subject: [PATCH bpf-next 2/2] selftests/bpf: Add test to access union argument in tracing program
Date: Fri, 5 Sep 2025 21:32:26 +0800 [thread overview]
Message-ID: <20250905133226.84675-3-leon.hwang@linux.dev> (raw)
In-Reply-To: <20250905133226.84675-1-leon.hwang@linux.dev>
Adding verifier test for accessing union argument in tracing programs.
The test program loads 1st argument of bpf_fentry_test11 function
which is union and checks that verifier allows that.
cd tools/testing/selftests/bpf
./test_progs -t verifier_btf_ctx
501/7 verifier_btf_ctx_access/btf_ctx_access union arg accept:OK
501 verifier_btf_ctx_access:OK
Summary: 1/7 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
net/bpf/test_run.c | 14 +++++++++++++-
.../selftests/bpf/progs/verifier_btf_ctx_access.c | 12 ++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 4a862d6053861..c65d468fd6012 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -574,6 +574,16 @@ noinline int bpf_fentry_test10(const void *a)
return (long)a;
}
+typedef union {
+ void *arg0;
+ int *arg1;
+} union_test_t;
+
+noinline int bpf_fentry_test11(union_test_t t)
+{
+ return (int)(long)t.arg0;
+}
+
noinline void bpf_fentry_test_sinfo(struct skb_shared_info *sinfo)
{
}
@@ -688,6 +698,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
struct bpf_fentry_test_t arg = {};
u16 side_effect = 0, ret = 0;
int b = 2, err = -EFAULT;
+ union_test_t utt = {};
u32 retval = 0;
if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size)
@@ -705,7 +716,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
bpf_fentry_test8(&arg) != 0 ||
bpf_fentry_test9(&retval) != 0 ||
- bpf_fentry_test10((void *)0) != 0)
+ bpf_fentry_test10((void *)0) != 0 ||
+ bpf_fentry_test11(utt) != 0)
goto out;
break;
case BPF_MODIFY_RETURN:
diff --git a/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c b/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c
index 03942cec07e56..ff379836b5f00 100644
--- a/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c
+++ b/tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c
@@ -77,4 +77,16 @@ __naked void ctx_access_const_void_pointer_accept(void)
" ::: __clobber_all);
}
+SEC("fentry/bpf_fentry_test11")
+__description("btf_ctx_access union arg accept")
+__success __retval(0)
+__naked void ctx_access_union_arg_accept(void)
+{
+ asm volatile (" \
+ r2 = *(u64 *)(r1 + 0); /* load 1st argument value (union) */\
+ r0 = 0; \
+ exit; \
+" ::: __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";
--
2.50.1
prev parent reply other threads:[~2025-09-05 13:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 13:32 [PATCH bpf-next 0/2] bpf: Support fentry/fexit for functions with union args Leon Hwang
2025-09-05 13:32 ` [PATCH bpf-next 1/2] " Leon Hwang
2025-09-10 0:54 ` Alexei Starovoitov
2025-09-12 2:52 ` Leon Hwang
2025-09-05 13:32 ` Leon Hwang [this message]
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=20250905133226.84675-3-leon.hwang@linux.dev \
--to=leon.hwang@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-patches-bot@fb.com \
--cc=martin.lau@linux.dev \
--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 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.