Re: [PATCH v3] riscv: disable local interrupts and stop other CPUs before reboot/shutdown

From: Troy Mitchell

Date: Sun Jun 07 2026 - 21:22:06 EST


On Wed Apr 29, 2026 at 7:44 PM CST, Troy Mitchell wrote:
> Hi all,
>
> On Mon Mar 30, 2026 at 5:58 PM CST, Troy Mitchell wrote:
>> From: Troy Mitchell <troy.mitchell@xxxxxxxxx>
>>
>> Currently, the RISC-V implementation of machine_restart(), machine_halt(),
>> and machine_power_off() invokes the kernel teardown chains (e.g.,
>> do_kernel_restart()) with local interrupts enabled and other CPUs still
>> running.
>>
>> This implementation fails to provide a deterministic execution environment
>> for registered handlers in the restart or power-off notifier chains. These
>> chains are intended to be executed in a strict atomic and single-threaded
>> context.
>>
>> Specifically, under CONFIG_PREEMPT_RCU, rcu_read_lock() does not increment
>> the preempt_count. If local interrupts remain enabled, the environment
>> is not guaranteed to be atomic. This can lead to a context misidentification
>> within generic kernel teardown code, causing it to incorrectly enter
>> non-atomic paths (such as attempting to acquire sleeping locks), which
>> results in fatal "scheduling while atomic" splats or system hangs.
>>
>> Additionally, stopping other CPUs ensures the primary CPU has exclusive
>> access to the hardware state during the final teardown phase, preventing
>> unpredictable interference from other active cores.
>>
>> Align RISC-V with other major architectures by disabling local interrupts
>> and stopping other CPUs at the beginning of the shutdown sequences. This
>> guarantees the architectural expectations of the kernel's restart and
>> power-off handlers are met.
>>
>> Signed-off-by: Troy Mitchell <troy.mitchell@xxxxxxxxx>
>> Tested-by: Aurelien Jarno <aurelien@xxxxxxxxxxx>
> Gentle ping on this patch. Is there anything I should change or any
> concerns with the approach?
Just a gentle ping on this series.

Please let me know if anyone has any feedback or if there is anything
I should update.

- Troy