[PATCH 0/2] MIPS: kprobes fixes

From: Rong Zhang

Date: Thu Nov 19 2026 - 05:40:22 EST


arch_prepare_kprobe() writes the copied instruction and a single-step
completion breakpoint into an out-of-line instruction slot, but does not
synchronize the instruction cache for it. Due to arch_arm_kprobe() only
flushing the probed instruction by calling flush_insn_slot(), the
executable slot may remain unflushed when the kprobe is hit. This
becomes critical when get_insn_slot() reuses a just-freed slot.

Fix it by calling flush_icache_range() to really finish the preparation.

Additionally, 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.

Fix it by building the breakpoint handler with KMODE to enter kernel
mode with interrupts left as they are.

Fixes: c1bf207d6ee1 ("MIPS: kprobe: Add support.")
Co-developed-by: Mike Yang <reimu@xxxxxxxxxxxxx>
Signed-off-by: Mike Yang <reimu@xxxxxxxxxxxxx>
Signed-off-by: Rong Zhang <rongrong@xxxxxxxxxxxxxxxxx>
---
Rong Zhang (2):
MIPS: kprobes: Flush out-of-line instruction slots before use
MIPS: Keep interrupts as they are in breakpoint handler

arch/mips/kernel/genex.S | 6 +++++-
arch/mips/kernel/kprobes.c | 9 +++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
---
base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
change-id: c0497927-mips-kprobes-bp-eb8d4af0a685

Thanks,
Rong