From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796196278; b=0ikwOKeB8UtgYjJjEz6LbzoqDu2DAOLmA5kXzgYinIbk210dpghAUIG2avhSfPK7HKdO ASZ0r0TxtMydXS7iJ5HTZ73NlvmNtJxvgY6Aa5Vza0+tlw/Y7xDV96cQh/OZxyQRvndTZ /u6S3m31PBxLnWs8Gq/us1/Vwv/HCRjh6NBsvGVNYCXltl+hcVuaAbT9rD8DKjTTxfo70 v5BbNezvR3b5vyNKHoZvO2MQWScPxynIAI4KuM36Q7PuhQzCcHx9OrAHopxmxwxWbhssK yrqvzHpG+dwxZUdQi6x7/j+aZrqIEa40zfUj5WgR3njB/Uy/g5FoInOvHUiZCGrnfkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796196278; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ztNIcwxUshHVDC/FWaEyL0v1h8jDcjPneXSFs7kT+0U=; b=46/JWXTsTReYz/O8xj9w0pyxfTK8Ef4ZWvHEOlnAzhHpQ8+s6ycEEfP+KV61IWDCl8OT LcGoOSJbrtRaB9Akze6hY3q9+Ez/c+nv3K0Oeq2IXV72AjvAWlwEzhiHc255E85eEBQUW FlDM+oC6WiL/JzHyHihY7e3pNqbhtKpbpWG9kRLT1pEhxLFuEJ6CRa7Bn0+EfPlQmrhZZ 5KKO9uZNmBJZvzrA9sWLhXW/gxUa+MRK2ki/RJGYqOt7IfZnN4KETriIxgo4JJq7U4Tf1 DC81BaeWSowZSbUS14pBgzCNdeIoUasKwjfLj2Y+bt1V9/0QEWeakpl+019jhoBmTpA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LG8M3OoP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA642606A31A for ; Wed, 2 Dec 2026 07:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LG8M3OoP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 106931F0089C; Wed, 2 Dec 2026 07:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796196277; bh=ztNIcwxUshHVDC/FWaEyL0v1h8jDcjPneXSFs7kT+0U=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=LG8M3OoPhp+dKS591Ow0i01Rark+iLG4vxKFYgG/w2pC1FgvAwR04aOUhi4vIenC3 nqSbRN7s5x3uq3OszC9EchzeLOE5SvF1OvcgMOzrWVPUPH2fZhp2BMk4/jyJ/9Xfgz lSbnpSsq4pngOO6GObnlhsDI0iyfwjSSHEPc5idGJkMNfX2E6HA9jWPTlPZLNPsMP9 QEga83+GQjOKhn+LbFjKPgc5YGYsvOBzEpj7qoFbio1F10D9uYS274NIBbwlET937I gp6q3u5EF9MrgBZzMW10nO2q4PXhI24o5biBZEAlPa+YmYHCmBuBi90EmB+ZAZjvhe XG4MJj556Y9aA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 10/10] selftests/riscv: add perf user-stack SSE copy regression test Reply-To: sashiko-reviews@lists.linux.dev To: "Zhanpeng Zhang" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261202070003.42491-22-zhangzhanpeng.jasper@bytedance.com> References: <20261202070003.42491-12-zhangzhanpeng.jasper@bytedance.com> <20261202070003.42491-22-zhangzhanpeng.jasper@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 07:24:36 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/s= elftests/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 +=3D -I$(top_srcdir)/tools/testing/selftests > +LDLIBS +=3D -lpthread > + > TEST_GEN_MODS_DIR :=3D module > =20 > +TEST_GEN_PROGS :=3D 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 =3D 0; i < ARRAY_SIZE(frame); i++) > + frame[i] =3D (unsigned long)depth * i + *sink; > + > + if (depth > 0) > + frame[depth & 31] +=3D burn_stack(depth - 1, sink); > + > + for (i =3D 0; i < ARRAY_SIZE(frame); i++) > + *sink +=3D 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 =3D { > + .type =3D PERF_TYPE_HARDWARE, > + .size =3D sizeof(attr), > + .config =3D PERF_COUNT_HW_INSTRUCTIONS, > + .sample_type =3D PERF_SAMPLE_STACK_USER, > + .sample_stack_user =3D STACK_DUMP_SIZE, > + .freq =3D 1, > + .sample_freq =3D freq, > + .disabled =3D 1, > + .exclude_kernel =3D 1, > + .exclude_hv =3D 1, > + }; > + > + return attr; > +} > + > +static bool open_skip_reason(int err, const char **why) > +{ > + switch (err) { > + case EACCES: > + case EPERM: > + *why =3D "insufficient privilege for PMU sampling (perf_event_paranoid= )"; > + return true; > + case ENOENT: > + case ENODEV: > + case EOPNOTSUPP: > + *why =3D "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_h= v, perf_try_init_event() rejects the event with -EINVAL before perf_event_open= () reaches the PERF_PMU_CAP_NO_INTERRUPT check that returns -EOPNOTSUPP, causi= ng test_ustack_records_wellformed() to report FAIL instead of SKIP. [ ... ] > +static int truncation_child(void *arg) > +{ > + int ready_fd =3D (intptr_t)arg; > + char ready =3D 1; > + > + if (write(ready_fd, &ready, sizeof(ready)) !=3D 1) > + return 1; > + > + for (;;) > + __asm__ __volatile__("" : : : "memory"); > +} [ ... ] > + if (dyn_size > dump_size) { > + ok =3D false; > + break; > + } > + if (dyn_size < dump_size) > + truncated++; > + } > + } > + tail +=3D 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 =3D=3D 0) > + ksft_test_result_skip("ustack records: no samples collected\n"); > + else if (truncated =3D=3D 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 =3D=3D 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 cach= e 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 =3D=3D 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_si= ze && 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 =3D=3D 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 =3D=3D 0` with `w= hy =3D=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202070003.4249= 1-12-zhangzhanpeng.jasper@bytedance.com?part=3D10