Skip to content

Commit 4a26e70

Browse files
committed
Merge tag 'core-bugs-2025-12-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull bug handling infrastructure updates from Ingo Molnar: "Core updates: - Improve WARN(), which has vararg printf like arguments, to work with the x86 #UD based WARN-optimizing infrastructure by hiding the format in the bug_table and replacing this first argument with the address of the bug-table entry, while making the actual function that's called a UD1 instruction (Peter Zijlstra) - Introduce the CONFIG_DEBUG_BUGVERBOSE_DETAILED Kconfig switch (Ingo Molnar, s390 support by Heiko Carstens) Fixes and cleanups: - bugs/s390: Remove private WARN_ON() implementation (Heiko Carstens) - <asm/bugs.h>: Make i386 use GENERIC_BUG_RELATIVE_POINTERS (Peter Zijlstra)" * tag 'core-bugs-2025-12-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (31 commits) x86/bugs: Make i386 use GENERIC_BUG_RELATIVE_POINTERS x86/bug: Fix BUG_FORMAT vs KASLR x86_64/bug: Inline the UD1 x86/bug: Implement WARN_ONCE() x86_64/bug: Implement __WARN_printf() x86/bug: Use BUG_FORMAT for DEBUG_BUGVERBOSE_DETAILED x86/bug: Add BUG_FORMAT basics bug: Allow architectures to provide __WARN_printf() bug: Implement WARN_ON() using __WARN_FLAGS() bug: Add report_bug_entry() bug: Add BUG_FORMAT_ARGS infrastructure bug: Clean up CONFIG_GENERIC_BUG_RELATIVE_POINTERS bug: Add BUG_FORMAT infrastructure x86: Rework __bug_table helpers bugs/s390: Remove private WARN_ON() implementation bugs/core: Reorganize fields in the first line of WARNING output, add ->comm[] output bugs/sh: Concatenate 'cond_str' with '__FILE__' in __WARN_FLAGS(), to extend WARN_ON/BUG_ON output bugs/parisc: Concatenate 'cond_str' with '__FILE__' in __WARN_FLAGS(), to extend WARN_ON/BUG_ON output bugs/riscv: Concatenate 'cond_str' with '__FILE__' in __BUG_FLAGS(), to extend WARN_ON/BUG_ON output bugs/riscv: Pass in 'cond_str' to __BUG_FLAGS() ...
2 parents dcd8637 + b0a848f commit 4a26e70

17 files changed

Lines changed: 477 additions & 178 deletions

File tree

arch/arm64/include/asm/bug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
unreachable(); \
2020
} while (0)
2121

22-
#define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
22+
#define __WARN_FLAGS(cond_str, flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
2323

2424
#define HAVE_ARCH_BUG
2525

arch/loongarch/include/asm/bug.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#else
1212
#define __BUGVERBOSE_LOCATION(file, line) \
1313
.pushsection .rodata.str, "aMS", @progbits, 1; \
14-
10002: .string file; \
14+
10002: .ascii file "\0"; \
1515
.popsection; \
1616
\
1717
.long 10002b - .; \
@@ -20,39 +20,38 @@
2020
#endif
2121

2222
#ifndef CONFIG_GENERIC_BUG
23-
#define __BUG_ENTRY(flags)
23+
#define __BUG_ENTRY(cond_str, flags)
2424
#else
25-
#define __BUG_ENTRY(flags) \
25+
#define __BUG_ENTRY(cond_str, flags) \
2626
.pushsection __bug_table, "aw"; \
2727
.align 2; \
2828
10000: .long 10001f - .; \
29-
_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \
30-
.short flags; \
29+
_BUGVERBOSE_LOCATION(WARN_CONDITION_STR(cond_str) __FILE__, __LINE__) \
30+
.short flags; \
3131
.popsection; \
3232
10001:
3333
#endif
3434

35-
#define ASM_BUG_FLAGS(flags) \
36-
__BUG_ENTRY(flags) \
35+
#define ASM_BUG_FLAGS(cond_str, flags) \
36+
__BUG_ENTRY(cond_str, flags) \
3737
break BRK_BUG;
3838

39-
#define ASM_BUG() ASM_BUG_FLAGS(0)
39+
#define ASM_BUG() ASM_BUG_FLAGS("", 0)
4040

41-
#define __BUG_FLAGS(flags, extra) \
42-
asm_inline volatile (__stringify(ASM_BUG_FLAGS(flags)) \
43-
extra);
41+
#define __BUG_FLAGS(cond_str, flags, extra) \
42+
asm_inline volatile (__stringify(ASM_BUG_FLAGS(cond_str, flags)) extra);
4443

45-
#define __WARN_FLAGS(flags) \
44+
#define __WARN_FLAGS(cond_str, flags) \
4645
do { \
4746
instrumentation_begin(); \
48-
__BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE(10001b));\
47+
__BUG_FLAGS(cond_str, BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE(10001b));\
4948
instrumentation_end(); \
5049
} while (0)
5150

5251
#define BUG() \
5352
do { \
5453
instrumentation_begin(); \
55-
__BUG_FLAGS(0, ""); \
54+
__BUG_FLAGS("", 0, ""); \
5655
unreachable(); \
5756
} while (0)
5857

arch/parisc/include/asm/bug.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#endif
5151

5252
#ifdef CONFIG_DEBUG_BUGVERBOSE
53-
#define __WARN_FLAGS(flags) \
53+
#define __WARN_FLAGS(cond_str, flags) \
5454
do { \
5555
asm volatile("\n" \
5656
"1:\t" PARISC_BUG_BREAK_ASM "\n" \
@@ -61,12 +61,12 @@
6161
"\t.short %1, %2\n" \
6262
"\t.blockz %3-2*4-2*2\n" \
6363
"\t.popsection" \
64-
: : "i" (__FILE__), "i" (__LINE__), \
64+
: : "i" (WARN_CONDITION_STR(cond_str) __FILE__), "i" (__LINE__), \
6565
"i" (BUGFLAG_WARNING|(flags)), \
6666
"i" (sizeof(struct bug_entry)) ); \
6767
} while(0)
6868
#else
69-
#define __WARN_FLAGS(flags) \
69+
#define __WARN_FLAGS(cond_str, flags) \
7070
do { \
7171
asm volatile("\n" \
7272
"1:\t" PARISC_BUG_BREAK_ASM "\n" \

arch/powerpc/include/asm/bug.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151
".previous\n"
5252
#endif
5353

54-
#define BUG_ENTRY(insn, flags, ...) \
54+
#define BUG_ENTRY(cond_str, insn, flags, ...) \
5555
__asm__ __volatile__( \
5656
"1: " insn "\n" \
5757
_EMIT_BUG_ENTRY \
58-
: : "i" (__FILE__), "i" (__LINE__), \
58+
: : "i" (WARN_CONDITION_STR(cond_str) __FILE__), "i" (__LINE__), \
5959
"i" (flags), \
6060
"i" (sizeof(struct bug_entry)), \
6161
##__VA_ARGS__)
@@ -67,20 +67,20 @@
6767
*/
6868

6969
#define BUG() do { \
70-
BUG_ENTRY("twi 31, 0, 0", 0); \
70+
BUG_ENTRY("", "twi 31, 0, 0", 0); \
7171
unreachable(); \
7272
} while (0)
7373
#define HAVE_ARCH_BUG
7474

75-
#define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags))
75+
#define __WARN_FLAGS(cond_str, flags) BUG_ENTRY(cond_str, "twi 31, 0, 0", BUGFLAG_WARNING | (flags))
7676

7777
#ifdef CONFIG_PPC64
7878
#define BUG_ON(x) do { \
7979
if (__builtin_constant_p(x)) { \
8080
if (x) \
8181
BUG(); \
8282
} else { \
83-
BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
83+
BUG_ENTRY(#x, PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
8484
} \
8585
} while (0)
8686

@@ -90,7 +90,7 @@
9090
if (__ret_warn_on) \
9191
__WARN(); \
9292
} else { \
93-
BUG_ENTRY(PPC_TLNEI " %4, 0", \
93+
BUG_ENTRY(#x, PPC_TLNEI " %4, 0", \
9494
BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \
9595
"r" (__ret_warn_on)); \
9696
} \

arch/riscv/include/asm/bug.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,28 @@ typedef u32 bug_insn_t;
6060
".org 2b + " size "\n\t" \
6161
".popsection" \
6262

63-
#define __BUG_FLAGS(flags) \
63+
#define __BUG_FLAGS(cond_str, flags) \
6464
do { \
6565
__asm__ __volatile__ ( \
6666
ARCH_WARN_ASM("%0", "%1", "%2", "%3") \
6767
: \
68-
: "i" (__FILE__), "i" (__LINE__), \
68+
: "i" (WARN_CONDITION_STR(cond_str) __FILE__), "i" (__LINE__), \
6969
"i" (flags), \
7070
"i" (sizeof(struct bug_entry))); \
7171
} while (0)
7272

7373
#else /* CONFIG_GENERIC_BUG */
74-
#define __BUG_FLAGS(flags) do { \
74+
#define __BUG_FLAGS(cond_str, flags) do { \
7575
__asm__ __volatile__ ("ebreak\n"); \
7676
} while (0)
7777
#endif /* CONFIG_GENERIC_BUG */
7878

7979
#define BUG() do { \
80-
__BUG_FLAGS(0); \
80+
__BUG_FLAGS("", 0); \
8181
unreachable(); \
8282
} while (0)
8383

