All of lore.kernel.org
 help / color / mirror / Atom feed
From: He Zhe <zhe.he@windriver.com>
To: catalin.marinas@arm.com, will@kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, zhe.he@windriver.com,
	bigeasy@linutronix.de, tglx@linutronix.de, rostedt@goodmis.org,
	linux-rt-users@vger.kernel.org
Subject: [PATCH] arm64: signal: Delay calling signals in atomic
Date: Tue, 12 Oct 2021 16:44:21 +0800	[thread overview]
Message-ID: <20211012084421.35136-1-zhe.he@windriver.com> (raw)

Debugging with breakpoints on arm64 and RT would trigger the following
call trace. When CONFIG_PREEMPT_RT is enabled, spin_locks become mutexes,
and one of these is the spin lock used in signal handling.

BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:46
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 357, name: multi-timer
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
Preemption disabled at:
[<ffffffc01002f11c>] do_debug_exception+0x58/0x14c
CPU: 0 PID: 357 Comm: multi-timer Not tainted 5.15.0-rc4-rt8-yocto-preempt-rt #1
Hardware name: linux,dummy-virt (DT)
Call trace:
 dump_backtrace+0x0/0x19c
 show_stack+0x24/0x30
 dump_stack_lvl+0x7c/0xa0
 dump_stack+0x18/0x34
 __might_resched+0x160/0x1c0
 rt_spin_lock+0x3c/0xb0
 force_sig_info_to_task+0x38/0x14c
 force_sig_fault+0x60/0x84
 arm64_force_sig_fault+0x4c/0x7c
 send_user_sigtrap+0x70/0x84
 single_step_handler+0x50/0xf0
 do_debug_exception+0xa4/0x14c
 el0_dbg+0x20/0x60
 el0t_64_sync_handler+0x110/0x1b0
 el0t_64_sync+0x1a0/0x1a4

Fix potential sleep while atomic in the similar way of
2dbbc3a07009 ("signal/x86: Delay calling signals in atomic")

Define ARCH_RT_DELAYS_SIGNAL_SEND to enable delaying action in
force_sig_info_to_task. Add actual sending action to arm64 specific path.

Signed-off-by: He Zhe <zhe.he@windriver.com>
---
 arch/arm64/include/asm/signal.h | 4 ++++
 arch/arm64/kernel/signal.c      | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm64/include/asm/signal.h b/arch/arm64/include/asm/signal.h
index ef449f5f4ba8..5e535c3e4926 100644
--- a/arch/arm64/include/asm/signal.h
+++ b/arch/arm64/include/asm/signal.h
@@ -22,4 +22,8 @@ static inline void __user *arch_untagged_si_addr(void __user *addr,
 }
 #define arch_untagged_si_addr arch_untagged_si_addr
 
+#if defined(CONFIG_PREEMPT_RT)
+#define ARCH_RT_DELAYS_SIGNAL_SEND
+#endif
+
 #endif
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 8a9194ed981c..1d65f2801e13 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -928,6 +928,14 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
 		} else {
 			local_daif_restore(DAIF_PROCCTX);
 
+#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
+			if (unlikely(current->forced_info.si_signo)) {
+				struct task_struct *t = current;
+				force_sig_info(&t->forced_info);
+				t->forced_info.si_signo = 0;
+			}
+#endif
+
 			if (thread_flags & _TIF_UPROBE)
 				uprobe_notify_resume(regs);
 
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: He Zhe <zhe.he@windriver.com>
To: catalin.marinas@arm.com, will@kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, zhe.he@windriver.com,
	bigeasy@linutronix.de, tglx@linutronix.de, rostedt@goodmis.org,
	linux-rt-users@vger.kernel.org
Subject: [PATCH] arm64: signal: Delay calling signals in atomic
Date: Tue, 12 Oct 2021 16:44:21 +0800	[thread overview]
Message-ID: <20211012084421.35136-1-zhe.he@windriver.com> (raw)

Debugging with breakpoints on arm64 and RT would trigger the following
call trace. When CONFIG_PREEMPT_RT is enabled, spin_locks become mutexes,
and one of these is the spin lock used in signal handling.

BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:46
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 357, name: multi-timer
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
Preemption disabled at:
[<ffffffc01002f11c>] do_debug_exception+0x58/0x14c
CPU: 0 PID: 357 Comm: multi-timer Not tainted 5.15.0-rc4-rt8-yocto-preempt-rt #1
Hardware name: linux,dummy-virt (DT)
Call trace:
 dump_backtrace+0x0/0x19c
 show_stack+0x24/0x30
 dump_stack_lvl+0x7c/0xa0
 dump_stack+0x18/0x34
 __might_resched+0x160/0x1c0
 rt_spin_lock+0x3c/0xb0
 force_sig_info_to_task+0x38/0x14c
 force_sig_fault+0x60/0x84
 arm64_force_sig_fault+0x4c/0x7c
 send_user_sigtrap+0x70/0x84
 single_step_handler+0x50/0xf0
 do_debug_exception+0xa4/0x14c
 el0_dbg+0x20/0x60
 el0t_64_sync_handler+0x110/0x1b0
 el0t_64_sync+0x1a0/0x1a4

Fix potential sleep while atomic in the similar way of
2dbbc3a07009 ("signal/x86: Delay calling signals in atomic")

Define ARCH_RT_DELAYS_SIGNAL_SEND to enable delaying action in
force_sig_info_to_task. Add actual sending action to arm64 specific path.

Signed-off-by: He Zhe <zhe.he@windriver.com>
---
 arch/arm64/include/asm/signal.h | 4 ++++
 arch/arm64/kernel/signal.c      | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm64/include/asm/signal.h b/arch/arm64/include/asm/signal.h
index ef449f5f4ba8..5e535c3e4926 100644
--- a/arch/arm64/include/asm/signal.h
+++ b/arch/arm64/include/asm/signal.h
@@ -22,4 +22,8 @@ static inline void __user *arch_untagged_si_addr(void __user *addr,
 }
 #define arch_untagged_si_addr arch_untagged_si_addr
 
+#if defined(CONFIG_PREEMPT_RT)
+#define ARCH_RT_DELAYS_SIGNAL_SEND
+#endif
+
 #endif
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 8a9194ed981c..1d65f2801e13 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -928,6 +928,14 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
 		} else {
 			local_daif_restore(DAIF_PROCCTX);
 
+#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
+			if (unlikely(current->forced_info.si_signo)) {
+				struct task_struct *t = current;
+				force_sig_info(&t->forced_info);
+				t->forced_info.si_signo = 0;
+			}
+#endif
+
 			if (thread_flags & _TIF_UPROBE)
 				uprobe_notify_resume(regs);
 
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2021-10-12  8:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12  8:44 He Zhe [this message]
2021-10-12  8:44 ` [PATCH] arm64: signal: Delay calling signals in atomic He Zhe
2021-10-15 17:03 ` Sebastian Andrzej Siewior
2021-10-15 17:03   ` Sebastian Andrzej Siewior

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=20211012084421.35136-1-zhe.he@windriver.com \
    --to=zhe.he@windriver.com \
    --cc=bigeasy@linutronix.de \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.