Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
To: linux-arm-kernel@lists.infradead.org
Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>,
	Russell King <linux@armlinux.org.uk>,
	Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH 09/11] ARM: traps: Move the BUG handling from die() to do_undefinstr()
Date: Sat, 10 Oct 2026 00:21:16 +0200	[thread overview]
Message-ID: <20261010-arm_warning-v1-9-ddf4be42ae0d@breakpoint.cc> (raw)
In-Reply-To: <20261010-arm_warning-v1-0-ddf4be42ae0d@breakpoint.cc>

The BUG() macro uses an opcode which is treated as an invalid opcode by
the ARM core. There is no dedicated handling for this. Instead, should
the core step onto an invalid opcode then the do_undefinstr() will
eventually end in die(). At this point, the kernel will crash and stop
invoking opcodes.

Move the BUG handling earlier to do_undefinstr() in the kernel block.
This allows a different handling if a BUG-entry is found.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
 arch/arm/kernel/traps.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index afbd2ebe5c39d..1353bf24da53f 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -355,14 +355,10 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
  */
 void die(const char *str, struct pt_regs *regs, int err)
 {
-	enum bug_trap_type bug_type = BUG_TRAP_TYPE_NONE;
-	unsigned long flags = oops_begin();
+	unsigned long flags;
 	int sig = SIGSEGV;
 
-	if (!user_mode(regs))
-		bug_type = report_bug(regs->ARM_pc, regs);
-	if (bug_type != BUG_TRAP_TYPE_NONE)
-		str = "Oops - BUG";
+	flags = oops_begin();
 
 	if (__die(str, err, regs))
 		sig = 0;
@@ -442,6 +438,26 @@ int call_undef_hook(struct pt_regs *regs, unsigned int instr)
 	return fn ? fn(regs, instr) : 1;
 }
 
+static int handle_bug_opcode(unsigned int instr, struct pt_regs *regs)
+{
+	enum bug_trap_type bug_type;
+	unsigned long flags;
+	int sig = SIGSEGV;
+
+	if (instr != BUG_INSTR_VALUE)
+		return 0;
+
+	bug_type = report_bug(regs->ARM_pc, regs);
+	if (bug_type == BUG_TRAP_TYPE_NONE)
+		return 0;
+
+	flags = oops_begin();
+	if (__die("Oops - BUG", 0, regs))
+		sig = 0;
+	oops_end(flags, regs, sig);
+	return 1;
+}
+
 asmlinkage void do_undefinstr(struct pt_regs *regs)
 {
 	unsigned int instr;
@@ -461,6 +477,10 @@ asmlinkage void do_undefinstr(struct pt_regs *regs)
 		} else
 #endif
 			instr = __mem_to_opcode_arm(*(u32 *) pc);
+
+		if (handle_bug_opcode(instr, regs))
+			return;
+
 	} else if (thumb_mode(regs)) {
 		if (get_user(instr, (u16 __user *)pc))
 			goto die_sig;

-- 
2.55.0



  parent reply	other threads:[~2026-10-09 22:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 01/11] ARM: BUG: Move the assembly out of __BUG() macro Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 02/11] ARM: BUG: Spent each entry in __BUG__LINE() its own line Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 03/11] ARM: BUG: Move the section right after the opcode Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 04/11] ARM: BUG: Move file/ line encoding into a custom macro Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 05/11] ARM: BUG: Move __bug_table creation to __BUG_ENTRY_GENERIC() macro Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 06/11] ARM: BUG: Move the __BUG() out of CONFIG_DEBUG_BUGVERBOSE Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 07/11] ARM: BUG: Pass a flags argument to __BUG__LINE() Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 08/11] ARM: BUG: Move BUG() into the do-while loop Sebastian Andrzej Siewior
2026-10-09 22:21 ` Sebastian Andrzej Siewior [this message]
2026-10-09 22:21 ` [PATCH 10/11] ARM: traps: Add handling for warnings to handle_bug_opcode() Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 11/11] ARM: BUG: Add WARN support via __WARN_FLAGS() 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=20261010-arm_warning-v1-9-ddf4be42ae0d@breakpoint.cc \
    --to=sebastian@breakpoint.cc \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    /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