84-
#define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
84+
#define __WARN_FLAGS(cond_str, flags) __BUG_FLAGS(cond_str, BUGFLAG_WARNING|(flags))
8585

8686
#define ARCH_WARN_REACHABLE
8787

arch/s390/include/asm/bug.h

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,55 @@
22
#ifndef _ASM_S390_BUG_H
33
#define _ASM_S390_BUG_H
44

5-
#include <linux/compiler.h>
6-
7-
#ifdef CONFIG_BUG
8-
9-
#ifdef CONFIG_DEBUG_BUGVERBOSE
10-
11-
#define __EMIT_BUG(x) do { \
12-
asm_inline volatile( \
13-
"0: mc 0,0\n" \
14-
".section .rodata.str,\"aMS\",@progbits,1\n" \
15-
"1: .asciz \""__FILE__"\"\n" \
16-
".previous\n" \
17-
".section __bug_table,\"aw\"\n" \
18-
"2: .long 0b-.\n" \
19-
" .long 1b-.\n" \
20-
" .short %0,%1\n" \
21-
" .org 2b+%2\n" \
22-
".previous\n" \
23-
: : "i" (__LINE__), \
24-
"i" (x), \
25-
"i" (sizeof(struct bug_entry))); \
26-
} while (0)
27-
28-
#else /* CONFIG_DEBUG_BUGVERBOSE */
29-
30-
#define __EMIT_BUG(x) do { \
31-
asm_inline volatile( \
32-
"0: mc 0,0\n" \
33-
".section __bug_table,\"aw\"\n" \
34-
"1: .long 0b-.\n" \
35-
" .short %0\n" \
36-
" .org 1b+%1\n" \
37-
".previous\n" \
38-
: : "i" (x), \
39-
"i" (sizeof(struct bug_entry))); \
5+
#include <linux/stringify.h>
6+
7+
#ifndef CONFIG_DEBUG_BUGVERBOSE
8+
#define _BUGVERBOSE_LOCATION(file, line)
9+
#else
10+
#define __BUGVERBOSE_LOCATION(file, line) \
11+
.pushsection .rodata.str, "aMS", @progbits, 1; \
12+
10002: .ascii file "\0"; \
13+
.popsection; \
14+
\
15+
.long 10002b - .; \
16+
.short line;
17+
#define _BUGVERBOSE_LOCATION(file, line) __BUGVERBOSE_LOCATION(file, line)
18+
#endif
19+
20+
#ifndef CONFIG_GENERIC_BUG
21+
#define __BUG_ENTRY(cond_str, flags)
22+
#else
23+
#define __BUG_ENTRY(cond_str, flags) \
24+
.pushsection __bug_table, "aw"; \
25+
.align 4; \
26+
10000: .long 10001f - .; \
27+
_BUGVERBOSE_LOCATION(WARN_CONDITION_STR(cond_str) __FILE__, __LINE__) \
28+
.short flags; \
29+
.popsection; \
30+
10001:
31+
#endif
32+
33+
#define ASM_BUG_FLAGS(cond_str, flags) \
34+
__BUG_ENTRY(cond_str, flags) \
35+
mc 0,0
36+
37+
#define ASM_BUG() ASM_BUG_FLAGS("", 0)
38+
39+
#define __BUG_FLAGS(cond_str, flags) \
40+
asm_inline volatile(__stringify(ASM_BUG_FLAGS(cond_str, flags)));
41+
42+
#define __WARN_FLAGS(cond_str, flags) \
43+
do { \
44+
__BUG_FLAGS(cond_str, BUGFLAG_WARNING|(flags)); \
4045
} while (0)
4146

