Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust

Add new ARCH_WARN_ASM macro for BUG/WARN assembly code sharing with
Rust to avoid the duplication.

No functional changes.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Link: https://lore.kernel.org/r/20250502094537.231725-2-fujita.tomonori@gmail.com
[ Fixed typo in macro parameter name. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

FUJITA Tomonori and committed by
Miguel Ojeda
8c8efa93 07dad44a

+28 -28
+28 -28
arch/x86/include/asm/bug.h
··· 32 32 #ifdef CONFIG_GENERIC_BUG 33 33 34 34 #ifdef CONFIG_X86_32 35 - # define __BUG_REL(val) ".long " __stringify(val) 35 + # define __BUG_REL(val) ".long " val 36 36 #else 37 - # define __BUG_REL(val) ".long " __stringify(val) " - ." 37 + # define __BUG_REL(val) ".long " val " - ." 38 38 #endif 39 39 40 40 #ifdef CONFIG_DEBUG_BUGVERBOSE 41 + #define __BUG_ENTRY(file, line, flags) \ 42 + "2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ 43 + "\t" __BUG_REL(file) "\t# bug_entry::file\n" \ 44 + "\t.word " line "\t# bug_entry::line\n" \ 45 + "\t.word " flags "\t# bug_entry::flags\n" 46 + #else 47 + #define __BUG_ENTRY(file, line, flags) \ 48 + "2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ 49 + "\t.word " flags "\t# bug_entry::flags\n" 50 + #endif 51 + 52 + #define _BUG_FLAGS_ASM(ins, file, line, flags, size, extra) \ 53 + "1:\t" ins "\n" \ 54 + ".pushsection __bug_table,\"aw\"\n" \ 55 + __BUG_ENTRY(file, line, flags) \ 56 + "\t.org 2b + " size "\n" \ 57 + ".popsection\n" \ 58 + extra 41 59 42 60 #define _BUG_FLAGS(ins, flags, extra) \ 43 61 do { \ 44 - asm_inline volatile("1:\t" ins "\n" \ 45 - ".pushsection __bug_table,\"aw\"\n" \ 46 - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ 47 - "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ 48 - "\t.word %c1" "\t# bug_entry::line\n" \ 49 - "\t.word %c2" "\t# bug_entry::flags\n" \ 50 - "\t.org 2b+%c3\n" \ 51 - ".popsection\n" \ 52 - extra \ 62 + asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c0", \ 63 + "%c1", "%c2", "%c3", extra) \ 53 64 : : "i" (__FILE__), "i" (__LINE__), \ 54 65 "i" (flags), \ 55 66 "i" (sizeof(struct bug_entry))); \ 56 67 } while (0) 57 68 58 - #else /* !CONFIG_DEBUG_BUGVERBOSE */ 59 - 60 - #define _BUG_FLAGS(ins, flags, extra) \ 61 - do { \ 62 - asm_inline volatile("1:\t" ins "\n" \ 63 - ".pushsection __bug_table,\"aw\"\n" \ 64 - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ 65 - "\t.word %c0" "\t# bug_entry::flags\n" \ 66 - "\t.org 2b+%c1\n" \ 67 - ".popsection\n" \ 68 - extra \ 69 - : : "i" (flags), \ 70 - "i" (sizeof(struct bug_entry))); \ 71 - } while (0) 72 - 73 - #endif /* CONFIG_DEBUG_BUGVERBOSE */ 69 + #define ARCH_WARN_ASM(file, line, flags, size) \ 70 + _BUG_FLAGS_ASM(ASM_UD2, file, line, flags, size, "") 74 71 75 72 #else 76 73 ··· 89 92 * were to trigger, we'd rather wreck the machine in an attempt to get the 90 93 * message out than not know about it. 91 94 */ 95 + 96 + #define ARCH_WARN_REACHABLE ANNOTATE_REACHABLE(1b) 97 + 92 98 #define __WARN_FLAGS(flags) \ 93 99 do { \ 94 100 __auto_type __flags = BUGFLAG_WARNING|(flags); \ 95 101 instrumentation_begin(); \ 96 - _BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE(1b)); \ 102 + _BUG_FLAGS(ASM_UD2, __flags, ARCH_WARN_REACHABLE); \ 97 103 instrumentation_end(); \ 98 104 } while (0) 99 105