Module Name:    src
Committed By:   jmcneill
Date:           Sat Feb 15 00:30:49 UTC 2025

Modified Files:
        src/sys/arch/powerpc/pic: intr.c

Log Message:
powerpc: Fix ci_ipending corruption with cascaded pics

A cascaded pic will register pic_handle_intr as its interrupt handler,
but interrupt handlers are called with MSR[EE] = 1. This breaks
assumptions in pic callbacks and can result in eg. corrupt ci_ipending
due to a read/modify/write of the field with nested interrupts.

Fix this by always clearing MSR[EE] at the top of pic_handle_intr.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/powerpc/pic/intr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/pic/intr.c
diff -u src/sys/arch/powerpc/pic/intr.c:1.34 src/sys/arch/powerpc/pic/intr.c:1.35
--- src/sys/arch/powerpc/pic/intr.c:1.34	Wed Feb 16 23:49:27 2022
+++ src/sys/arch/powerpc/pic/intr.c	Sat Feb 15 00:30:49 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.34 2022/02/16 23:49:27 riastradh Exp $ */
+/*	$NetBSD: intr.c,v 1.35 2025/02/15 00:30:49 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -29,7 +29,7 @@
 #define __INTR_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.34 2022/02/16 23:49:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.35 2025/02/15 00:30:49 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_interrupt.h"
@@ -560,13 +560,17 @@ pic_handle_intr(void *cookie)
 	struct cpu_info *ci = curcpu();
 	int picirq;
 
-	picirq = pic->pic_get_irq(pic, PIC_GET_IRQ);
-	if (picirq == 255)
-		return 0;
-
 	const register_t msr = mfmsr();
 	const int pcpl = ci->ci_cpl;
 
+	mtmsr(msr & ~PSL_EE);
+
+	picirq = pic->pic_get_irq(pic, PIC_GET_IRQ);
+	if (picirq == 255) {
+		mtmsr(msr);
+		return 0;
+	}
+
 	do {
 		const int virq = virq_map[picirq + pic->pic_intrbase];
 

Reply via email to