42-
#endif /* CONFIG_DEBUG_BUGVERBOSE */
43-
44-
#define BUG() do { \
45-
__EMIT_BUG(0); \
46-
unreachable(); \
47+
#define BUG() \
48+
do { \
49+
__BUG_FLAGS("", 0); \
50+
unreachable(); \
4751
} while (0)
4852

49-
#define __WARN_FLAGS(flags) do { \
50-
__EMIT_BUG(BUGFLAG_WARNING|(flags)); \
51-
} while (0)
52-
53-
#define WARN_ON(x) ({ \
54-
int __ret_warn_on = !!(x); \
55-
if (__builtin_constant_p(__ret_warn_on)) { \
56-
if (__ret_warn_on) \
57-
__WARN(); \
58-
} else { \
59-
if (unlikely(__ret_warn_on)) \
60-
__WARN(); \
61-
} \
62-
unlikely(__ret_warn_on); \
63-
})
64-
6553
#define HAVE_ARCH_BUG
66-
#define HAVE_ARCH_WARN_ON
67-
#endif /* CONFIG_BUG */
6854

6955
#include <asm-generic/bug.h>
7056

arch/sh/include/asm/bug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ do { \
5252
unreachable(); \
5353
} while (0)
5454

55-
#define __WARN_FLAGS(flags) \
55+
#define __WARN_FLAGS(cond_str, flags) \
5656
do { \
5757
__asm__ __volatile__ ( \
5858
"1:\t.short %O0\n" \
5959
_EMIT_BUG_ENTRY \
6060
: \
6161
: "n" (TRAPA_BUG_OPCODE), \
62-
"i" (__FILE__), \
62+
"i" (WARN_CONDITION_STR(cond_str) __FILE__), \
6363
"i" (__LINE__), \
6464
"i" (BUGFLAG_WARNING|(flags)), \
6565
"i" (sizeof(struct bug_entry))); \

arch/x86/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ config GENERIC_CSUM
381381
config GENERIC_BUG
382382
def_bool y
383383
depends on BUG
384-
select GENERIC_BUG_RELATIVE_POINTERS if X86_64
384+
select GENERIC_BUG_RELATIVE_POINTERS
385385

386386
config GENERIC_BUG_RELATIVE_POINTERS
387387
bool

arch/x86/entry/entry.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ SYM_FUNC_END(write_ibpb)
3232
/* For KVM */
3333
EXPORT_SYMBOL_GPL(write_ibpb);
3434

35+
SYM_FUNC_START(__WARN_trap)
36+
ANNOTATE_NOENDBR
37+
ANNOTATE_REACHABLE
38+
ud1 (%edx), %_ASM_ARG1
39+
RET
40+
SYM_FUNC_END(__WARN_trap)
41+
EXPORT_SYMBOL(__WARN_trap)
42+
3543
.popsection
3644

3745
/*

0 commit comments

Comments
 (0)