From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Chen Pei" <cp0613@linux.alibaba.com>, <daniel@iogearbox.net>,
<andrii@kernel.org>, <memxor@gmail.com>, <bjorn@kernel.org>,
<puranjay@kernel.org>
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>,
<pulehui@huawei.com>, <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 v2 bpf-next 3/3] selftests/bpf: Add a runtime test for private stack and stack arguments
Date: Thu, 05 Nov 2026 16:37:02 +0000 [thread overview]
Message-ID: <DMNFA3D0M816.2K02S8LB47QM4@gmail.com> (raw)
In-Reply-To: <20261104100411.997-4-cp0613@linux.alibaba.com>
On Wed, Nov 04, 2026 at 02:04 AM Chen Pei <cp0613@linux.alibaba.com> wrote:
> .../selftests/bpf/private_stack_runtime.h | 12 ++
> .../bpf/prog_tests/private_stack_runtime.c | 84 +++++++++++
> .../bpf/progs/private_stack_runtime.c | 140 ++++++++++++++++++
> 3 files changed, 236 insertions(+)
bpf ci is right in the other email.
pw-bot: cr
Also, the test runs on riscv64 only. BPF CI runs arm64 and not riscv64.
arm64 has the same combination and no test for it.
The run time part has nothing specific to riscv64.
The __jited patterns pin the frame sizes that clang picks for C code.
zero_stack doesn't use the private stack.
It's the only reason for serial_.
Two asm progs in verifier_stack_arg.c are enough.
BPF_PROG_TEST_RUN runs a raw_tp prog. No need to attach it.
The test runs on x86-64, arm64 and riscv64.
On x86-64 both frames stay on the kernel stack.
Like (not even compile tested):
diff --git a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
index abf319c..9423048 100644
--- a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
+++ b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
@@ -667,6 +667,53 @@ __naked void stack_arg_precision_fallback(void)
);
}
+/* Writes both ends of its frame, then reads args 9, 10 and the frame of the caller. */
+__naked __noinline __used
+static 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;"
+ );
+}
+
+/*
+ * 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.
+ */
+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
SEC("socket")
prev parent reply other threads:[~2026-11-05 16:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 10:04 [PATCH v2 bpf-next 0/3] riscv: bpf: Add BPF private stack support Chen Pei
2026-11-04 10:04 ` [PATCH v2 bpf-next 1/3] " Chen Pei
2026-11-05 13:30 ` Pu Lehui
2026-11-04 10:04 ` [PATCH v2 bpf-next 2/3] selftests/bpf: Enable private stack tests for riscv64 Chen Pei
2026-11-04 10:04 ` [PATCH v2 bpf-next 3/3] selftests/bpf: Add a runtime test for private stack and stack arguments Chen Pei
2026-11-04 10:43 ` bot+bpf-ci
2026-11-05 16:37 ` Alexei Starovoitov [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=DMNFA3D0M816.2K02S8LB47QM4@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--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=pulehui@huawei.com \
--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®