[PATCH 2/2] MIPS: Keep interrupts as they are in breakpoint handler
From: Rong Zhang
Date: Thu Nov 19 2026 - 05:40:37 EST
Currently, the breakpoint exception handler executes STI, which enables
interrupts even when the breakpoint is located in an interrupt-disabled
critical section. Such situations usually correlate with kprobes, where
breakpoints are used to trap into the handlers and single-step the
original instruction.
As a result, registering kprobes into an IRQ-disabled critical section
could accidentally enable interrupts. Though returning to the next
instruction will restore (i.e., disable) interrupts again, it may have
caused irreversible consequences during breakpoint handling.
Build the breakpoint handler with KMODE to enter kernel mode with
interrupts left as they are.
Fixes: c1bf207d6ee1 ("MIPS: kprobe: Add support.")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Mike Yang <reimu@xxxxxxxxxxxxx>
Signed-off-by: Mike Yang <reimu@xxxxxxxxxxxxx>
Signed-off-by: Rong Zhang <rongrong@xxxxxxxxxxxxxxxxx>
---
arch/mips/kernel/genex.S | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kernel/genex.S b/arch/mips/kernel/genex.S
index be1b049d856f..e7a5f6bc31ff 100644
--- a/arch/mips/kernel/genex.S
+++ b/arch/mips/kernel/genex.S
@@ -485,6 +485,10 @@ NESTED(nmi_handler, PT_SIZE, sp)
TRACE_IRQS_OFF
.endm
+ .macro __build_clear_kmode
+ KMODE
+ .endm
+
.macro __build_clear_fpe
CLI
TRACE_IRQS_OFF
@@ -569,7 +573,7 @@ NESTED(nmi_handler, PT_SIZE, sp)
BUILD_HANDLER ades ade ade silent /* #5 */
BUILD_HANDLER ibe be cli silent /* #6 */
BUILD_HANDLER dbe be cli silent /* #7 */
- BUILD_HANDLER bp bp sti silent /* #9 */
+ BUILD_HANDLER bp bp kmode silent /* #9 */
BUILD_HANDLER ri ri sti silent /* #10 */
BUILD_HANDLER cpu cpu sti silent /* #11 */
BUILD_HANDLER ov ov sti silent /* #12 */
--
2.55.0