[PATCH 1/3] x86/reboot: Allow "blindly" calling nmi_shootdown_cpus() without a callback

From: Sean Christopherson
Date: Tue Sep 03 2024 - 13:14:27 EST


Warn if nmi_shootdown_cpus() is called after the crash IPI has been issued
if and only if the caller wants to run a specific callback, and drop the
check nmi_shootdown_cpus_on_restart() whose sole purpose was to avoid
triggering the warning. This will allow removing the "on restart" variant.

Note, the only caller of nmi_shootdown_cpus_on_restart() unconditionally
disables IRQs, i.e. doubling down on disabling IRQs when a crash IPI has
already been issued doesn't affect the resulting functionality.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kernel/reboot.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 615922838c51..25f68952af57 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -915,10 +915,14 @@ void nmi_shootdown_cpus(nmi_shootdown_cb callback)
/*
* Avoid certain doom if a shootdown already occurred; re-registering
* the NMI handler will cause list corruption, modifying the callback
- * will do who knows what, etc...
+ * will do who knows what, etc... Blindly attempting a shootdown is
+ * allowed if the caller's goal is purely to ensure a shootdown occurs,
+ * i.e. if the caller doesn't want to run a specific callback.
*/
- if (WARN_ON_ONCE(crash_ipi_issued))
+ if (crash_ipi_issued) {
+ WARN_ON_ONCE(callback);
return;
+ }

/* Make a note of crashing cpu. Will be used in NMI callback. */
crashing_cpu = safe_smp_processor_id();
@@ -956,8 +960,7 @@ void nmi_shootdown_cpus(nmi_shootdown_cb callback)

static inline void nmi_shootdown_cpus_on_restart(void)
{
- if (!crash_ipi_issued)
- nmi_shootdown_cpus(NULL);
+ nmi_shootdown_cpus(NULL);
}

/*

base-commit: 8cf0b93919e13d1e8d4466eb4080a4c4d9d66d7b
--
2.47.0.rc1.288.g06298d1525-goog


--Osa6c5ZHj6sBiqsE
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="0002-x86-reboot-Open-code-nmi_shootdown_cpus_on_restart-i.patch"