arm64: power off a CPU stopped by the SDEI NMI

A CPU stopped via the SDEI rung previously parked inside its event
handler. That leaves the SDEI event uncompleted (EL3 keeps the dispatch
slot until reset) and, more importantly, leaves the CPU merely parked:
PSCI still reports it ON, so an SMP capture kernel cannot reclaim it with
CPU_ON. SMP kdump capture kernels are common (parallel makedumpfile), so
this matters.

Power the CPU off instead, the way ipi_cpu_crash_stop() already does.
PSCI CPU_OFF cannot be issued from inside an in-flight SDEI event, so the
stop entry only does the bookkeeping (crash_save_cpu() on the kdump path,
set_cpu_online(false), mask the PE) and flags a pending park.
do_sdei_event() consumes the flag and returns the address of
__sdei_nmi_cpu_park, so the SDEI exit path completes the event with
SDEI_EVENT_COMPLETE_AND_RESUME and resumes there; the stub switches to
this CPU's (now-free) SDEI stack and calls __cpu_try_die(), falling back
to a park loop if CPU_OFF is unavailable. With the event completed EL3
holds no state for the PE, and the powered-off CPU is reclaimable by a
later kernel.

COMPLETE_AND_RESUME resumes into kernel text, which is not mapped on the
KPTI return path to EL0. A CPU interrupted in userspace is reached by the
stop IPI rather than this rung, so that only arises as a rare race; for
it, park in-handler (event left uncompleted) instead.

Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
5 files changed