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=1796196369; b=ZS40ag2EPmscD8UOlk7Kv85rcfTwJkx9ohP26HdfRngznzwollmF3hhAcewC3ZRIuryT N8JiCrQ0RaBcuPm3U0x1yUlXlUIlfRRs4tdJ3UfrlQj0WAJmDBMz2GJSyHQWH9s46y8aD 6CeQbXpCenndl4JMofJ2WcjZR9v6UZDyZp4RK7ZUXfGO/4ecOe6utNwfcZsrgm3UCrgA/ spYyG/rylqHud8jmIMtSg7v+vko9wln70cQvpWIcf+HM/BndRidvnNaZWcEapq0pdCKK7 g1Ser6zug0GgfRiNKND6L05fNDOkrymRNJ0RftHDo68bx6COgm/FFVGibMmtn7CQxcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796196369; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=qjixhEbJsWmpkNPApbFHSeZdtJlwbgk/q7UGZDsI0U4=; b=sXyiNM5e2iEyEwTgX6OfBIfjJR1YZELO29ZfkvhCsx5LiYkAH/HTLX/KgNZOOPLUyUqG kyn35/iCkidMxhiTevK5pep0kpW05jBTRLlK5ucxcPX0qzAwdS3qO8z5nDuOhzPnlYWbA ef7flf37PFd/+PH1BmokkLNnyKnTgfd8aWuee96F20gNm5ZpPOa0F0ewJOJEh7KT5JXJ6 s+xHGssKOeH8w9oeFVC6dKlxUw9WoWdU9EP8V+icmMJ2uOB8DRJ95HOhldODuu786CQh8 xQyNEE6CUQusCaSnWb6+y+R2Z0rdzK42bJZmVzTa0FPJ0CKGSjomhhYJ6PF0JpgkOow== 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=T5izjZEp; 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 B0903606A31A for ; Wed, 2 Dec 2026 07:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T5izjZEp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 236C01F000C1; Wed, 2 Dec 2026 07:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796196369; bh=qjixhEbJsWmpkNPApbFHSeZdtJlwbgk/q7UGZDsI0U4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=T5izjZEpLH+QPPILxQvrkLWiCBNO/4S8ru88gKbWi9+ARE46bwfQnmk+fLWSHYjLc SqWWqyqvSHWOD1fdvdLfYMbCgTV86U6LgvXSlA0Eigy00jcS7NM0ztBwfOKhkXtvQL jd1iOUQRVecRZ2k7OXtccs/UWo1RKGlmmyzrMoTgh8dRDRrp5A5Geo6FYrGC+Q6/6f dXTKMzCK5UWwa6O0h1zI+x/eGMb6e0c9ixrXPkU31y6s/0EqGCVKF4yMHDHFrf7WWA V/mjk4RNFd3xPvTq6keqj7xoMNL4VQv/89C0Y0PIt2r/y9ZL1R581NPWTPd/zVKRr3 /UHPaJgUpd33A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 09/10] selftests/riscv: add SSE test module Reply-To: sashiko-reviews@lists.linux.dev To: "Zhanpeng Zhang" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261202070003.42491-21-zhangzhanpeng.jasper@bytedance.com> References: <20261202070003.42491-12-zhangzhanpeng.jasper@bytedance.com> <20261202070003.42491-21-zhangzhanpeng.jasper@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 07:26:08 +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 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=C3=A9ment L=C3=A9ger 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/te= sting/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 +=3D riscv_sse_test.o > +endif > + > +ifndef KERNELRELEASE > + > +TESTMODS_DIR :=3D $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)= )))) > +KDIR ?=3D /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=3D$(TESTMODS_DIR) > +endif [Severity: Medium] Does defaulting KDIR to /lib/modules/$(shell uname -r)/build break cross-compilation and out-of-tree (O=3D) builds? When cross-building RISC-V selftests with ARCH=3Driscv on a non-RISC-V host that has /lib/modules/$(uname -r)/build installed, Kbuild runs against the host kernel build tree with ARCH=3Driscv and fails. On an out-of-tree O=3D build, tools/testing/selftests/Makefile exports O=3D$(abs_objtree) in MAKEFLAGS while -C enters /lib/modules/$(uname -r)/build, so the top-level Makefile finds CURDIR !=3D $(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/Makefi= le use: KDIR ?=3D $(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 =3D -1; > + > + mutex_lock(&sse_test_cleanup_lock); > + for (i =3D 0; i < ARRAY_SIZE(sse_test_cleanup_events); i++) { > + if (sse_test_cleanup_events[i] =3D=3D event) > + goto out_schedule; > + if (!sse_test_cleanup_events[i] && free_slot < 0) > + free_slot =3D i; > + } > + > + if (WARN_ON_ONCE(free_slot < 0)) > + goto out_unlock; > + > + sse_test_cleanup_events[free_slot] =3D 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 =3D { .evt =3D evt }; > + unsigned long timeout; > + int ret =3D 0; > + > + if (sse_event_is_global(evt)) > + return sse_test_wait_not_running(evt); > + > + wait.attr_buf =3D kmalloc_obj(*wait.attr_buf, GFP_KERNEL); > + if (!wait.attr_buf) > + return -ENOMEM; > + > + timeout =3D jiffies + HZ; > + do { > + ret =3D smp_call_function_single(cpu, sse_test_read_status_local, > + &wait, true); > + if (ret || wait.ret) { > + ret =3D ret ?: wait.ret; > + break; > + } > + if (wait.status !=3D SBI_SSE_STATE_RUNNING) > + break; > + usleep_range(100, 200); > + } while (time_before(jiffies, timeout)); > + > + if (!ret && wait.status =3D=3D SBI_SSE_STATE_RUNNING) { > + sse_err("Timed out waiting for event %x on CPU %u\n", evt, cpu); > + ret =3D -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 =3D 0; > + struct fast_test_arg *targ =3D 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 publishe= d\n", > + evt); > + ret =3D -EINVAL; > + goto complete; > + } > + > + test_evt =3D READ_ONCE(targ->evt); > + cpu =3D READ_ONCE(targ->cpu); > + > + if (evt !=3D test_evt) { > + sse_err("Received SSE event id %x instead of %x\n", test_evt, evt); > + ret =3D -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 !=3D smp_processor_id()) { > + sse_err("Received SSE event %d on CPU %d instead of %d\n", evt, smp_pr= ocessor_id(), > + cpu); > + ret =3D -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 =3D 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 =3D jiffies + HZ / 100; > + /* We can not use 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 =3D 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=3Dy, 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 *ar= gs, 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 =3D NULL, *prev_arg =3D NULL; > + > + pr_info("Starting SSE priority test (%s)\n", test_name); > + /* Keep the complete priority chain on one CPU. */ > + migrate_disable(); > + target_cpu =3D smp_processor_id(); > + > + for (i =3D 0; i < args_size; i++) { > + arg =3D &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 =3D 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(r= q) */ 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 =3D 0; i < args_size; i++) { > + arg =3D &args[i]; > + event =3D arg->event; > + if (!event) > + continue; > + > + ret =3D 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 =3D 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 =3D 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 >=3D 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 =3D SBI_SSE_EVENT_LOCAL_SOFTWARE_INJECTED; > + stress_ctx.layer =3D 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 =3D 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=3D1 or stress=3D2 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/te= sting/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=3D1) 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202070003.4249= 1-12-zhangzhanpeng.jasper@bytedance.com?part=3D9