* [PATCH 00/11] ARM: Use invalid opcode also for warnings
@ 2026-10-09 22:21 Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 01/11] ARM: BUG: Move the assembly out of __BUG() macro Sebastian Andrzej Siewior
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
ARM is already using an invalid opcode for BUG(). WARN_ON() an its
variants are not optimised this way. The series here massages the BUG()
implementation until __WARN_FLAGS() can make use of it. Here is
comparison build of the defconfig with and without the series:
| text data bss filename
| 19678700 10728606 407364 vmlinux
| 19434880 10814198 407748 vmlinux-patched
text -238KiB, data +84KiB, bss +384
| 19680276 10699150 408132 vmlinux-!DEBUG_BUGVERBOSE
| 19443392 10735644 408516 vmlinux-patched-!DEBUG_BUGVERBOSE
text -231KiB, data +36KiB, +384
In general the text savings are greater than the increment in data.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
Sebastian Andrzej Siewior (11):
ARM: BUG: Move the assembly out of __BUG() macro
ARM: BUG: Spent each entry in __BUG__LINE() its own line
ARM: BUG: Move the section right after the opcode
ARM: BUG: Move file/ line encoding into a custom macro
ARM: BUG: Move __bug_table creation to __BUG_ENTRY_GENERIC() macro
ARM: BUG: Move the __BUG() out of CONFIG_DEBUG_BUGVERBOSE
ARM: BUG: Pass a flags argument to __BUG__LINE()
ARM: BUG: Move BUG() into the do-while loop
ARM: traps: Move the BUG handling from die() to do_undefinstr()
ARM: traps: Add handling for warnings to handle_bug_opcode()
ARM: BUG: Add WARN support via __WARN_FLAGS()
arch/arm/include/asm/bug.h | 61 ++++++++++++++++++++++++++++------------------
arch/arm/kernel/traps.c | 40 +++++++++++++++++++++++++-----
2 files changed, 71 insertions(+), 30 deletions(-)
---
base-commit: 4eeccbed21e50c19f97be9d325511f3de6343f2d
change-id: 20261004-arm_warning-3ac1e2aea65f
Best regards,
--
Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 01/11] ARM: BUG: Move the assembly out of __BUG() macro
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
@ 2026-10-09 22:21 ` 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
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Move the assembly line from within the __BUG() macro into its own
define. The quotation marks and the string escape can be removed and
instead the resulting __BUG__LINE() macro can be wrapped into
__stringify() to achieve the same.
The BUG_INSTR() expects a string context. This can be replaced with
___asm_opcode_to_mem_arm()/_thumb16() macro. Wrap this into
BUG_ENCODING() macro.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index ba8d9d7d242bd..24f46d4f6e733 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -14,9 +14,11 @@
#ifdef CONFIG_THUMB2_KERNEL
#define BUG_INSTR_VALUE 0xde02
#define BUG_INSTR(__value) __inst_thumb16(__value)
+#define BUG_ENCODING() .short ___asm_opcode_to_mem_thumb16(BUG_INSTR_VALUE)
#else
#define BUG_INSTR_VALUE 0xe7f001f2
#define BUG_INSTR(__value) __inst_arm(__value)
+#define BUG_ENCODING() .long ___asm_opcode_to_mem_arm(BUG_INSTR_VALUE)
#endif
@@ -25,24 +27,27 @@
#ifdef CONFIG_DEBUG_BUGVERBOSE
+#define __BUG__LINE(__file, __line, __value) \
+ 1: ; \
+ BUG_ENCODING(); \
+ .pushsection .rodata.str, "aMS", %progbits, 1; \
+ 2: .asciz __file; \
+ .popsection; \
+ .pushsection __bug_table,"aw"; \
+ .align 2; \
+ 3: .word 1b, 2b; \
+ .hword __line , 0; \
+ .popsection;
+
/*
* The extra indirection is to ensure that the __FILE__ string comes through
* OK. Many version of gcc do not support the asm %c parameter which would be
* preferable to this unpleasantness. We use mergeable string sections to
* avoid multiple copies of the string appearing in the kernel image.
*/
-
#define __BUG(__file, __line, __value) \
do { \
- asm volatile("1:\t" BUG_INSTR(__value) "\n" \
- ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
- "2:\t.asciz " #__file "\n" \
- ".popsection\n" \
- ".pushsection __bug_table,\"aw\"\n" \
- ".align 2\n" \
- "3:\t.word 1b, 2b\n" \
- "\t.hword " #__line ", 0\n" \
- ".popsection"); \
+ asm volatile(__stringify(__BUG__LINE(__file, __line, __value))); \
unreachable(); \
} while (0)
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 02/11] ARM: BUG: Spent each entry in __BUG__LINE() its own line
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 ` Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 03/11] ARM: BUG: Move the section right after the opcode Sebastian Andrzej Siewior
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
After the "3:" label the individual entries for the struct bug_entry
follow.
Move the entries into their own line which makes re-grouping later
simpler.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index 24f46d4f6e733..4c01e360ccfe0 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -35,8 +35,11 @@
.popsection; \
.pushsection __bug_table,"aw"; \
.align 2; \
- 3: .word 1b, 2b; \
- .hword __line , 0; \
+ 3: \
+ .word 1b; \
+ .word 2b; \
+ .hword __line; \
+ .hword 0; \
.popsection;
/*
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 03/11] ARM: BUG: Move the section right after the opcode
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 ` Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 04/11] ARM: BUG: Move file/ line encoding into a custom macro Sebastian Andrzej Siewior
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Move the references to the opcode right after the opcode. This requires
to push the section __bug_table first and keep it open. The .rodata.str
section will nest into it but this is not a problem.
This simplifies the splitting later on.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index 4c01e360ccfe0..1bb215367eed2 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -30,13 +30,13 @@
#define __BUG__LINE(__file, __line, __value) \
1: ; \
BUG_ENCODING(); \
+ .pushsection __bug_table,"aw"; \
+ .align 2; \
+ .word 1b; \
.pushsection .rodata.str, "aMS", %progbits, 1; \
2: .asciz __file; \
.popsection; \
- .pushsection __bug_table,"aw"; \
- .align 2; \
3: \
- .word 1b; \
.word 2b; \
.hword __line; \
.hword 0; \
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 04/11] ARM: BUG: Move file/ line encoding into a custom macro
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (2 preceding siblings ...)
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 ` 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
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Move the filename encoding and the line number into a custom macro named
_BUG_VERBOSE_LINE(). This makes it simpler to add this entries depending
on CONFIG_DEBUG_BUGVERBOSE.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index 1bb215367eed2..18dc13a0509f6 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -27,18 +27,21 @@
#ifdef CONFIG_DEBUG_BUGVERBOSE
-#define __BUG__LINE(__file, __line, __value) \
- 1: ; \
- BUG_ENCODING(); \
- .pushsection __bug_table,"aw"; \
- .align 2; \
- .word 1b; \
+#define _BUG_VERBOSE_LINE(__file, __line) \
.pushsection .rodata.str, "aMS", %progbits, 1; \
2: .asciz __file; \
.popsection; \
3: \
.word 2b; \
.hword __line; \
+
+#define __BUG__LINE(__file, __line, __value) \
+ 1: ; \
+ BUG_ENCODING(); \
+ .pushsection __bug_table,"aw"; \
+ .align 2; \
+ .word 1b; \
+ _BUG_VERBOSE_LINE(__file, __line); \
.hword 0; \
.popsection;
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 05/11] ARM: BUG: Move __bug_table creation to __BUG_ENTRY_GENERIC() macro
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (3 preceding siblings ...)
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 ` Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 06/11] ARM: BUG: Move the __BUG() out of CONFIG_DEBUG_BUGVERBOSE Sebastian Andrzej Siewior
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Move the creation of the __bug_table section into a custom macro
__BUG_ENTRY_GENERIC() and make it depend on CONFIG_GENERIC_BUG.
This is preparatory work to make the creation of BUG-opcode and the
additional tables depend on CONFIG_GENERIC_BUG instead
CONFIG_DEBUG_BUGVERBOSE.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index 18dc13a0509f6..172e6a84541cb 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -35,9 +35,8 @@
.word 2b; \
.hword __line; \
-#define __BUG__LINE(__file, __line, __value) \
- 1: ; \
- BUG_ENCODING(); \
+#ifdef CONFIG_GENERIC_BUG
+#define __BUG_ENTRY_GENERIC(__file, __line, __value) \
.pushsection __bug_table,"aw"; \
.align 2; \
.word 1b; \
@@ -45,6 +44,15 @@
.hword 0; \
.popsection;
+#else
+#define __BUG_ENTRY_GENERIC(__file, __line, __value)
+#endif
+
+#define __BUG__LINE(__file, __line, __value) \
+ 1: ; \
+ BUG_ENCODING(); \
+ __BUG_ENTRY_GENERIC(__file, __line, __value);
+
/*
* The extra indirection is to ensure that the __FILE__ string comes through
* OK. Many version of gcc do not support the asm %c parameter which would be
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 06/11] ARM: BUG: Move the __BUG() out of CONFIG_DEBUG_BUGVERBOSE
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (4 preceding siblings ...)
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 ` Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 07/11] ARM: BUG: Pass a flags argument to __BUG__LINE() Sebastian Andrzej Siewior
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Move the __BUG() macro out of the CONFIG_DEBUG_BUGVERBOSE block and
provide an empty _BUG_VERBOSE_LINE() macro for the
!CONFIG_DEBUG_BUGVERBOSE case.
This allows the removal of the other __BUG implementation (in the old
!CONFIG_DEBUG_BUGVERBOSE case). Remove BUG_INSTR which has no users now.
The side effect is that the entries in __bug_table are still added but
without FILE and LINE.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index 172e6a84541cb..c47b693aed8ae 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -13,11 +13,9 @@
*/
#ifdef CONFIG_THUMB2_KERNEL
#define BUG_INSTR_VALUE 0xde02
-#define BUG_INSTR(__value) __inst_thumb16(__value)
#define BUG_ENCODING() .short ___asm_opcode_to_mem_thumb16(BUG_INSTR_VALUE)
#else
#define BUG_INSTR_VALUE 0xe7f001f2
-#define BUG_INSTR(__value) __inst_arm(__value)
#define BUG_ENCODING() .long ___asm_opcode_to_mem_arm(BUG_INSTR_VALUE)
#endif
@@ -26,7 +24,6 @@
#define _BUG(file, line, value) __BUG(file, line, value)
#ifdef CONFIG_DEBUG_BUGVERBOSE
-
#define _BUG_VERBOSE_LINE(__file, __line) \
.pushsection .rodata.str, "aMS", %progbits, 1; \
2: .asciz __file; \
@@ -35,6 +32,10 @@
.word 2b; \
.hword __line; \
+#else
+#define _BUG_VERBOSE_LINE(__file, __line)
+#endif
+
#ifdef CONFIG_GENERIC_BUG
#define __BUG_ENTRY_GENERIC(__file, __line, __value) \
.pushsection __bug_table,"aw"; \
@@ -65,15 +66,6 @@ do { \
unreachable(); \
} while (0)
-#else
-
-#define __BUG(__file, __line, __value) \
-do { \
- asm volatile(BUG_INSTR(__value) "\n"); \
- unreachable(); \
-} while (0)
-#endif /* CONFIG_DEBUG_BUGVERBOSE */
-
#define HAVE_ARCH_BUG
#include <asm-generic/bug.h>
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 07/11] ARM: BUG: Pass a flags argument to __BUG__LINE()
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (5 preceding siblings ...)
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 ` Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 08/11] ARM: BUG: Move BUG() into the do-while loop Sebastian Andrzej Siewior
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Since the hard coding of the BUG-opcode, the value argument remained
unused. Repurpose that argument as flags from struct bug_entry. For now
this is set to 0.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index c47b693aed8ae..b9e58be656360 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -20,8 +20,8 @@
#endif
-#define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE)
-#define _BUG(file, line, value) __BUG(file, line, value)
+#define BUG() _BUG(__FILE__, __LINE__)
+#define _BUG(file, line) __BUG(file, line)
#ifdef CONFIG_DEBUG_BUGVERBOSE
#define _BUG_VERBOSE_LINE(__file, __line) \
@@ -37,22 +37,22 @@
#endif
#ifdef CONFIG_GENERIC_BUG
-#define __BUG_ENTRY_GENERIC(__file, __line, __value) \
+#define __BUG_ENTRY_GENERIC(__file, __line, __flags) \
.pushsection __bug_table,"aw"; \
.align 2; \
.word 1b; \
_BUG_VERBOSE_LINE(__file, __line); \
- .hword 0; \
+ .hword __flags; \
.popsection;
#else
-#define __BUG_ENTRY_GENERIC(__file, __line, __value)
+#define __BUG_ENTRY_GENERIC(__file, __line, __flags)
#endif
-#define __BUG__LINE(__file, __line, __value) \
+#define __BUG__LINE(__file, __line, __flags) \
1: ; \
BUG_ENCODING(); \
- __BUG_ENTRY_GENERIC(__file, __line, __value);
+ __BUG_ENTRY_GENERIC(__file, __line, __flags);
/*
* The extra indirection is to ensure that the __FILE__ string comes through
@@ -60,9 +60,9 @@
* preferable to this unpleasantness. We use mergeable string sections to
* avoid multiple copies of the string appearing in the kernel image.
*/
-#define __BUG(__file, __line, __value) \
+#define __BUG(__file, __line) \
do { \
- asm volatile(__stringify(__BUG__LINE(__file, __line, __value))); \
+ asm volatile(__stringify(__BUG__LINE(__file, __line, 0))); \
unreachable(); \
} while (0)
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 08/11] ARM: BUG: Move BUG() into the do-while loop
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (6 preceding siblings ...)
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 ` Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 09/11] ARM: traps: Move the BUG handling from die() to do_undefinstr() Sebastian Andrzej Siewior
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Make the BUG() macro use the do-while loop and make the __BUG_FLAGS()
use the extra indirection. This shift makes it possible to use
__BUG_FLAGS() macro without having the unreachable() macro.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index b9e58be656360..963365b3158b9 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -19,9 +19,8 @@
#define BUG_ENCODING() .long ___asm_opcode_to_mem_arm(BUG_INSTR_VALUE)
#endif
-
-#define BUG() _BUG(__FILE__, __LINE__)
-#define _BUG(file, line) __BUG(file, line)
+#define __BUG_FLAGS(__file, __line, __flags) __BUG_FLAGS_(__file, __line, __flags)
+#define __BUG_FLAGS_(__file, __line, __flags) __BUG__LINE(__file, __line, __flags)
#ifdef CONFIG_DEBUG_BUGVERBOSE
#define _BUG_VERBOSE_LINE(__file, __line) \
@@ -60,9 +59,9 @@
* preferable to this unpleasantness. We use mergeable string sections to
* avoid multiple copies of the string appearing in the kernel image.
*/
-#define __BUG(__file, __line) \
+#define BUG() \
do { \
- asm volatile(__stringify(__BUG__LINE(__file, __line, 0))); \
+ asm volatile(__stringify(__BUG_FLAGS(__FILE__, __LINE__, 0))); \
unreachable(); \
} while (0)
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 09/11] ARM: traps: Move the BUG handling from die() to do_undefinstr()
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (7 preceding siblings ...)
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
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
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 10/11] ARM: traps: Add handling for warnings to handle_bug_opcode()
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (8 preceding siblings ...)
2026-10-09 22:21 ` [PATCH 09/11] ARM: traps: Move the BUG handling from die() to do_undefinstr() Sebastian Andrzej Siewior
@ 2026-10-09 22:21 ` Sebastian Andrzej Siewior
2026-10-09 22:21 ` [PATCH 11/11] ARM: BUG: Add WARN support via __WARN_FLAGS() Sebastian Andrzej Siewior
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
Should a WARNing be encoded with a BUG opcode then it is needed to
forwarded the PC so the CPU can continue after the invalid opcode.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/kernel/traps.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index 1353bf24da53f..12833307f9064 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -451,6 +451,14 @@ static int handle_bug_opcode(unsigned int instr, struct pt_regs *regs)
if (bug_type == BUG_TRAP_TYPE_NONE)
return 0;
+ if (bug_type == BUG_TRAP_TYPE_WARN) {
+ if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
+ regs->ARM_pc += 2;
+ else
+ regs->ARM_pc += 4;
+ return 1;
+ }
+
flags = oops_begin();
if (__die("Oops - BUG", 0, regs))
sig = 0;
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 11/11] ARM: BUG: Add WARN support via __WARN_FLAGS()
2026-10-09 22:21 [PATCH 00/11] ARM: Use invalid opcode also for warnings Sebastian Andrzej Siewior
` (9 preceding siblings ...)
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 ` Sebastian Andrzej Siewior
10 siblings, 0 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-09 22:21 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sebastian Andrzej Siewior, Russell King, Arnd Bergmann
the recent rework makes it possible to add support for WARN_ON() and
friends by defining __WARN_FLAGS(). The __BUG_FLAGS() macro needs to
pass BUGFLAG_WARNING as option to distinguish it from BUG() entries.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
arch/arm/include/asm/bug.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h
index 963365b3158b9..f9c093bac432f 100644
--- a/arch/arm/include/asm/bug.h
+++ b/arch/arm/include/asm/bug.h
@@ -65,6 +65,9 @@ do { \
unreachable(); \
} while (0)
+#define __WARN_FLAGS(cond_str, flags) \
+ asm volatile(__stringify(__BUG_FLAGS(__FILE__, __LINE__, BUGFLAG_WARNING|(flags))))
+
#define HAVE_ARCH_BUG
#include <asm-generic/bug.h>
--
2.55.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-10-09 22:22 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 09/11] ARM: traps: Move the BUG handling from die() to do_undefinstr() Sebastian Andrzej Siewior
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox