From: sashiko-bot@kernel.org
To: "Zhanpeng Zhang" <zhangzhanpeng.jasper@bytedance.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v14 09/10] selftests/riscv: add SSE test module
Date: Wed, 02 Dec 2026 07:26:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-245063@kernel.org> (raw)
In-Reply-To: <20261202070003.42491-21-zhangzhanpeng.jasper@bytedance.com>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [Medium] selftests/riscv: sse module Makefile defaults KDIR to host
/lib/modules
- [Medium] selftests/riscv: sse: deadlock between migrate_disable() and
cpus_read_lock()
- [Medium] selftests/riscv: sse: fast test ignores errors and races on
1-jiffy timeout
- [Medium] selftests/riscv: sse: unlogged errors in
sse_test_wait_not_running_on_cpu()
- [Medium] selftests/riscv: sse: stress test treats -EEXIST as failure
instead of skip
- [Low] selftests/riscv: sse: swapped log args in sse_test_handler() and
dead field
- [Low] selftests/riscv: sse: deprecated system_wq and pinned module on
cleanup
- [Low] selftests/riscv: sse: stale pointers left in priority_test_arg
on teardown
- [Low] selftests/riscv: run_sse_test.sh added with non-executable mode
0644
--
commit d18167796bde0fdeb57c3e749d237794731e6df4
Author: Clément Léger <cleger@rivosinc.com>
selftests/riscv: add SSE test module
This commit adds a RISC-V SSE kselftest kernel module and runner script
that exercise fast event injection, priority ordering, and stress modes.
> diff --git a/tools/testing/selftests/riscv/sse/module/Makefile b/tools/testing/selftests/riscv/sse/module/Makefile
> new file mode 100644
> index 0000000000000..eac4b1c6228bb
> --- /dev/null
> +++ b/tools/testing/selftests/riscv/sse/module/Makefile
> @@ -0,0 +1,22 @@
> +ifneq ($(CONFIG_RISCV_SBI_SSE),)
> +obj-m += riscv_sse_test.o
> +endif
> +
> +ifndef KERNELRELEASE
> +
> +TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
> +KDIR ?= /lib/modules/$(shell uname -r)/build
> +
> +# Ensure that KDIR exists, otherwise skip the compilation
> +modules:
> +ifneq ("$(wildcard $(KDIR))", "")
> + $(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
> +endif
[Severity: Medium]
Does defaulting KDIR to /lib/modules/$(shell uname -r)/build break
cross-compilation and out-of-tree (O=) builds?
When cross-building RISC-V selftests with ARCH=riscv on a non-RISC-V host
that has /lib/modules/$(uname -r)/build installed, Kbuild runs against the
host kernel build tree with ARCH=riscv and fails. On an out-of-tree O=
build, tools/testing/selftests/Makefile exports O=$(abs_objtree) in
MAKEFLAGS while -C enters /lib/modules/$(uname -r)/build, so the top-level
Makefile finds CURDIR != $(objtree), clears output, and tries to write
artifacts into /lib/modules/$(uname -r)/build instead of $(TESTMODS_DIR).
In container or CI builds without /lib/modules/$(uname -r)/build, the
module build is silently skipped instead of using the kernel tree under
test.
Other kselftest modules such as tools/testing/selftests/mm/page_frag/Makefile
use:
KDIR ?= $(if $(O),$(O),$(realpath ../../../../..))
> diff --git a/tools/testing/selftests/riscv/sse/module/riscv_sse_test.c b/tools/testing/selftests/riscv/sse/module/riscv_sse_test.c
> new file mode 100644
> index 0000000000000..cc5c2e46f2fdb
> --- /dev/null
> +++ b/tools/testing/selftests/riscv/sse/module/riscv_sse_test.c
[ ... ]
> +static void sse_test_queue_cleanup(struct sse_event *event)
> +{
> + int i, free_slot = -1;
> +
> + mutex_lock(&sse_test_cleanup_lock);
> + for (i = 0; i < ARRAY_SIZE(sse_test_cleanup_events); i++) {
> + if (sse_test_cleanup_events[i] == event)
> + goto out_schedule;
> + if (!sse_test_cleanup_events[i] && free_slot < 0)
> + free_slot = i;
> + }
> +
> + if (WARN_ON_ONCE(free_slot < 0))
> + goto out_unlock;
> +
> + sse_test_cleanup_events[free_slot] = event;
> +
> +out_schedule:
> + mod_delayed_work(system_wq, &sse_test_cleanup_work,
> + msecs_to_jiffies(100));
> +out_unlock:
> + mutex_unlock(&sse_test_cleanup_lock);
> +}
[Severity: Low]
Does queuing sse_test_cleanup_work on system_wq trigger the
__WQ_DEPRECATED warning in __queue_work() (and likewise in
sse_test_cleanup_workfn())? system_percpu_wq or system_dfl_wq should be
used instead.
Also, when sse_test_queue_cleanup() is invoked during sse_test_init(),
THIS_MODULE remains pinned by __module_get(THIS_MODULE) for at least
100 ms after init returns 0, causing the immediate rmmod in
run_sse_test.sh to fail before it parses the run log.
[ ... ]
> +static int sse_test_wait_not_running_on_cpu(u32 evt, unsigned int cpu)
> +{
> + struct sse_test_wait_status wait = { .evt = evt };
> + unsigned long timeout;
> + int ret = 0;
> +
> + if (sse_event_is_global(evt))
> + return sse_test_wait_not_running(evt);
> +
> + wait.attr_buf = kmalloc_obj(*wait.attr_buf, GFP_KERNEL);
> + if (!wait.attr_buf)
> + return -ENOMEM;
> +
> + timeout = jiffies + HZ;
> + do {
> + ret = smp_call_function_single(cpu, sse_test_read_status_local,
> + &wait, true);
> + if (ret || wait.ret) {
> + ret = ret ?: wait.ret;
> + break;
> + }
> + if (wait.status != SBI_SSE_STATE_RUNNING)
> + break;
> + usleep_range(100, 200);
> + } while (time_before(jiffies, timeout));
> +
> + if (!ret && wait.status == SBI_SSE_STATE_RUNNING) {
> + sse_err("Timed out waiting for event %x on CPU %u\n", evt, cpu);
> + ret = -ETIMEDOUT;
> + }
> +
> + kfree(wait.attr_buf);
> +
> + return ret;
> +}
[Severity: Medium]
Can non-timeout failures in sse_test_wait_not_running_on_cpu() go
unreported during the fast injection test?
Unlike sse_test_wait_not_running(), this function only logs sse_err() on
-ETIMEDOUT. If kmalloc_obj(), smp_call_function_single(), or
sse_event_attr_read() fails when called from sse_run_fast_test_cpu(),
sse_run_fast_test() returns without emitting a FAILED: line to dmesg, so
run_sse_test.sh can report a false pass.
[ ... ]
> +static int sse_test_handler(u32 evt, void *arg, struct pt_regs *regs)
> +{
> + int ret = 0;
> + struct fast_test_arg *targ = arg;
> + u32 test_evt;
> + int cpu;
> +
> + atomic_inc(&sse_test_handler_count);
> +
> + /* Pairs with the argument publication in sse_run_fast_test_cpu(). */
> + if (!smp_load_acquire(&targ->args_ready)) {
> + sse_err("Received SSE event %x before its test arguments were published\n",
> + evt);
> + ret = -EINVAL;
> + goto complete;
> + }
> +
> + test_evt = READ_ONCE(targ->evt);
> + cpu = READ_ONCE(targ->cpu);
> +
> + if (evt != test_evt) {
> + sse_err("Received SSE event id %x instead of %x\n", test_evt, evt);
> + ret = -EINVAL;
> + }
[Severity: Low]
Are test_evt and evt swapped in this sse_err() format string? evt is the
received event ID and test_evt is the expected ID.
> +
> + if (!sse_event_is_global(evt) && cpu != smp_processor_id()) {
> + sse_err("Received SSE event %d on CPU %d instead of %d\n", evt, smp_processor_id(),
> + cpu);
> + ret = -EINVAL;
> + }
> +
> +complete:
> + WRITE_ONCE(targ->args_ready, false);
> + /* Publish handler-side checks before waking the waiting CPU. */
> + smp_store_release(&targ->completion, true);
> +
> + return ret;
> +}
> +
> +static int sse_run_fast_test_cpu(struct fast_test_arg *test_arg,
> + struct sse_event *event, u32 evt, int cpu)
> +{
> + unsigned long timeout;
> + int ret;
> +
> + WRITE_ONCE(test_arg->completion, false);
> + WRITE_ONCE(test_arg->args_ready, false);
> + WRITE_ONCE(test_arg->evt, evt);
> + WRITE_ONCE(test_arg->cpu, cpu);
> + /* Publish all arguments before firmware can inject on another hart. */
> + smp_store_release(&test_arg->args_ready, true);
> +
> + ret = sse_test_inject_event(event, evt, cpu);
> + if (ret) {
> + sse_err("event %s injection failed, err %d\n",
> + sse_evt_name(evt), ret);
> + return ret;
> + }
> +
> + timeout = jiffies + HZ / 100;
> + /* We can not use <linux/completion.h> since they are not NMI safe */
> + /* Pairs with the handler's completion publication. */
> + while (!smp_load_acquire(&test_arg->completion) &&
> + time_before(jiffies, timeout))
> + cpu_relax();
> + /* Acquire the handler's checks even if the loop observed a timeout. */
> + if (!smp_load_acquire(&test_arg->completion)) {
> + sse_err("Failed to wait for event %s completion on CPU %d\n",
> + sse_evt_name(evt), cpu);
> + return -ETIMEDOUT;
> + }
> +
> + return sse_test_wait_not_running_on_cpu(evt, cpu);
> +}
> +
> +static void sse_run_fast_test(struct fast_test_arg *test_arg,
> + struct sse_event *event, u32 evt)
> +{
> + int cpu;
> +
> + if (sse_event_is_global(evt)) {
> + /* Keep the selected target online through injection and completion. */
> + cpu_hotplug_disable();
> + for_each_online_cpu(cpu) {
> + if (sse_run_fast_test_cpu(test_arg, event, evt, cpu))
> + break;
> + }
> + cpu_hotplug_enable();
> + return;
> + }
> +
> + guard(cpus_read_lock)();
> + for_each_online_cpu(cpu) {
> + if (sse_run_fast_test_cpu(test_arg, event, evt, cpu))
> + return;
> + }
> +}
> +
> +static void sse_test_injection_fast(void)
> +{
[ ... ]
> + for (j = 0; j < RUN_LOOP_COUNT; j++)
> + sse_run_fast_test(&fast_test_arg, event, evt);
> + pr_info("Finished testing event %s\n", sse_evt_name(evt));
[Severity: Medium]
Can a timeout or error in sse_run_fast_test_cpu() race with an in-flight
handler across the remaining RUN_LOOP_COUNT iterations?
In sse_run_fast_test_cpu(), jiffies + HZ / 100 is only 1 jiffy when
CONFIG_HZ_100=y, which can expire on the next timer tick in near-zero
elapsed time, and the timeout return path skips
sse_test_wait_not_running_on_cpu(). Because sse_run_fast_test() returns
void and drops the error, sse_test_injection_fast() continues all 1,000
iterations, immediately overwriting the shared static fast_test_arg while
the delayed SSE handler on the timed-out CPU may still be executing and
reading or writing fast_test_arg. Repeating a 1-second timeout across
1,000 iterations can also stall module load for up to 1,000 seconds.
[ ... ]
> +struct priority_test_arg {
> + unsigned long evt;
> + struct sse_event *event;
> + bool called;
> + bool enable_attempted;
> + u32 prio;
> + struct priority_test_arg *next_evt_arg;
> + void (*check_func)(struct priority_test_arg *arg);
> +};
[Severity: Low]
This isn't a bug, but check_func in struct priority_test_arg is never
used.
[ ... ]
> +static void sse_test_injection_priority_arg(struct priority_test_arg *args, unsigned int args_size,
> + sse_event_handler_fn handler, const char *test_name)
> +{
> + unsigned int i;
> + unsigned long timeout;
> + int ret;
> + int target_cpu;
> + struct sse_event *event;
> + struct priority_test_arg *arg, *first_arg = NULL, *prev_arg = NULL;
> +
> + pr_info("Starting SSE priority test (%s)\n", test_name);
> + /* Keep the complete priority chain on one CPU. */
> + migrate_disable();
> + target_cpu = smp_processor_id();
> +
> + for (i = 0; i < args_size; i++) {
> + arg = &args[i];
> +
> + if (!sse_test_can_inject_event(arg->evt))
> + continue;
> +
> + WRITE_ONCE(arg->called, false);
> + WRITE_ONCE(arg->next_evt_arg, NULL);
> + WRITE_ONCE(arg->event, NULL);
> + WRITE_ONCE(arg->enable_attempted, false);
> +
> + event = sse_test_event_register(arg->evt, arg->prio, handler,
> + (void *)arg);
[Severity: Medium]
Can calling sse_test_event_register() (and the subsequent SSE APIs) inside
migrate_disable() without first disabling CPU hotplug cause an ABBA
deadlock with CPU hotplug teardown?
CPU0 (target_cpu) CPU1
----------------- ----
migrate_disable()
_cpu_down(target_cpu)
cpus_write_lock()
...
sched_cpu_wait_empty()
balance_hotplug_wait()
/* waits for !rq_has_pinned_tasks(rq) */
sse_test_event_register()
sse_event_register()
mutex_lock(&sse_mutex)
cpus_read_lock()
*** DEADLOCK ***
sse_event_register(), sse_event_set_target_cpu(), sse_event_enable(),
sse_event_disable(), and sse_event_unregister() each acquire sse_mutex and
cpus_read_lock() and release them on return. Because migrate_disable()
pins the task to target_cpu without blocking CPU hotplug, _cpu_down() can
acquire cpus_write_lock() between any two SSE calls, run
sse_cpu_teardown() on target_cpu mid-test, and then block in
balance_hotplug_wait() waiting for the pinned task to call
migrate_enable(), while CPU0 blocks in cpus_read_lock() holding sse_mutex.
Calling cpu_hotplug_disable() before migrate_disable() (and
cpu_hotplug_enable() after migrate_enable()) avoids this lock inversion.
[ ... ]
> +release_events:
> +
> + for (i = 0; i < args_size; i++) {
> + arg = &args[i];
> + event = arg->event;
> + if (!event)
> + continue;
> +
> + ret = sse_test_wait_not_running_on_cpu(arg->evt, target_cpu);
> + if (ret)
> + sse_err("Event %s did not complete, err %d\n",
> + sse_evt_name(arg->evt), ret);
> +
> + if (arg->enable_attempted) {
> + ret = sse_event_disable(event);
> + if (ret) {
> + sse_err("Failed to disable event %s, err %d\n",
> + sse_evt_name(arg->evt), ret);
> + sse_test_queue_cleanup(event);
> + WRITE_ONCE(arg->event, NULL);
> + WRITE_ONCE(arg->enable_attempted, false);
> + continue;
> + }
> + }
> +
> + ret = sse_test_event_unregister(event);
> + if (ret) {
> + sse_err("Failed to unregister event %s, err %d\n",
> + sse_evt_name(arg->evt), ret);
> + continue;
> + }
> +
> + WRITE_ONCE(arg->event, NULL);
> + WRITE_ONCE(arg->enable_attempted, false);
> + }
[Severity: Low]
Does the release_events loop leave stale pointers in priority_test_arg
when disable or unregister fails?
When sse_test_event_unregister() fails, it queues event for deferred
destruction via sse_test_queue_cleanup(), but the error branch executes
continue before clearing arg->event and arg->enable_attempted. In
addition, teardown never clears arg->next_evt_arg, so if an event fails to
disable or unregister while later events in the chain are unregistered, a
late handler invocation on the retained event will still see a non-NULL
targ->next_evt_arg and inject next->evt after that successor has been
unregistered.
[ ... ]
> +static int sse_stress_test_layer(int layer)
> +{
> + struct sse_event *event;
> + int inject_count, handler_count;
> + int ret, target_cpu, unregister_ret;
> +
> + if (layer < 0 || layer >= ARRAY_SIZE(stress_handlers))
> + return -EINVAL;
> +
> + pr_info("Starting SSE stress layer %d (%s)\n",
> + layer, stress_layer_names[layer]);
> +
> + memset(&stress_ctx, 0, sizeof(stress_ctx));
> + stress_ctx.evt_id = SBI_SSE_EVENT_LOCAL_SOFTWARE_INJECTED;
> + stress_ctx.layer = layer;
> + WRITE_ONCE(stress_ctx.running, true);
> + atomic_set(&stress_ctx.inject_count, 0);
> + atomic_set(&stress_ctx.handler_count, 0);
> + atomic_set(&stress_ctx.handler_errors, 0);
> + init_waitqueue_head(&stress_ctx.wait_q);
> +
> + event = sse_test_event_register(stress_ctx.evt_id, 0,
> + stress_handlers[layer], &stress_ctx);
> + if (IS_ERR(event)) {
> + sse_err("Failed to register stress event, err %ld\n",
> + PTR_ERR(event));
> + return PTR_ERR(event);
> + }
[Severity: Medium]
Should sse_stress_test_layer() skip rather than fail when
sse_test_event_register() returns -EEXIST?
Unlike sse_test_injection_fast() and sse_test_injection_priority_arg(),
which skip events that are already registered (-EEXIST),
sse_stress_test_layer() and sse_stress_test_all_layers() log FAILED: via
sse_err() on -EEXIST. Because run_sse_test.sh checks for FAILED: before
SKIP:, stress=1 or stress=2 exits with failure (1) instead of SKIP (4)
when SBI_SSE_EVENT_LOCAL_SOFTWARE_INJECTED is already registered by
another user.
> diff --git a/tools/testing/selftests/riscv/sse/run_sse_test.sh b/tools/testing/selftests/riscv/sse/run_sse_test.sh
> new file mode 100644
> index 0000000000000..e70a2fd14b05e
> --- /dev/null
> +++ b/tools/testing/selftests/riscv/sse/run_sse_test.sh
> @@ -0,0 +1,59 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
[Severity: Low]
Should run_sse_test.sh be committed with mode 100755 instead of 100644?
Because run_sse_test.sh is listed in TEST_PROGS without executable
permissions, direct invocation (such as ./run_sse_test.sh stress=1) fails
with permission denied, and tools/testing/selftests/kselftest/runner.sh
emits "Warning: file run_sse_test.sh is not executable" and takes a
fallback path that omits $kselftest_cmd_args.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202070003.42491-12-zhangzhanpeng.jasper@bytedance.com?part=9
next prev parent reply other threads:[~2026-12-02 7:26 UTC|newest]
Thread overview: 17+ 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 ` [PATCH v14 01/10] riscv: add SBI SSE extension definitions 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: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:29 ` sashiko-bot
2026-12-02 7:00 ` [PATCH v14 04/10] drivers: firmware: add riscv SSE support 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 ` [PATCH v14 06/10] perf: RISC-V: support callchains with SSE delivery 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:33 ` sashiko-bot
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 ` [PATCH v14 09/10] selftests/riscv: add SSE test module Zhanpeng Zhang
2026-12-02 7:26 ` sashiko-bot [this message]
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:24 ` sashiko-bot
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-245063@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox