From: sashiko-bot@kernel.org
To: "Zhanpeng Zhang" <zhangzhanpeng.jasper@bytedance.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v14 10/10] selftests/riscv: add perf user-stack SSE copy regression test
Date: Wed, 02 Dec 2026 07:24:36 +0000 [thread overview]
Message-ID: <sashiko-outbox-245061@kernel.org> (raw)
In-Reply-To: <20261202070003.42491-22-zhangzhanpeng.jasper@bytedance.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] selftests/riscv: perf_event_open() EINVAL fails instead of
skipping
- [Medium] selftests/riscv: test_ustack_records_wellformed() accepts
0-byte copy
- [Medium] selftests/riscv: burn_stack() overflows default musl pthread
stack
- [Low] selftests/riscv: false skip on setup failure in
test_sse_stress_no_crash()
- [Low] selftests/riscv: unused stress_thread fields and missing
.gitignore entry
--
commit 13ea3ed7f68e83a790b8d54de61c754fa456ab46
Author: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>
selftests/riscv: add perf user-stack SSE copy regression test
This commit adds a kselftest under tools/testing/selftests/riscv/sse/ to
exercise PERF_SAMPLE_STACK_USER guard-page truncation and multi-CPU sampling
stress when PMU overflow interrupts are delivered via RISC-V SBI SSE.
> diff --git a/tools/testing/selftests/riscv/sse/Makefile b/tools/testing/selftests/riscv/sse/Makefile
> index 7e2677fdce09a..646b418de9ffb 100644
> --- a/tools/testing/selftests/riscv/sse/Makefile
> +++ b/tools/testing/selftests/riscv/sse/Makefile
> @@ -1,5 +1,10 @@
> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests
> +LDLIBS += -lpthread
> +
> TEST_GEN_MODS_DIR := module
>
> +TEST_GEN_PROGS := sse_perf_ustack
[Severity: Low]
This isn't a bug, but sse_perf_ustack should also be listed in
tools/testing/selftests/riscv/sse/.gitignore like the other RISC-V selftest
subdirectories do for TEST_GEN_PROGS binaries.
> diff --git a/tools/testing/selftests/riscv/sse/sse_perf_ustack.c b/tools/testing/selftests/riscv/sse/sse_perf_ustack.c
> new file mode 100644
> index 0000000000000..9535b6d7ba4c1
> --- /dev/null
> +++ b/tools/testing/selftests/riscv/sse/sse_perf_ustack.c
> @@ -0,0 +1,564 @@
[ ... ]
> +#define STRESS_SECONDS 5
> +#define RECURSE_DEPTH 512
> +#define TRUNCATION_RUN_MS 250
[ ... ]
> +static noinline unsigned long burn_stack(int depth, unsigned long *sink)
> +{
> + unsigned long frame[32];
> + unsigned int i;
> +
> + for (i = 0; i < ARRAY_SIZE(frame); i++)
> + frame[i] = (unsigned long)depth * i + *sink;
> +
> + if (depth > 0)
> + frame[depth & 31] += burn_stack(depth - 1, sink);
> +
> + for (i = 0; i < ARRAY_SIZE(frame); i++)
> + *sink += frame[i];
> +
> + keep_alive(frame);
> + return *sink;
> +}
[Severity: Medium]
Can burn_stack() overflow the worker thread stack on musl libc?
With RECURSE_DEPTH set to 512, 513 active frames of unsigned long frame[32]
plus saved registers consume roughly 148 KiB on 64-bit RISC-V.
test_sse_stress_no_crash() creates worker threads with default pthread
attributes without calling pthread_attr_setstacksize(), which exceeds musl's
128 KiB default thread stack and crashes the test with SIGSEGV.
> +static struct perf_event_attr sampling_attr(unsigned long freq)
> +{
> + struct perf_event_attr attr = {
> + .type = PERF_TYPE_HARDWARE,
> + .size = sizeof(attr),
> + .config = PERF_COUNT_HW_INSTRUCTIONS,
> + .sample_type = PERF_SAMPLE_STACK_USER,
> + .sample_stack_user = STACK_DUMP_SIZE,
> + .freq = 1,
> + .sample_freq = freq,
> + .disabled = 1,
> + .exclude_kernel = 1,
> + .exclude_hv = 1,
> + };
> +
> + return attr;
> +}
> +
> +static bool open_skip_reason(int err, const char **why)
> +{
> + switch (err) {
> + case EACCES:
> + case EPERM:
> + *why = "insufficient privilege for PMU sampling (perf_event_paranoid)";
> + return true;
> + case ENOENT:
> + case ENODEV:
> + case EOPNOTSUPP:
> + *why = "hardware PMU sampling event not available";
> + return true;
> + default:
> + return false;
> + }
> +}
[Severity: Medium]
Does perf_event_open() fail with EINVAL rather than skipping when PMU
overflow interrupts and mode filtering are both unsupported?
On RISC-V platforms without SSE or Sscofpmf overflow support, riscv_pmu_sbi
and riscv_pmu_legacy set both PERF_PMU_CAP_NO_INTERRUPT and
PERF_PMU_CAP_NO_EXCLUDE without registering a riscv-pmu interrupt in
/proc/interrupts. Because sampling_attr() sets exclude_kernel and exclude_hv,
perf_try_init_event() rejects the event with -EINVAL before perf_event_open()
reaches the PERF_PMU_CAP_NO_INTERRUPT check that returns -EOPNOTSUPP, causing
test_ustack_records_wellformed() to report FAIL instead of SKIP.
[ ... ]
> +static int truncation_child(void *arg)
> +{
> + int ready_fd = (intptr_t)arg;
> + char ready = 1;
> +
> + if (write(ready_fd, &ready, sizeof(ready)) != 1)
> + return 1;
> +
> + for (;;)
> + __asm__ __volatile__("" : : : "memory");
> +}
[ ... ]
> + if (dyn_size > dump_size) {
> + ok = false;
> + break;
> + }
> + if (dyn_size < dump_size)
> + truncated++;
> + }
> + }
> + tail += hdr.size;
> + }
> + __atomic_store_n(&meta->data_tail, head, __ATOMIC_RELEASE);
> +
> + if (!ok)
> + ksft_test_result_fail("ustack records: malformed sample record\n");
> + else if (samples == 0)
> + ksft_test_result_skip("ustack records: no samples collected\n");
> + else if (truncated == 0)
> + ksft_test_result_fail("ustack records: no guarded-stack truncation\n");
> + else
> + ksft_test_result_pass("ustack records: %lu samples, %lu truncated\n",
> + samples, truncated);
> + }
[Severity: Medium]
Does test_ustack_records_wellformed() pass even when every sample copies 0
bytes (`dyn_size == 0`)?
clone() starts truncation_child() at stack + page_size right below the
PROT_NONE guard page, and truncation_child() only pushes a small frame of
16 to 48 bytes before spinning. In arch/riscv/lib/uaccess.S, .Lword_copy
issues 8 unrolled REG_L loads (64 bytes on RV64) before storing any bytes or
advancing the destination pointer:
arch/riscv/lib/uaccess.S:fallback_scalar_usercopy_sum_enabled() {
...
.Lword_copy:
/*
* Word copy loop,rolled 8X. Chosen because that gives two 64B cache lines on
* RV64 and one on RV32.
*/
addi a2, a2, -(8*SZREG)
bltu a2, t1, .Lword_copy_tail
1:
fixup REG_L t0, (0*SZREG)(a1), 10f
fixup REG_L t2, (1*SZREG)(a1), 10f
fixup REG_L t3, (2*SZREG)(a1), 10f
fixup REG_L t4, (3*SZREG)(a1), 10f
fixup REG_L a3, (4*SZREG)(a1), 10f
fixup REG_L a4, (5*SZREG)(a1), 10f
fixup REG_L a5, (6*SZREG)(a1), 10f
fixup REG_L a6, (7*SZREG)(a1), 10f
REG_S t0, (0*SZREG)(a0)
...
}
Because sp is within 64 bytes of the guard page, the first burst always
faults before advancing a0, recording `dyn_size == 0`, which `dyn_size <
dump_size` counts as a valid partial truncation. Allocating a live stack
buffer larger than 64 bytes in truncation_child() and requiring `0 < dyn_size
&& dyn_size < dump_size` would verify that a partial stack copy actually
occurred.
[ ... ]
> +struct stress_thread {
> + pthread_t tid;
> + int cpu;
> + int *stop;
> + int fd;
> + void *rb;
> + size_t rb_bytes;
> +};
[Severity: Low]
This isn't a bug, but struct stress_thread::cpu and struct
stress_thread::rb_bytes are written in test_sse_stress_no_crash() and never
read.
[ ... ]
> + if (started == 0) {
> + free(threads);
> + if (why)
> + ksft_test_result_skip("sse stress: %s\n", why);
> + else
> + ksft_test_result_skip("sse stress: could not start any sampler\n");
> + return;
> + }
[Severity: Low]
Should the `!why` branch report a failure or error instead of
ksft_test_result_skip()?
`why` is only set when perf_event_open() fails due to a missing PMU or
privilege prerequisite in open_skip_reason(). If `started == 0` with `why ==
NULL`, every sampler failed in an unexpected perf_event_open(), mmap(), or
pthread setup call, so skipping lets the test exit with KSFT_PASS and masks
the setup failure.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202070003.42491-12-zhangzhanpeng.jasper@bytedance.com?part=10
prev parent reply other threads:[~2026-12-02 7:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 7:00 [PATCH v14 00/10] riscv: add SBI Supervisor Software Events support Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 01/10] riscv: add SBI SSE extension definitions Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 02/10] riscv: add support for SBI Supervisor Software Events extension Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:21 ` sashiko-bot
2026-12-02 7:00 ` [PATCH v14 03/10] riscv: sse: mask events during shutdown and kexec Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 04/10] drivers: firmware: add riscv SSE support Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:25 ` sashiko-bot
2026-12-02 7:00 ` [PATCH v14 05/10] riscv: mm: avoid enabling interrupts for nofault page faults Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 06/10] perf: RISC-V: support callchains with SSE delivery Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 07/10] perf: RISC-V: add support for SSE event Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 08/10] MAINTAINERS: add RISC-V SSE maintainers and file coverage Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 09/10] selftests/riscv: add SSE test module Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:00 ` [PATCH v14 10/10] selftests/riscv: add perf user-stack SSE copy regression test Zhanpeng Zhang
2026-12-02 7:00 ` Zhanpeng Zhang
2026-12-02 7:24 ` sashiko-bot [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=sashiko-outbox-245061@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhangzhanpeng.jasper@bytedance.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.