[PATCH v2 1/2] arm64: kprobes: disable preemption across XOL single-step

Khaja Hussain Shaik Khaji
2026-02-17T13:39:32Z

On arm64, non-emulatable kprobes instructions execute out-of-line (XOL)
after returning from the initial debug exception. The XOL instruction
runs in normal kernel context, while kprobe state is maintained per-CPU.

If the task is preempted or migrates during the XOL window, the subsequent
SS-BRK exception may be handled on a different CPU, corrupting per-CPU
kprobe state and preventing correct recovery.

Disable preemption across the XOL instruction and re-enable it in the
SS-BRK handler to prevent migration until control returns to the kprobe
handler.

Signed-off-by: Khaja Hussain Shaik Khaji <khaja.khaji@oss.qualcomm.com>
---
arch/arm64/kernel/probes/kprobes.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 43a0361a8bf0..d8a70c456543 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -227,6 +227,14 @@ static void __kprobes setup_singlestep(struct kprobe *p,

kprobes_save_local_irqflag(kcb, regs);
instruction_pointer_set(regs, slot);
+
+ /*
+ * Disable preemption across the out-of-line (XOL) instruction.
+ * The XOL instruction executes in normal kernel context and
+ * kprobe state is per-CPU.
+ */
+ preempt_disable();
+
} else {
/* insn simulation */
arch_simulate_insn(p, regs);
@@ -363,6 +371,11 @@ kprobe_ss_brk_handler(struct pt_regs *regs, unsigned long esr)
kprobes_restore_local_irqflag(kcb, regs);
post_kprobe_handler(cur, kcb, regs);

+ /*
+ * Re-enable preemption after completing the XOL instruction.
+ */
+ preempt_enable_no_resched();
+
return DBG_HOOK_HANDLED;
}

--
2.34.1