From: Clement Leger <clement.leger@linux.dev>
To: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>,
pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
alex@ghiti.fr, himanshu.chauhan@oss.qualcomm.com,
conor@kernel.org, anup.patel@oss.qualcomm.com
Cc: cuiyunhui@bytedance.com, atish.patra@linux.dev,
peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
james.clark@linaro.org, will@kernel.org, tglx@kernel.org,
corbet@lwn.net, rdunlap@infradead.org, shuah@kernel.org,
yuanzhu@bytedance.com, yang.susheng@zte.com.cn,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v13 03/11] riscv: sse: mask events during shutdown and kexec
Date: Thu, 19 Nov 2026 14:44:18 +0100 [thread overview]
Message-ID: <0305b6b3-8292-4a4d-a473-dc26a39beca1@linux.dev> (raw)
In-Reply-To: <20261119120824.13969-16-zhangzhanpeng.jasper@bytedance.com>
On 11/19/26 13:08, Zhanpeng Zhang wrote:
> SSE delivery is independent of normal S-mode interrupts. Firmware may also
> retain an event registration until Linux explicitly unregisters it. A hart
> must therefore stop accepting SSE events before Linux stops servicing the
> registered handler.
>
> Mask SSE on the local hart before panic stop, CPU stop, restart, poweroff,
> and crash shutdown paths. This prevents firmware from entering Linux-owned
> handler state after the corresponding CPU or kernel context is no longer
> valid.
>
> A crash kernel cannot identify or take ownership of registrations
> inherited from the crashed kernel. Reject a later normal kexec while such
> SSE state may still exist, rather than transferring unknown firmware state
> to another kernel.
>
> The restriction is deliberately based on firmware SSE availability, not
> CONFIG_RISCV_SBI_SSE or registrations made by the crash kernel. Disabling
> SSE in the crash kernel does not establish that registrations left by the
> crashed kernel are absent. Consequently, normal kexec from a crash kernel
> is also rejected when firmware advertises SSE but no registrations were
> actually left behind. This conservative restriction remains until a safe
> way to establish or clear inherited firmware state is available.
>
> Link: https://lore.kernel.org/r/as7-3PbWDxygadnJ@hu-himchau-blr.qualcomm.com/
> Reviewed-by: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>
> Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>
> ---
> arch/riscv/kernel/machine_kexec.c | 11 +++++++++++
> arch/riscv/kernel/reset.c | 18 ++++++++++++++++++
> arch/riscv/kernel/smp.c | 17 +++++++++++++++++
> 3 files changed, 46 insertions(+)
>
> diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c
> index 738df176ff6f..24e7affae70b 100644
> --- a/arch/riscv/kernel/machine_kexec.c
> +++ b/arch/riscv/kernel/machine_kexec.c
> @@ -14,10 +14,13 @@
> #include <asm/set_memory.h> /* For set_memory_x() */
> #include <linux/compiler.h> /* For unreachable() */
> #include <linux/cpu.h> /* For cpu_down() */
> +#include <linux/crash_dump.h>
> #include <linux/reboot.h>
> #include <linux/interrupt.h>
> #include <linux/irq.h>
>
> +#include <asm/sse.h>
> +
> /*
> * machine_kexec_prepare - Initialize kexec
> *
> @@ -36,6 +39,13 @@ machine_kexec_prepare(struct kimage *image)
> unsigned int control_code_buffer_sz = 0;
> int i = 0;
>
> + /* A crash kernel cannot tear down registrations inherited from firmware. */
> + if (is_kdump_kernel() && image->type != KEXEC_TYPE_CRASH &&
> + riscv_sse_available()) {
> + pr_err("Normal kexec from a crash kernel is unsupported with SSE\n");
> + return -EOPNOTSUPP;
> + }
> +> /* Find the Flattened Device Tree and save its physical address */
> for (i = 0; i < image->nr_segments; i++) {
> if (image->segment[i].memsz <= sizeof(fdt))
> @@ -127,6 +137,7 @@ void
> machine_crash_shutdown(struct pt_regs *regs)
> {
> local_irq_disable();
> + riscv_sse_mask_current_hart();
>
> /* shutdown non-crashing cpus */
> crash_smp_send_stop();
> diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
> index 14eb08a6db85..fdab37e7ae52 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
>
> 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();
> }
Hi Zhanpeng,
Can you please factor that out in a single function ? both functions are
doing the exact same thing.
Thanks,
Clément
> diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
> index 07027cfeba4b..5b05243e1deb 100644
> --- a/arch/riscv/kernel/smp.c
> +++ b/arch/riscv/kernel/smp.c
> @@ -22,10 +22,13 @@
> #include <linux/irq.h>
> #include <linux/irq_work.h>
> #include <linux/nmi.h>
> +#include <linux/panic.h>
>
> #include <asm/tlbflush.h>
> #include <asm/cacheflush.h>
> #include <asm/cpu_ops.h>
> +#include <asm/sbi.h>
> +#include <asm/sse.h>
>
> static const char * const ipi_names[] = {
> [IPI_RESCHEDULE] = "Rescheduling interrupts",
> @@ -66,8 +69,18 @@ int riscv_hartid_to_cpuid(unsigned long hartid)
> return -ENOENT;
> }
>
> +void __noreturn panic_smp_self_stop(void)
> +{
> + riscv_sse_mask_current_hart();
> + local_irq_disable();
> +
> + for (;;)
> + cpu_relax();
> +}
> +
> static void ipi_stop(void)
> {
> + riscv_sse_mask_current_hart();
> set_cpu_online(smp_processor_id(), false);
> while (1)
> wait_for_interrupt();
> @@ -78,6 +91,7 @@ static atomic_t waiting_for_crash_ipi = ATOMIC_INIT(0);
>
> static inline void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs)
> {
> + riscv_sse_mask_current_hart();
> crash_save_cpu(regs, cpu);
>
> atomic_dec(&waiting_for_crash_ipi);
> @@ -241,6 +255,8 @@ void smp_send_stop(void)
> {
> unsigned long timeout;
>
> + riscv_sse_mask_current_hart();
> +
> if (num_online_cpus() > 1) {
> cpumask_t mask;
>
> @@ -288,6 +304,7 @@ void crash_smp_send_stop(void)
> return;
>
> cpus_stopped = 1;
> + riscv_sse_mask_current_hart();
>
> /*
> * If this cpu is the only one alive at this point in time, online or
WARNING: multiple messages have this Message-ID (diff)
From: Clement Leger <clement.leger@linux.dev>
To: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>,
pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
alex@ghiti.fr, himanshu.chauhan@oss.qualcomm.com,
conor@kernel.org, anup.patel@oss.qualcomm.com
Cc: cuiyunhui@bytedance.com, atish.patra@linux.dev,
peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
james.clark@linaro.org, will@kernel.org, tglx@kernel.org,
corbet@lwn.net, rdunlap@infradead.org, shuah@kernel.org,
yuanzhu@bytedance.com, yang.susheng@zte.com.cn,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v13 03/11] riscv: sse: mask events during shutdown and kexec
Date: Thu, 19 Nov 2026 14:44:18 +0100 [thread overview]
Message-ID: <0305b6b3-8292-4a4d-a473-dc26a39beca1@linux.dev> (raw)
In-Reply-To: <20261119120824.13969-16-zhangzhanpeng.jasper@bytedance.com>
On 11/19/26 13:08, Zhanpeng Zhang wrote:
> SSE delivery is independent of normal S-mode interrupts. Firmware may also
> retain an event registration until Linux explicitly unregisters it. A hart
> must therefore stop accepting SSE events before Linux stops servicing the
> registered handler.
>
> Mask SSE on the local hart before panic stop, CPU stop, restart, poweroff,
> and crash shutdown paths. This prevents firmware from entering Linux-owned
> handler state after the corresponding CPU or kernel context is no longer
> valid.
>
> A crash kernel cannot identify or take ownership of registrations
> inherited from the crashed kernel. Reject a later normal kexec while such
> SSE state may still exist, rather than transferring unknown firmware state
> to another kernel.
>
> The restriction is deliberately based on firmware SSE availability, not
> CONFIG_RISCV_SBI_SSE or registrations made by the crash kernel. Disabling
> SSE in the crash kernel does not establish that registrations left by the
> crashed kernel are absent. Consequently, normal kexec from a crash kernel
> is also rejected when firmware advertises SSE but no registrations were
> actually left behind. This conservative restriction remains until a safe
> way to establish or clear inherited firmware state is available.
>
> Link: https://lore.kernel.org/r/as7-3PbWDxygadnJ@hu-himchau-blr.qualcomm.com/
> Reviewed-by: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>
> Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>
> ---
> arch/riscv/kernel/machine_kexec.c | 11 +++++++++++
> arch/riscv/kernel/reset.c | 18 ++++++++++++++++++
> arch/riscv/kernel/smp.c | 17 +++++++++++++++++
> 3 files changed, 46 insertions(+)
>
> diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c
> index 738df176ff6f..24e7affae70b 100644
> --- a/arch/riscv/kernel/machine_kexec.c
> +++ b/arch/riscv/kernel/machine_kexec.c
> @@ -14,10 +14,13 @@
> #include <asm/set_memory.h> /* For set_memory_x() */
> #include <linux/compiler.h> /* For unreachable() */
> #include <linux/cpu.h> /* For cpu_down() */
> +#include <linux/crash_dump.h>
> #include <linux/reboot.h>
> #include <linux/interrupt.h>
> #include <linux/irq.h>
>
> +#include <asm/sse.h>
> +
> /*
> * machine_kexec_prepare - Initialize kexec
> *
> @@ -36,6 +39,13 @@ machine_kexec_prepare(struct kimage *image)
> unsigned int control_code_buffer_sz = 0;
> int i = 0;
>
> + /* A crash kernel cannot tear down registrations inherited from firmware. */
> + if (is_kdump_kernel() && image->type != KEXEC_TYPE_CRASH &&
> + riscv_sse_available()) {
> + pr_err("Normal kexec from a crash kernel is unsupported with SSE\n");
> + return -EOPNOTSUPP;
> + }
> +> /* Find the Flattened Device Tree and save its physical address */
> for (i = 0; i < image->nr_segments; i++) {
> if (image->segment[i].memsz <= sizeof(fdt))
> @@ -127,6 +137,7 @@ void
> machine_crash_shutdown(struct pt_regs *regs)
> {
> local_irq_disable();
> + riscv_sse_mask_current_hart();
>
> /* shutdown non-crashing cpus */
> crash_smp_send_stop();
> diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
> index 14eb08a6db85..fdab37e7ae52 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
>
> 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();
> }
Hi Zhanpeng,
Can you please factor that out in a single function ? both functions are
doing the exact same thing.
Thanks,
Clément
> diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
> index 07027cfeba4b..5b05243e1deb 100644
> --- a/arch/riscv/kernel/smp.c
> +++ b/arch/riscv/kernel/smp.c
> @@ -22,10 +22,13 @@
> #include <linux/irq.h>
> #include <linux/irq_work.h>
> #include <linux/nmi.h>
> +#include <linux/panic.h>
>
> #include <asm/tlbflush.h>
> #include <asm/cacheflush.h>
> #include <asm/cpu_ops.h>
> +#include <asm/sbi.h>
> +#include <asm/sse.h>
>
> static const char * const ipi_names[] = {
> [IPI_RESCHEDULE] = "Rescheduling interrupts",
> @@ -66,8 +69,18 @@ int riscv_hartid_to_cpuid(unsigned long hartid)
> return -ENOENT;
> }
>
> +void __noreturn panic_smp_self_stop(void)
> +{
> + riscv_sse_mask_current_hart();
> + local_irq_disable();
> +
> + for (;;)
> + cpu_relax();
> +}
> +
> static void ipi_stop(void)
> {
> + riscv_sse_mask_current_hart();
> set_cpu_online(smp_processor_id(), false);
> while (1)
> wait_for_interrupt();
> @@ -78,6 +91,7 @@ static atomic_t waiting_for_crash_ipi = ATOMIC_INIT(0);
>
> static inline void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs)
> {
> + riscv_sse_mask_current_hart();
> crash_save_cpu(regs, cpu);
>
> atomic_dec(&waiting_for_crash_ipi);
> @@ -241,6 +255,8 @@ void smp_send_stop(void)
> {
> unsigned long timeout;
>
> + riscv_sse_mask_current_hart();
> +
> if (num_online_cpus() > 1) {
> cpumask_t mask;
>
> @@ -288,6 +304,7 @@ void crash_smp_send_stop(void)
> return;
>
> cpus_stopped = 1;
> + riscv_sse_mask_current_hart();
>
> /*
> * If this cpu is the only one alive at this point in time, online or
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-11-19 13:44 UTC|newest]
Thread overview: 38+ 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 ` Zhanpeng Zhang
2026-11-19 12:08 ` [PATCH v13 01/11] riscv: add SBI SSE extension definitions Zhanpeng Zhang
2026-11-19 12:08 ` 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:08 ` 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:08 ` Zhanpeng Zhang
2026-11-19 12:38 ` sashiko-bot
2026-11-19 13:44 ` Clement Leger [this message]
2026-11-19 13:44 ` Clement Leger
2026-11-19 12:08 ` [PATCH v13 04/11] drivers: firmware: add riscv SSE support Zhanpeng Zhang
2026-11-19 12:08 ` 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:08 ` 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:08 ` Zhanpeng Zhang
2026-11-19 12:21 ` sashiko-bot
2026-11-19 13:46 ` Clement Leger
2026-11-19 13:46 ` Clement Leger
2026-11-19 12:08 ` [PATCH v13 07/11] perf: RISC-V: support callchains with SSE delivery Zhanpeng Zhang
2026-11-19 12:08 ` 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:08 ` 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 ` Zhanpeng Zhang
2026-11-19 12:08 ` [PATCH v13 10/11] selftests/riscv: add SSE test module Zhanpeng Zhang
2026-11-19 12:08 ` 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:08 ` 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=0305b6b3-8292-4a4d-a473-dc26a39beca1@linux.dev \
--to=clement.leger@linux.dev \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alex@ghiti.fr \
--cc=alexander.shishkin@linux.intel.com \
--cc=anup.patel@oss.qualcomm.com \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=conor@kernel.org \
--cc=corbet@lwn.net \
--cc=cuiyunhui@bytedance.com \
--cc=himanshu.chauhan@oss.qualcomm.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=rdunlap@infradead.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=will@kernel.org \
--cc=yang.susheng@zte.com.cn \
--cc=yuanzhu@bytedance.com \
--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.