Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64/entry: Don't disable preemption in debug_exception_enter() with RT kernel
@ 2026-05-19 22:25 Waiman Long
  2026-05-20  0:23 ` Luis Claudio R. Goncalves
  2026-05-20  6:19 ` Sebastian Andrzej Siewior
  0 siblings, 2 replies; 3+ messages in thread
From: Waiman Long @ 2026-05-19 22:25 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Mark Rutland,
	Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt
  Cc: linux-arm-kernel, linux-kernel, linux-rt-devel, Waiman Long

Commit d8bb6718c4db ("arm64: Make debug exception handlers visible from
RCU") introduces debug_exception_enter() and debug_exception_exit()
where preemption is explicitly disabled. With a PREEMPT_RT debug kernel,
the following bug report can happen.

  BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
  in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 15255, name: gdb_app
  preempt_count: 1, expected: 0
  RCU nest depth: 0, expected: 0
  1 lock held by gdb_app/15255:
  #0: ffff10007f41b7d8 (&sighand->siglock){..}-{3:3}, at: force_sig_info_to_task+0x34/0x130
  Preemption disabled at:
  [<ffff800080081ea8>] debug_exception_enter+0x18/0x70
    :
  Call trace:
  dump_backtrace+0xac/0x130
  show_stack+0x1c/0x24
  dump_stack_lvl+0xa0/0xe0
  dump_stack+0x14/0x2c
  __might_resched+0x178/0x230
  rt_spin_lock+0x58/0x120
  force_sig_info_to_task+0x34/0x130
  force_sig_fault+0x58/0x80
  arm64_force_sig_fault+0x44/0x70
  send_user_sigtrap+0x5c/0xa0
  brk_handler+0x38/0x5c
  do_debug_exception+0x78/0x110
  el0_dbg+0x50/0x1e0
  el0t_64_sync_handler+0x114/0x150
  el0t_64_sync+0x17c/0x180

Fix that by blocking the preempt_disable()/preempt_enable_no_resched()
calls when CONFIG_PREEMPT_RT is enabled.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 arch/arm64/kernel/entry-common.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index c7a23f7c2212..191441b22b7c 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -290,15 +290,17 @@ static __always_inline void fpsimd_syscall_exit(void)
 }
 
 /*
- * In debug exception context, we explicitly disable preemption despite
- * having interrupts disabled.
+ * In debug exception context, we explicitly disable preemption except for
+ * PREEMPT_RT kernel as rt_spin_lock() can be called.
+ *
  * This serves two purposes: it makes it much less likely that we would
  * 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)
 {
-	preempt_disable();
+	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+		preempt_disable();
 
 	/* This code is a bit fragile.  Test it. */
 	RCU_LOCKDEP_WARN(!rcu_is_watching(), "exception_enter didn't work");
@@ -307,7 +309,8 @@ NOKPROBE_SYMBOL(debug_exception_enter);
 
 static void debug_exception_exit(struct pt_regs *regs)
 {
-	preempt_enable_no_resched();
+	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+		preempt_enable_no_resched();
 }
 NOKPROBE_SYMBOL(debug_exception_exit);
 
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64/entry: Don't disable preemption in debug_exception_enter() with RT kernel
  2026-05-19 22:25 [PATCH] arm64/entry: Don't disable preemption in debug_exception_enter() with RT kernel Waiman Long
@ 2026-05-20  0:23 ` Luis Claudio R. Goncalves
  2026-05-20  6:19 ` Sebastian Andrzej Siewior
  1 sibling, 0 replies; 3+ messages in thread
From: Luis Claudio R. Goncalves @ 2026-05-20  0:23 UTC (permalink / raw)
  To: Waiman Long, Ada Couprie Diaz
  Cc: Catalin Marinas, Will Deacon, Mark Rutland,
	Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
	linux-arm-kernel, linux-kernel, linux-rt-devel

