git: 52fd2aabb772 - stable/15 - powerpc: powerpc_ipi_handler(): Stop first, preempt last

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Wed, 04 Nov 2026 13:25:18 UTC
The branch stable/15 has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=52fd2aabb7726521e81f620d98a4c8d8c5a784fe

commit 52fd2aabb7726521e81f620d98a4c8d8c5a784fe
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-10-17 17:38:59 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-11-04 13:21:38 +0000

    powerpc: powerpc_ipi_handler(): Stop first, preempt last
    
    Preemption should happen last so that other IPIs have a chance to be
    executed in due course, in particular hardclockintr().  So, move
    handling of IPI_PREEMPT at the end.
    
    An IPI_STOP/IPI_STOP_HARD request should be processed immediately to
    avoid risks that further processing changes the system state on panic,
    or worse itself causes another panic on corrupted kernel state.
    
    While here, move IPI_AST handling just before IPI_PREEMPT.  We currently
    do not need to do anything for it, but if we were to, it is likely that
    would have to happen after other IPIs but IPI_PREEMPT.
    
    Reviewed by:    jhibbits
    Fixes:          9d5a22b928c2 ("MFp4: SMP support")
    Fixes:          12640815f815 ("MFp4: SMP support")
    Fixes:          7ed09a6778d3 ("powerpc: Rework IPI message processing")
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D60863
    
    (cherry picked from commit 07ab87b60d08c665eab0b187e81a239145f9961d)
---
 sys/powerpc/powerpc/mp_machdep.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/sys/powerpc/powerpc/mp_machdep.c b/sys/powerpc/powerpc/mp_machdep.c
index d6d140aa0ea2..ce0557c28d5a 100644
--- a/sys/powerpc/powerpc/mp_machdep.c
+++ b/sys/powerpc/powerpc/mp_machdep.c
@@ -301,17 +301,7 @@ powerpc_ipi_handler(void *arg)
 	ipimask = atomic_readandclear_32(&(pcpup->pc_ipimask));
 	if (ipimask == 0)
 		return (FILTER_STRAY);
-	if (ipimask & (1 << IPI_AST)) {
-		CTR1(KTR_SMP, "%s: IPI_AST", __func__);
-	}
-	if (ipimask & (1 << IPI_PREEMPT)) {
-		CTR1(KTR_SMP, "%s: IPI_PREEMPT", __func__);
-		sched_preempt(curthread);
-	}
-	if (ipimask & (1 << IPI_RENDEZVOUS)) {
-		CTR1(KTR_SMP, "%s: IPI_RENDEZVOUS", __func__);
-		smp_rendezvous_action();
-	}
+	/* A stop request should not be delayed.  Keep it first. */
 	if (ipimask & (1 << IPI_STOP)) {
 
 		/*
@@ -329,10 +319,26 @@ powerpc_ipi_handler(void *arg)
 		CPU_CLR_ATOMIC(cpuid, &started_cpus);
 		CTR1(KTR_SMP, "%s: IPI_STOP (restart)", __func__);
 	}
+	if (ipimask & (1 << IPI_RENDEZVOUS)) {
+		CTR1(KTR_SMP, "%s: IPI_RENDEZVOUS", __func__);
+		smp_rendezvous_action();
+	}
 	if (ipimask & (1 << IPI_HARDCLOCK)) {
 		CTR1(KTR_SMP, "%s: IPI_HARDCLOCK", __func__);
 		hardclockintr();
 	}
+	if (ipimask & (1 << IPI_AST)) {
+		CTR1(KTR_SMP, "%s: IPI_AST", __func__);
+	}
+	/*
+	 * sched_preempt() causes an immediate switch to another thread when not
+	 * executing in a critical section.  In order to ensure that all other
+	 * IPIs are processed in due course, it has to be called last.
+	 */
+	if (ipimask & (1 << IPI_PREEMPT)) {
+		CTR1(KTR_SMP, "%s: IPI_PREEMPT", __func__);
+		sched_preempt(curthread);
+	}
 
 	return (FILTER_HANDLED);
 }