mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pu Lehui <pulehui@huawei.com>
To: Chen Pei <cp0613@linux.alibaba.com>, <ast@kernel.org>,
	<daniel@iogearbox.net>, <andrii@kernel.org>, <memxor@gmail.com>,
	<bjorn@kernel.org>, <puranjay@kernel.org>,
	<alexei.starovoitov@gmail.com>
Cc: <eddyz87@gmail.com>, <martin.lau@linux.dev>, <song@kernel.org>,
	<yonghong.song@linux.dev>, <jolsa@kernel.org>,
	<emil@etsalapatis.com>, <ihor.solodrai@linux.dev>,
	<pjw@kernel.org>, <palmer@dabbelt.com>, <aou@eecs.berkeley.edu>,
	<alex@ghiti.fr>, <luke.r.nels@gmail.com>, <xi.wang@gmail.com>,
	<shuah@kernel.org>, <rgbi3307@gmail.com>, <guoren@kernel.org>,
	<bpf@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
	<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 bpf-next 3/3] selftests/bpf: Test a private stack together with stack arguments
Date: Sat, 7 Nov 2026 09:16:08 +0800	[thread overview]
Message-ID: <d0647583-f51c-4a74-b71c-6088abffe502@huawei.com> (raw)
In-Reply-To: <20261106181558.1564-4-cp0613@linux.alibaba.com>



On 2026/11/7 2:15, Chen Pei wrote:
> Add two asm programs to verifier_stack_arg.c, inside the block that is
> already gated on x86, arm64 and riscv64. A raw_tp program with a 64 byte
> frame calls a ten-argument subprog with a 64 byte frame of its own, and
> BPF_PROG_TEST_RUN runs the pair without attaching it. Args 9 and 10 stay
> in the kernel frame and arg 10 points into the caller's frame, so the two
> have to agree on where the outgoing area is. The callee returns what the
> caller stored plus arg 9, so a wrong area shows up as a wrong retval
> rather than as a crash.
> 
> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>
> ---
>   .../selftests/bpf/progs/verifier_stack_arg.c  | 49 +++++++++++++++++++
>   1 file changed, 49 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
> index 146cdf81bbc4..e8108e768b89 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
> @@ -975,6 +975,55 @@ __naked void stack_arg_precision_fallback(void)
>   	);
>   }
>   
> +/* Writes both ends of its frame, then reads args 9, 10 and the frame of the caller. */
> +static __naked __noinline __used
> +long priv_stack_10args(long a, long b, long c, long d, long e, long f, long g, long h,
> +		       long i, long *j)
> +{
> +	asm volatile (
> +		"r1 = 0;"
> +		"*(u64 *)(r10 - 8) = r1;"
> +		"*(u64 *)(r10 - 64) = r1;"
> +		"r0 = *(u64 *)(r11 + 32);"
> +		"r1 = *(u64 *)(r11 + 40);"
> +		"r1 = *(u64 *)(r1 + 0);"
> +		"r0 += r1;"
> +		"exit;"
> +		::: __clobber_all
> +	);
> +}
> +
> +/*
> + * A frame of 64 bytes in a raw_tp prog goes to the private stack.
> + * arm64 and riscv64 pass args 9 and 10 on the kernel stack. On x86-64
> + * both frames stay there as well.
> + */
> +SEC("raw_tp")
> +__description("stack_arg: private stack in the caller and in the callee")
> +__success __retval(890)
> +__naked void stack_arg_priv_stack(void)
> +{
> +	asm volatile (
> +		"r1 = 800;"
> +		"*(u64 *)(r10 - 64) = r1;"
> +		"r1 = r10;"
> +		"r1 += -64;"
> +		"*(u64 *)(r11 - 40) = r1;"
> +		"*(u64 *)(r11 - 32) = 90;"
> +		"*(u64 *)(r11 - 24) = 8;"
> +		"*(u64 *)(r11 - 16) = 7;"
> +		"*(u64 *)(r11 - 8) = 6;"
> +		"r1 = 1;"
> +		"r2 = 2;"
> +		"r3 = 3;"
> +		"r4 = 4;"
> +		"r5 = 5;"
> +		"call priv_stack_10args;"
> +		"exit;"
> +		::: __clobber_all
> +	);
> +}
> +
>   #else
>   
>   /* No BTF tells about this store. The insn is what JIT has to deal with. */


Reviewed-by: Pu Lehui <pulehui@huawei.com>

  reply	other threads:[~2026-11-07  1:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 18:15 [PATCH v3 bpf-next 0/3] riscv: bpf: Add BPF private stack support Chen Pei
2026-11-06 18:15 ` [PATCH v3 bpf-next 1/3] " Chen Pei
2026-11-06 18:15 ` [PATCH v3 bpf-next 2/3] selftests/bpf: Enable private stack tests for riscv64 Chen Pei
2026-11-06 18:15 ` [PATCH v3 bpf-next 3/3] selftests/bpf: Test a private stack together with stack arguments Chen Pei
2026-11-07  1:16   ` Pu Lehui [this message]
2026-11-23  7:46 ` [PATCH v3 bpf-next 0/3] riscv: bpf: Add BPF private stack support Pu Lehui
2026-11-24 20:29   ` Alexei Starovoitov

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=d0647583-f51c-4a74-b71c-6088abffe502@huawei.com \
    --to=pulehui@huawei.com \
    --cc=alex@ghiti.fr \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cp0613@linux.alibaba.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=guoren@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --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=rgbi3307@gmail.com \
    --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®