Re: [PATCH v12 03/11] riscv: sse: mask events during shutdown and kexec
From: Zhanpeng Zhang
Date: Thu Oct 29 2026 - 08:01:44 EST
Hi Himanshu,
On 10/29/26 7:49 PM, Himanshu Chauhan wrote:
> On Thu, Oct 29, 2026 at 03:48:45PM +0800, 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@xxxxxxxxxxxxxxxxxxxxxxxxxxx/
>> Reviewed-by: Himanshu Chauhan <himanshu.chauhan@xxxxxxxxxxxxxxxx>
>> Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@xxxxxxxxxxxxx>
>> ---
>> 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 738df176ff6..24e7affae70 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;
>
> I think I had pointed this out in v10 also. This rejects a normal kexec from any kdump kernel whenever firmware merely advertises SSE, regardless of CONFIG_RISCV_SBI_SSE or whether anything is registered. Can you check if its breaking kexec() with SSE just being advertised?
>
> Regards
> Himanshu
Thanks for following up. Yes, the current check rejects that case based
on firmware advertising SSE alone. I noted this restriction in the
commit message, but it still needs to be narrowed.
With the merge window closing, I kept that change out of v12 and will
address it in a separate follow-up patch like we discussed.
Thanks,
Zhanpeng