On Tue, May 19, 2026 at 06:25:24PM -0400, Waiman Long wrote:
> Commit d8bb6718c4db ("arm64: Make debug exception handlers visible from
> RCU") introduces debug_exception_enter() and debug_exception_exit()
> where preemption is explicitly disabled. With a PREEMPT_RT debug kernel,
> the following bug report can happen.
> 
>   BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
>   in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 15255, name: gdb_app
>   preempt_count: 1, expected: 0
>   RCU nest depth: 0, expected: 0
>   1 lock held by gdb_app/15255:
>   #0: ffff10007f41b7d8 (&sighand->siglock){..}-{3:3}, at: force_sig_info_to_task+0x34/0x130
>   Preemption disabled at:
>   [<ffff800080081ea8>] debug_exception_enter+0x18/0x70
>     :
>   Call trace:
>   dump_backtrace+0xac/0x130
>   show_stack+0x1c/0x24
>   dump_stack_lvl+0xa0/0xe0
>   dump_stack+0x14/0x2c
>   __might_resched+0x178/0x230
>   rt_spin_lock+0x58/0x120
>   force_sig_info_to_task+0x34/0x130
>   force_sig_fault+0x58/0x80
>   arm64_force_sig_fault+0x44/0x70
>   send_user_sigtrap+0x5c/0xa0
>   brk_handler+0x38/0x5c
>   do_debug_exception+0x78/0x110
>   el0_dbg+0x50/0x1e0
>   el0t_64_sync_handler+0x114/0x150
>   el0t_64_sync+0x17c/0x180
> 
> Fix that by blocking the preempt_disable()/preempt_enable_no_resched()
> calls when CONFIG_PREEMPT_RT is enabled.

Hi Waiman!

Last year Ada Couprie Diaz wrote a patcheseries that enhanced greatly the
ARM64 debug exception code. In the cover letter there is a discussion about
the effect of the patches on RT[0] (look for PREEMPT_RT), explaining that
there are a few remaining known bugs and briefly discussing the best way to
fix then. There is also a discussion[1] about the specific issue you reported.

I took the liberty of adding Ada to the thread.

Best regards,
Luis

[0] https://lore.kernel.org/all/20250707114109.35672-1-ada.coupriediaz@arm.com/
[1] https://lore.kernel.org/linux-arm-kernel/e86c5c3a-6666-46a7-b7ec-e803212a81a1@arm.com/
 
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  arch/arm64/kernel/entry-common.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> index c7a23f7c2212..191441b22b7c 100644
> --- a/arch/arm64/kernel/entry-common.c
> +++ b/arch/arm64/kernel/entry-common.c
> @@ -290,15 +290,17 @@ static __always_inline void fpsimd_syscall_exit(void)
>  }
>  
>  /*
> - * In debug exception context, we explicitly disable preemption despite
> - * having interrupts disabled.
> + * In debug exception context, we explicitly disable preemption except for
> + * PREEMPT_RT kernel as rt_spin_lock() can be called.
> + *
>   * This serves two purposes: it makes it much less likely that we would
>   * 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)
>  {
> -	preempt_disable();
> +	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
> +		preempt_disable();
>  
>  	/* This code is a bit fragile.  Test it. */
>  	RCU_LOCKDEP_WARN(!rcu_is_watching(), "exception_enter didn't work");
> @@ -307,7 +309,8 @@ NOKPROBE_SYMBOL(debug_exception_enter);
>  
>  static void debug_exception_exit(struct pt_regs *regs)
>  {
> -	preempt_enable_no_resched();
> +	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
> +		preempt_enable_no_resched();
>  }
>  NOKPROBE_SYMBOL(debug_exception_exit);
>  
> -- 
> 2.54.0
> 
> 
---end quoted text---



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64/entry: Don't disable preemption in debug_exception_enter() with RT kernel
  2026-05-19 22:25 [PATCH] arm64/entry: Don't disable preemption in debug_exception_enter() with RT kernel Waiman Long
  2026-05-20  0:23 ` Luis Claudio R. Goncalves
@ 2026-05-20  6:19 ` Sebastian Andrzej Siewior
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-05-20  6:19 UTC (permalink / raw)
  To: Waiman Long
  Cc: Catalin Marinas, Will Deacon, Mark Rutland, Clark Williams,
	Steven Rostedt, linux-arm-kernel, linux-kernel, linux-rt-devel

On 2026-05-19 18:25:24 [-0400], Waiman Long wrote:
> Commit d8bb6718c4db ("arm64: Make debug exception handlers visible from
> RCU") introduces debug_exception_enter() and debug_exception_exit()
> where preemption is explicitly disabled. With a PREEMPT_RT debug kernel,
> the following bug report can happen.
…

What kernel is this? I have backport (which is being tested) for v6.6
and v6.12, the patches are from v6.17-rc1.

Sebastian


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-20  6:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 22:25 [PATCH] arm64/entry: Don't disable preemption in debug_exception_enter() with RT kernel Waiman Long
2026-05-20  0:23 ` Luis Claudio R. Goncalves
2026-05-20  6:19 ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox