blob: 84b87538a15de6e863ed7f9a8e17caf5d5233b05 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_BUG_H
3#define _ASM_X86_BUG_H
Thomas Gleixner68fdc552007-10-17 17:19:30 +02004
Peter Zijlstra9a938482017-02-02 14:43:51 +01005#include <linux/stringify.h>
Ingo Molnard19e7892020-07-24 13:50:25 +02006#include <linux/instrumentation.h>
Peter Zijlstra9a938482017-02-02 14:43:51 +01007
8/*
Peter Zijlstra3b3a3712018-02-09 13:16:59 +01009 * Despite that some emulators terminate on UD2, we use it for WARN().
Peter Zijlstra9a938482017-02-02 14:43:51 +010010 */
Peter Zijlstra9a938482017-02-02 14:43:51 +010011#define ASM_UD2 ".byte 0x0f, 0x0b"
Peter Zijlstra9a938482017-02-02 14:43:51 +010012#define INSN_UD2 0x0b0f
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010013#define LEN_UD2 2
Peter Zijlstra9a938482017-02-02 14:43:51 +010014
Ingo Molnarffb61c62018-12-19 11:20:50 +010015#ifdef CONFIG_GENERIC_BUG
16
17#ifdef CONFIG_X86_32
18# define __BUG_REL(val) ".long " __stringify(val)
19#else
20# define __BUG_REL(val) ".long " __stringify(val) " - 2b"
21#endif
22
23#ifdef CONFIG_DEBUG_BUGVERBOSE
24
Peter Zijlstra9a938482017-02-02 14:43:51 +010025#define _BUG_FLAGS(ins, flags) \
26do { \
Rasmus Villemoes32ee8232019-09-13 00:19:27 +020027 asm_inline volatile("1:\t" ins "\n" \
Ingo Molnarffb61c62018-12-19 11:20:50 +010028 ".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" \
33 "\t.org 2b+%c3\n" \
34 ".popsection" \
35 : : "i" (__FILE__), "i" (__LINE__), \
36 "i" (flags), \
Peter Zijlstra9a938482017-02-02 14:43:51 +010037 "i" (sizeof(struct bug_entry))); \
38} while (0)
39
Ingo Molnarffb61c62018-12-19 11:20:50 +010040#else /* !CONFIG_DEBUG_BUGVERBOSE */
41
42#define _BUG_FLAGS(ins, flags) \
43do { \
Rasmus Villemoes32ee8232019-09-13 00:19:27 +020044 asm_inline volatile("1:\t" ins "\n" \
Ingo Molnarffb61c62018-12-19 11:20:50 +010045 ".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" \
48 "\t.org 2b+%c1\n" \
49 ".popsection" \
50 : : "i" (flags), \
51 "i" (sizeof(struct bug_entry))); \
52} while (0)
53
54#endif /* CONFIG_DEBUG_BUGVERBOSE */
55
56#else
57
58#define _BUG_FLAGS(ins, flags) asm volatile(ins)
59
60#endif /* CONFIG_GENERIC_BUG */
61
Arnd Bergmann70579a82017-03-29 23:16:31 +020062#define HAVE_ARCH_BUG
Joe Perches86d8a082008-03-23 01:01:46 -070063#define BUG() \
64do { \
Thomas Gleixner5916d5f2020-03-13 13:49:51 +010065 instrumentation_begin(); \
Peter Zijlstra9a938482017-02-02 14:43:51 +010066 _BUG_FLAGS(ASM_UD2, 0); \
David Daneya5fc5eb2009-12-04 17:44:51 -080067 unreachable(); \
Joe Perches86d8a082008-03-23 01:01:46 -070068} while (0)
Thomas Gleixner68fdc552007-10-17 17:19:30 +020069
Peter Zijlstra8e8bb062020-06-04 11:17:40 +020070/*
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.
75 */
Josh Poimboeuf2b5db662018-02-08 17:09:26 -060076#define __WARN_FLAGS(flags) \
77do { \
Thomas Gleixner5916d5f2020-03-13 13:49:51 +010078 instrumentation_begin(); \
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010079 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
Josh Poimboeuf2b5db662018-02-08 17:09:26 -060080 annotate_reachable(); \
Thomas Gleixner5916d5f2020-03-13 13:49:51 +010081 instrumentation_end(); \
Josh Poimboeuf2b5db662018-02-08 17:09:26 -060082} while (0)
Peter Zijlstra9a938482017-02-02 14:43:51 +010083
Thomas Gleixner68fdc552007-10-17 17:19:30 +020084#include <asm-generic/bug.h>
David Howellsf05e7982012-03-28 18:11:12 +010085
H. Peter Anvin1965aae2008-10-22 22:26:29 -070086#endif /* _ASM_X86_BUG_H */