Re: BUG: debug_exception_enter() disables preemption and may call sleeping functions on aarch64 with RT
From: Luis Claudio R. Goncalves <hidden>
Date: 2025-02-12 00:35:56
Also in:
linux-rt-devel, lkml
Subsystem:
arm64 port (aarch64 architecture), the rest · Maintainers:
Catalin Marinas, Will Deacon, Linus Torvalds
On Tue, Feb 11, 2025 at 11:34:26AM -0300, Luis Claudio R. Goncalves wrote:
On Mon, Feb 10, 2025 at 12:49:45PM +0000, Mark Rutland wrote:quoted
On Fri, Feb 07, 2025 at 11:22:57AM -0300, Luis Claudio R. Goncalves wrote:
...
quoted
I don't have an immediate suggestion; I'll need to go think about this for a bit. Unfortunatealy, there are several nested cans of worms here. :/ In theory, we can go split out the EL0 "debug exceptions" into separate handlers, and wouldn't generally need to disable preemption for things like BRK or single-step.If this is an acceptable workaround, until we have the real solution, I can work on that :) Luis
I tested the prototype below and it survived 6h of ssdd and the ptrace LTP tests running simultaneously, in a tight loop. Would something along these lines be an acceptable workaround?
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 8b281cf308b30..eb3b54710024f 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c@@ -933,18 +933,20 @@ void __init hook_debug_fault_code(int nr, * accidentally schedule in exception context and it will force a warning * if we somehow manage to schedule by accident. */ -static void debug_exception_enter(struct pt_regs *regs) +static void debug_exception_enter(struct pt_regs *regs, int touch_preemption) { - preempt_disable(); + if (touch_preemption) + preempt_disable(); /* This code is a bit fragile. Test it. */ RCU_LOCKDEP_WARN(!rcu_is_watching(), "exception_enter didn't work"); } NOKPROBE_SYMBOL(debug_exception_enter); -static void debug_exception_exit(struct pt_regs *regs) +static void debug_exception_exit(struct pt_regs *regs, int touch_preemption) { - preempt_enable_no_resched(); + if (touch_preemption) + preempt_enable_no_resched(); } NOKPROBE_SYMBOL(debug_exception_exit);
@@ -953,8 +955,14 @@ void do_debug_exception(unsigned long addr_if_watchpoint, unsigned long esr, { const struct fault_info *inf = esr_to_debug_fault_info(esr); unsigned long pc = instruction_pointer(regs); + unsigned long req = ESR_ELx_EC(esr); + int touch_preemption; - debug_exception_enter(regs); + touch_preemption = !(IS_ENABLED(CONFIG_PREEMPT_RT) && + (req == ESR_ELx_EC_SOFTSTP_LOW || req == ESR_ELx_EC_BRK64 + || req == ESR_ELx_EC_BKPT32 || req == ESR_ELx_EC_SOFTSTP_CUR)); + + debug_exception_enter(regs, touch_preemption); if (user_mode(regs) && !is_ttbr0_addr(pc)) arm64_apply_bp_hardening();
@@ -963,7 +971,7 @@ void do_debug_exception(unsigned long addr_if_watchpoint, unsigned long esr, arm64_notify_die(inf->name, regs, inf->sig, inf->code, pc, esr); } - debug_exception_exit(regs); + debug_exception_exit(regs, touch_preemption); } NOKPROBE_SYMBOL(do_debug_exception);