From: Pu Lehui <pulehui@huawei.com>
To: "Feng Jiang" <jiangfeng@kylinos.cn>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Luke Nelson" <luke.r.nels@gmail.com>,
"Xi Wang" <xi.wang@gmail.com>, "Björn Töpel" <bjorn@kernel.org>,
"Puranjay Mohan" <puranjay@kernel.org>,
"Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Shuah Khan" <shuah@kernel.org>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>
Cc: <bpf@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf-next v4 2/3] selftests/bpf: test timed may_goto preserves R0-R5
Date: Wed, 22 Jul 2026 19:10:10 +0800 [thread overview]
Message-ID: <2cd8255d-2b0a-45d8-bbc2-ac19e196c41a@huawei.com> (raw)
In-Reply-To: <20260722-riscv-bpf-timed-may-goto-v4-2-e117e6337bc7@kylinos.cn>
On 2026/7/22 12:21, Feng Jiang wrote:
> Add a test that checks R0-R5 are preserved across
> arch_bpf_timed_may_goto() calls.
>
> Use bpf_get_prandom_u32() to avoid the verifier removing the checks
> via DCE.
>
> Suggested-by: Björn Töpel <bjorn@kernel.org>
> Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn>
> ---
> .../selftests/bpf/progs/verifier_may_goto_1.c | 57 ++++++++++++++++++++++
> 1 file changed, 57 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
> index 4bdf4256a41e..98d59108d097 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
> @@ -106,4 +106,61 @@ __naked void may_goto_batch_2(void)
> : __clobber_all);
> }
>
> +/*
> + * Use bpf_get_prandom_u32() to prevent DCE from removing the checks.
> + * retval: 0=all ok, 1-6=R0-R5 clobbered.
> + */
> +SEC("raw_tp")
> +__description("timed may_goto preserves R0-R5")
> +__arch_x86_64
> +__arch_arm64
> +__arch_riscv64
> +__success
> +__retval(0)
__arch_s390x is also supported timed_may_goto
> +__naked void timed_may_goto_preserves_regs(void)
> +{
> + asm volatile (
> + "call %[bpf_get_prandom_u32];"
> + "r6 = r0;"
> + "r0 = 0x1111;"
> + "r0 += r6;"
> + "r1 = 0x2222;"
> + "r1 += r6;"
> + "r2 = 0x3333;"
> + "r2 += r6;"
> + "r3 = 0x4444;"
> + "r3 += r6;"
> + "r4 = 0x5555;"
> + "r4 += r6;"
> + "r5 = 0x6666;"
> + "r5 += r6;"
> + ".8byte %[may_goto];"
> + ".8byte %[loop];"
> + "r0 -= r6;"
> + "r1 -= r6;"
> + "r2 -= r6;"
> + "r3 -= r6;"
> + "r4 -= r6;"
> + "r5 -= r6;"
> + "if r0 != 0x1111 goto 1f;"
> + "if r1 != 0x2222 goto 2f;"
> + "if r2 != 0x3333 goto 3f;"
> + "if r3 != 0x4444 goto 4f;"
> + "if r4 != 0x5555 goto 5f;"
> + "if r5 != 0x6666 goto 6f;"
> + "r0 = 0;"
> + "exit;"
> + "1: r0 = 1; exit;"
> + "2: r0 = 2; exit;"
> + "3: r0 = 3; exit;"
> + "4: r0 = 4; exit;"
> + "5: r0 = 5; exit;"
> + "6: r0 = 6; exit;"
> + :
> + : __imm(bpf_get_prandom_u32),
> + __imm_insn(may_goto, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, 1, 0)),
> + __imm_insn(loop, BPF_RAW_INSN(BPF_JMP | BPF_JA, 0, 0, -2, 0))
> + : __clobber_all);
> +}
> +
> char _license[] SEC("license") = "GPL";
>
not work, pls take a look
root@(none):/mnt/bpf# ./test_progs -v -a verifier_may_goto_1
bpf_testmod.ko is already unloaded.
Loading bpf_testmod.ko...
[ 26.123549] bpf_testmod: loading out-of-tree module taints kernel.
[ 26.127885] bpf_testmod: module verification failed: signature and/or
required key missing - tainting kernel
Successfully loaded bpf_testmod.ko.
tester_init:PASS:tester_log_buf 0 nsec
process_subtest:PASS:obj_open_mem 0 nsec
process_subtest:PASS:specs_alloc 0 nsec
run_subtest:PASS:obj_open_mem 0 nsec
run_subtest:PASS:unexpected_load_failure 0 nsec
VERIFIER LOG:
=============
processed 43 insns (limit 1000000) max_states_per_insn 0 total_states 4
peak_states 5 mark_read 0
=============
do_prog_test_run:FAIL:1114 FAIL: Unexpected bpf_prog_test_run error: 22
(Invalid argument) #660/1 verifier_may_goto_1/timed may_goto preserves
R0-R5:FAIL
#660 verifier_may_goto_1:FAIL
Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
Successfully unloaded bpf_testmod.ko.
next prev parent reply other threads:[~2026-07-22 11:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 4:21 [PATCH bpf-next v4 0/3] bpf, riscv: add timed may_goto support Feng Jiang
2026-07-22 4:21 ` [PATCH bpf-next v4 1/3] bpf, riscv: add support for timed may_goto Feng Jiang
2026-07-22 10:18 ` Pu Lehui
2026-07-23 1:59 ` Feng Jiang
2026-07-22 4:21 ` [PATCH bpf-next v4 2/3] selftests/bpf: test timed may_goto preserves R0-R5 Feng Jiang
2026-07-22 11:10 ` Pu Lehui [this message]
2026-07-23 2:36 ` Feng Jiang
2026-07-22 4:21 ` [PATCH bpf-next v4 3/3] selftests/bpf: enable timed may_goto tests for riscv64 Feng Jiang
2026-07-22 10:45 ` Pu Lehui
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=2cd8255d-2b0a-45d8-bbc2-ac19e196c41a@huawei.com \
--to=pulehui@huawei.com \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jiangfeng@kylinos.cn \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=luke.r.nels@gmail.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=puranjay@kernel.org \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=xi.wang@gmail.com \
--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
all inboxes | Powered by JetHome®