From: "Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-rt-devel@lists.linux.dev,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Mark Brown <broonie@kernel.org>, Ard Biesheuvel <ardb@kernel.org>,
Joey Gouly <joey.gouly@arm.com>,
linux-kernel@vger.kernel.org
Subject: Re: BUG: debug_exception_enter() disables preemption and may call sleeping functions on aarch64 with RT
Date: Tue, 11 Feb 2025 21:35:40 -0300 [thread overview]
Message-ID: <Z6vs3IWxUxhIDBBO@uudg.org> (raw)
In-Reply-To: <Z6tf8iDhNriSGjeC@uudg.org>
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:
> > On Fri, Feb 07, 2025 at 11:22:57AM -0300, Luis Claudio R. Goncalves wrote:
...
> > 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);
next prev parent reply other threads:[~2025-02-12 0:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 14:22 BUG: debug_exception_enter() disables preemption and may call sleeping functions on aarch64 with RT Luis Claudio R. Goncalves
2025-02-10 12:49 ` Mark Rutland
2025-02-10 14:06 ` Sebastian Andrzej Siewior
2025-02-12 0:48 ` Luis Claudio R. Goncalves
2025-02-12 11:21 ` Sebastian Andrzej Siewior
2025-02-11 14:34 ` Luis Claudio R. Goncalves
2025-02-12 0:35 ` Luis Claudio R. Goncalves [this message]
2025-02-12 12:40 ` Mark Rutland
2025-02-12 13:07 ` Mark Rutland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z6vs3IWxUxhIDBBO@uudg.org \
--to=lgoncalv@redhat.com \
--cc=ardb@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=rostedt@goodmis.org \
--cc=ryan.roberts@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).