1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/stringify.h>
6 #include <linux/instrumentation.h>
9 * Despite that some emulators terminate on UD2, we use it for WARN().
11 #define ASM_UD2 ".byte 0x0f, 0x0b"
12 #define INSN_UD2 0x0b0f
15 #ifdef CONFIG_GENERIC_BUG
18 # define __BUG_REL(val) ".long " __stringify(val)
20 # define __BUG_REL(val) ".long " __stringify(val) " - 2b"
23 #ifdef CONFIG_DEBUG_BUGVERBOSE
25 #define _BUG_FLAGS(ins, flags) \
27 asm_inline volatile("1:\t" ins "\n" \
28 ".pushsection __bug_table,\"aw\"\n" \
29 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
30 "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
31 "\t.word %c1" "\t# bug_entry::line\n" \
32 "\t.word %c2" "\t# bug_entry::flags\n" \
35 : : "i" (__FILE__), "i" (__LINE__), \
37 "i" (sizeof(struct bug_entry))); \
40 #else /* !CONFIG_DEBUG_BUGVERBOSE */
42 #define _BUG_FLAGS(ins, flags) \
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.word %c0" "\t# bug_entry::flags\n" \
51 "i" (sizeof(struct bug_entry))); \
54 #endif /* CONFIG_DEBUG_BUGVERBOSE */
58 #define _BUG_FLAGS(ins, flags) asm volatile(ins)
60 #endif /* CONFIG_GENERIC_BUG */
65 instrumentation_begin(); \
66 _BUG_FLAGS(ASM_UD2, 0); \
71 * This instrumentation_begin() is strictly speaking incorrect; but it
72 * suppresses the complaints from WARN()s in noinstr code. If such a WARN()
73 * were to trigger, we'd rather wreck the machine in an attempt to get the
74 * message out than not know about it.
76 #define __WARN_FLAGS(flags) \
78 instrumentation_begin(); \
79 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
80 annotate_reachable(); \
81 instrumentation_end(); \
84 #include <asm-generic/bug.h>
86 #endif /* _ASM_X86_BUG_H */