Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhanpeng Zhang" <zhangzhanpeng.jasper@bytedance.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v13 03/11] riscv: sse: mask events during shutdown and kexec
Date: Thu, 19 Nov 2026 12:38:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-223101@kernel.org> (raw)
In-Reply-To: <20261119120824.13969-16-zhangzhanpeng.jasper@bytedance.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] riscv: sse: unreachable !CONFIG_SMP panic_smp_self_stop() in
  reset.c
- [Medium] riscv: sse: unmasked SSE on other harts and preemptible
  machine_restart()
--

commit 39abe8f5f293bf4034ca8ab03a15f0ede47b20ab
Author: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>

riscv: sse: mask events during shutdown and kexec

This commit masks SBI Supervisor Software Events (SSE) on the local hart
during panic, CPU stop, restart, poweroff, and crash shutdown paths, and
rejects normal kexec from a crash kernel when firmware supports SSE.

Link: https://lore.kernel.org/r/as7-3PbWDxygadnJ@hu-himchau-blr.qualcomm.com/

> diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
> index 14eb08a6db855..fdab37e7ae52d 100644
> --- a/arch/riscv/kernel/reset.c
> +++ b/arch/riscv/kernel/reset.c
> @@ -6,6 +6,20 @@
>  #include <linux/efi.h>
>  #include <linux/reboot.h>
>  #include <linux/pm.h>
> +#include <linux/smp.h>
> +
> +#include <asm/sse.h>
> +
> +#ifndef CONFIG_SMP
> +void __noreturn panic_smp_self_stop(void)
> +{
> +	riscv_sse_mask_current_hart();
> +	local_irq_disable();
> +
> +	for (;;)
> +		cpu_relax();
> +}
> +#endif

[Severity: Medium]
Is this !CONFIG_SMP definition of panic_smp_self_stop() reachable, and does
a uniprocessor panic ever mask SSE on the panicking hart?

All callers of panic_smp_self_stop() in kernel/panic.c are gated by
panic_try_force_cpu() or panic_on_other_cpu().  When !CONFIG_SMP,
panic_try_force_cpu() is a stub returning false, and raw_smp_processor_id()
is always 0 while panic_cpu can only be PANIC_CPU_INVALID or 0, so
panic_on_other_cpu() is also always false.

Meanwhile, the panicking CPU calls panic_other_cpus_shutdown() ->
smp_send_stop() / crash_smp_send_stop(), both of which compile to the empty
smp_send_stop() stub in include/linux/smp.h when !CONFIG_SMP, leaving SSE
unmasked during vpanic().

>  static void __noreturn default_power_off(void)
>  {
> @@ -18,6 +32,8 @@ EXPORT_SYMBOL(pm_power_off);
>  
>  void machine_restart(char *cmd)
>  {
> +	riscv_sse_mask_current_hart();
> +
>  	/*
>  	 * UpdateCapsule() depends on the system being reset via ResetSystem().
>  	 */
> @@ -30,12 +46,14 @@ void machine_restart(char *cmd)
>  
>  void machine_halt(void)
>  {
> +	riscv_sse_mask_current_hart();
>  	do_kernel_power_off();
>  	default_power_off();
>  }
>  
>  void machine_power_off(void)
>  {
> +	riscv_sse_mask_current_hart();
>  	do_kernel_power_off();
>  	default_power_off();
>  }

[Severity: Medium]
Can secondary harts—or the calling task itself after migration—still receive
SSE events during machine_restart(), machine_halt(), and
machine_power_off()?

Unlike arm64, these functions do not call local_irq_disable() or
smp_send_stop().  On paths that bypass reboot_notifier_list and
migrate_to_reboot_cpu(), such as emergency_restart() ->
machine_emergency_restart() -> machine_restart(), secondary harts never
receive IPI_CPU_STOP and stay online with SSE unmasked.  Because preemption
is not disabled before riscv_sse_mask_current_hart(), a preemptible
emergency_restart() caller (for example from a workqueue) can also migrate
to another unmasked hart after masking the previous one.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119120824.13969-13-zhangzhanpeng.jasper@bytedance.com?part=3

  reply	other threads:[~2026-11-19 12:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:08 [PATCH v13 00/11] riscv: add SBI Supervisor Software Events support Zhanpeng Zhang
2026-11-19 12:08 ` [PATCH v13 01/11] riscv: add SBI SSE extension definitions Zhanpeng Zhang
2026-11-19 12:14   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 02/11] riscv: add support for SBI Supervisor Software Events extension Zhanpeng Zhang
2026-11-19 12:36   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 03/11] riscv: sse: mask events during shutdown and kexec Zhanpeng Zhang
2026-11-19 12:38   ` sashiko-bot [this message]
2026-11-19 12:08 ` [PATCH v13 04/11] drivers: firmware: add riscv SSE support Zhanpeng Zhang
2026-11-19 12:38   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 05/11] riscv: mm: avoid enabling interrupts for nofault page faults Zhanpeng Zhang
2026-11-19 12:27   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 06/11] riscv: enable NMI-safe lockdep irqflags tracking Zhanpeng Zhang
2026-11-19 12:21   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 07/11] perf: RISC-V: support callchains with SSE delivery Zhanpeng Zhang
2026-11-19 12:45   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 08/11] perf: RISC-V: add support for SSE event Zhanpeng Zhang
2026-11-19 12:34   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 09/11] MAINTAINERS: add RISC-V SSE maintainers and file coverage Zhanpeng Zhang
2026-11-19 12:08 ` [PATCH v13 10/11] selftests/riscv: add SSE test module Zhanpeng Zhang
2026-11-19 12:37   ` sashiko-bot
2026-11-19 12:08 ` [PATCH v13 11/11] selftests/riscv: add perf user-stack SSE copy regression test Zhanpeng Zhang
2026-11-19 12:34   ` 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-223101@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