From: Yonghong Song <yonghong.song@linux.dev>
To: Eduard Zingerman <eddyz87@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com
Subject: Re: [PATCH bpf-next 10/12] selftests/bpf: Add inline-asm and subprog tests for R0:R2 returns
Date: Thu, 9 Jul 2026 22:35:53 -0700 [thread overview]
Message-ID: <9ea6b6be-b368-4631-84e2-509c445df0cf@linux.dev> (raw)
In-Reply-To: <6e8a7e39e2823970e7045585e6eed37bae3acf89.camel@gmail.com>
On 7/9/26 6:38 PM, Eduard Zingerman wrote:
> On Wed, 2026-07-08 at 13:10 -0700, Yonghong Song wrote:
>> Add inline-asm and subprogram tests for more coverage, including
>> BPF-to-BPF cases, kfunc cases, backtracking and liveness. Both positive
>> and negative tests are added.
>>
>> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
>> ---
> [...]
>
>> @@ -93,4 +97,25 @@ void test_aggregate_ret(void)
>> run_prog(skel_union_c->progs.aggregate_ret_union_c_test, true);
>>
>> aggregate_ret_union_c__destroy(skel_union_c);
>> +
>> + skel_run = aggregate_ret_run__open_and_load();
>> + if (!ASSERT_OK_PTR(skel_run, "skel_run_open_load"))
>> + return;
>> +
>> + /* Inline-asm variant: compiler-version independent, always runs. */
>> + if (test__start_subtest("asm"))
>> + run_prog(skel_run->progs.aggregate_ret_asm_test, false);
>> +
>> + /* Struct-by-value kfunc returns, also compiler-version independent. */
>> + if (test__start_subtest("struct"))
>> + run_prog(skel_run->progs.aggregate_ret_struct_test, false);
>> +
>> + /* Union-by-value kfunc return, compiler-version independent. */
>> + if (test__start_subtest("union"))
>> + run_prog(skel_run->progs.aggregate_ret_union_test, false);
>> +
>> + aggregate_ret_run__destroy(skel_run);
>> +
>> + RUN_TESTS(aggregate_ret_func);
>> + RUN_TESTS(aggregate_ret_kfunc);
> This can be folded into tools/testing/selftests/bpf/prog_tests/verifier.c.
>
>> }
>> diff --git a/tools/testing/selftests/bpf/progs/aggregate_ret_func.c b/tools/testing/selftests/bpf/progs/aggregate_ret_func.c
>> new file mode 100644
>> index 000000000000..31e176103374
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/aggregate_ret_func.c
>> @@ -0,0 +1,361 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
>> +#include <linux/bpf.h>
>> +#include <bpf/bpf_helpers.h>
>> +#include "bpf_misc.h"
>> +
>> +typedef unsigned __int128 u128;
>> +
>> +__naked u128 global_agg_good(void)
>> +{
>> + asm volatile (
>> + "r0 = 0x1234;" /* low 64 bits */
>> + "r2 = 0x5678;" /* high 64 bits */
>> + "exit;"
>> + );
>> +}
>> +
>> +__naked u128 global_agg_bad(void)
>> +{
>> + asm volatile (
>> + "r0 = 0;"
>> + "exit;"
>> + );
>> +}
> C version of tests from a previous patch already checks global vs.
> local functions. I suggest dropping that version from C tests and keep
> in assembly only to reduce the duplication.
>
> [...]
>
>> +SEC("tc")
>> +__success __retval(0)
>> +int aggregate_ret_global_union(void *ctx)
>> +{
>> + __u64 lo, hi;
>> +
>> + asm volatile (
>> + "call %[global_ret_union];"
>> + "%[lo] = r0;"
>> + "%[hi] = r2;"
>> + : [lo]"=r"(lo), [hi]"=r"(hi)
>> + : __imm(global_ret_union)
>> + : "r0", "r1", "r2", "r3", "r4", "r5");
>> + if (lo != 0x1234)
>> + return 1;
>> + if (hi != 0x5678)
>> + return 2;
>> + return 0;
>> +}
> And here I'd only keep the C version.
>
>> +__naked struct with_ptr global_ret_struct_ptr(void)
>> +{
>> + asm volatile (
>> + "r0 = 0;"
>> + "r2 = 0;"
>> + "exit;"
>> + );
>> +}
> [...]
>
>> +static __naked u128 agg_callee(void)
>> +{
>> + asm volatile (
>> + "r0 = 1;"
>> + "r2 = 2;"
>> + "exit;"
>> + );
>> +}
>> +
>> +SEC("tc")
>> +__log_level(2)
>> +__msg("Live regs before insn:")
>> +__msg("0: .12345.... (85) call pc+2")
>> +__msg("1: ..2....... (bf) r0 = r2")
>> +__msg("2: 0......... (95) exit")
>> +__msg("3: .......... (b7) r0 = 1")
>> +__msg("4: 0......... (b7) r2 = 2")
>> +__msg("5: 0.2....... (95) exit")
>> +__naked int aggregate_ret_live(void)
>> +{
>> + asm volatile (
>> + "call %[agg_callee];"
>> + "r0 = r2;"
>> + "exit;"
>> + :
>> + : [agg_callee]"i"(agg_callee)
>> + : __clobber_all);
>> +}
> Nit: usually we add such tests to compute_live_registers.c.
I can move the test to compute_live_registers.c.
>
> [...]
>
>> diff --git a/tools/testing/selftests/bpf/progs/aggregate_ret_run.c b/tools/testing/selftests/bpf/progs/aggregate_ret_run.c
> I think the test cases in this file are by a large degree redundant.
> A single test case calling a kfunc returning a small struct and
> checking returned values would suffice.
Ack. I tried to test for both C and asm test cases. They are indeed some duplicates.
I will try to remove the redundant ones in next revision.
>
> [...]
next prev parent reply other threads:[~2026-07-10 5:35 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 20:09 [PATCH bpf-next 00/12] bpf: Support 16-byte return values in the R0:R2 register pair Yonghong Song
2026-07-08 20:09 ` [PATCH bpf-next 01/12] bpf: Factor check_global_ret_scalar_reg() out of the global return check Yonghong Song
2026-07-08 20:09 ` [PATCH bpf-next 02/12] bpf: Add verifier support for 16-byte returns in R0:R2 Yonghong Song
2026-07-08 21:17 ` bot+bpf-ci
2026-07-09 16:40 ` Yonghong Song
2026-07-09 22:21 ` Eduard Zingerman
2026-07-10 4:57 ` Yonghong Song
2026-07-08 20:09 ` [PATCH bpf-next 03/12] bpf: Wire up JIT support for 16-byte kfunc returns Yonghong Song
2026-07-10 0:06 ` Eduard Zingerman
2026-07-08 20:10 ` [PATCH bpf-next 04/12] bpf: Track R2 of register-pair returns in precision backtracking Yonghong Song
2026-07-08 21:10 ` bot+bpf-ci
2026-07-09 16:41 ` Yonghong Song
2026-07-10 0:31 ` Eduard Zingerman
2026-07-08 20:10 ` [PATCH bpf-next 05/12] bpf: Account R2 of register-pair returns in live register analysis Yonghong Song
2026-07-08 21:10 ` bot+bpf-ci
2026-07-09 21:07 ` Eduard Zingerman
2026-07-10 5:06 ` Yonghong Song
2026-07-08 20:10 ` [PATCH bpf-next 06/12] bpf: Force JIT for programs using the R0:R2 register pair Yonghong Song
2026-07-08 21:10 ` bot+bpf-ci
2026-07-09 3:15 ` Leon Hwang
2026-07-09 16:44 ` Yonghong Song
2026-07-09 20:30 ` Eduard Zingerman
2026-07-10 5:07 ` Yonghong Song
2026-07-09 22:27 ` Eduard Zingerman
2026-07-10 5:09 ` Yonghong Song
2026-07-08 20:10 ` [PATCH bpf-next 07/12] bpf: Reject >8 byte return values on return-reading trampoline paths Yonghong Song
2026-07-09 3:16 ` Leon Hwang
2026-07-09 16:52 ` Yonghong Song
2026-07-10 2:01 ` Leon Hwang
2026-07-09 23:08 ` Eduard Zingerman
2026-07-10 2:02 ` Leon Hwang
2026-07-10 5:27 ` Yonghong Song
2026-07-10 5:12 ` Yonghong Song
2026-07-08 20:10 ` [PATCH bpf-next 08/12] bpf: Enable 16-byte aggregate return types Yonghong Song
2026-07-08 20:28 ` sashiko-bot
2026-07-09 19:40 ` Yonghong Song
2026-07-10 0:45 ` Eduard Zingerman
2026-07-10 5:29 ` Yonghong Song
2026-07-08 20:10 ` [PATCH bpf-next 09/12] selftests/bpf: Add C tests for 16-byte returns in R0:R2 Yonghong Song
2026-07-08 20:24 ` sashiko-bot
2026-07-09 19:51 ` Yonghong Song
2026-07-08 21:10 ` bot+bpf-ci
2026-07-09 19:54 ` Yonghong Song
2026-07-10 1:19 ` Eduard Zingerman
2026-07-10 5:32 ` Yonghong Song
2026-07-08 20:10 ` [PATCH bpf-next 10/12] selftests/bpf: Add inline-asm and subprog tests for R0:R2 returns Yonghong Song
2026-07-08 20:28 ` sashiko-bot
2026-07-09 19:57 ` Yonghong Song
2026-07-10 1:38 ` Eduard Zingerman
2026-07-10 5:35 ` Yonghong Song [this message]
2026-07-08 20:10 ` [PATCH bpf-next 11/12] selftests/bpf: Cover tracing on >8 and <=16 byte return targets Yonghong Song
2026-07-08 20:10 ` [PATCH bpf-next 12/12] Documentation/bpf: Document 16-byte kfunc return values in R0:R2 Yonghong Song
2026-07-10 0:56 ` [PATCH bpf-next 00/12] bpf: Support 16-byte return values in the R0:R2 register pair Eduard Zingerman
2026-07-10 6:00 ` Yonghong Song
2026-07-10 6:13 ` Eduard Zingerman
2026-07-10 15:18 ` 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=9ea6b6be-b368-4631-84e2-509c445df0cf@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 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.