Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_BUG_H |
| 3 | #define _ASM_X86_BUG_H |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 4 | |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 5 | #include <linux/stringify.h> |
Ingo Molnar | d19e789 | 2020-07-24 13:50:25 +0200 | [diff] [blame] | 6 | #include <linux/instrumentation.h> |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 7 | |
| 8 | /* |
Peter Zijlstra | 3b3a371 | 2018-02-09 13:16:59 +0100 | [diff] [blame] | 9 | * Despite that some emulators terminate on UD2, we use it for WARN(). |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 10 | */ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 11 | #define ASM_UD2 ".byte 0x0f, 0x0b" |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 12 | #define INSN_UD2 0x0b0f |
Peter Zijlstra | 3b3a371 | 2018-02-09 13:16:59 +0100 | [diff] [blame] | 13 | #define LEN_UD2 2 |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 14 | |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 15 | #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 | |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 25 | #define _BUG_FLAGS(ins, flags, extra) \ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 26 | do { \ |
Rasmus Villemoes | 32ee823 | 2019-09-13 00:19:27 +0200 | [diff] [blame] | 27 | asm_inline volatile("1:\t" ins "\n" \ |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 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" \ |
| 33 | "\t.org 2b+%c3\n" \ |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 34 | ".popsection\n" \ |
| 35 | extra \ |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 36 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 37 | "i" (flags), \ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 38 | "i" (sizeof(struct bug_entry))); \ |
| 39 | } while (0) |
| 40 | |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 41 | #else /* !CONFIG_DEBUG_BUGVERBOSE */ |
| 42 | |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 43 | #define _BUG_FLAGS(ins, flags, extra) \ |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 44 | do { \ |
Rasmus Villemoes | 32ee823 | 2019-09-13 00:19:27 +0200 | [diff] [blame] | 45 | asm_inline volatile("1:\t" ins "\n" \ |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 46 | ".pushsection __bug_table,\"aw\"\n" \ |
| 47 | "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ |
| 48 | "\t.word %c0" "\t# bug_entry::flags\n" \ |
| 49 | "\t.org 2b+%c1\n" \ |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 50 | ".popsection\n" \ |
| 51 | extra \ |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 52 | : : "i" (flags), \ |
| 53 | "i" (sizeof(struct bug_entry))); \ |
| 54 | } while (0) |
| 55 | |
| 56 | #endif /* CONFIG_DEBUG_BUGVERBOSE */ |
| 57 | |
| 58 | #else |
| 59 | |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 60 | #define _BUG_FLAGS(ins, flags, extra) asm volatile(ins) |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 61 | |
| 62 | #endif /* CONFIG_GENERIC_BUG */ |
| 63 | |
Arnd Bergmann | 70579a8 | 2017-03-29 23:16:31 +0200 | [diff] [blame] | 64 | #define HAVE_ARCH_BUG |
Joe Perches | 86d8a08 | 2008-03-23 01:01:46 -0700 | [diff] [blame] | 65 | #define BUG() \ |
| 66 | do { \ |
Thomas Gleixner | 5916d5f | 2020-03-13 13:49:51 +0100 | [diff] [blame] | 67 | instrumentation_begin(); \ |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 68 | _BUG_FLAGS(ASM_UD2, 0, ""); \ |
| 69 | __builtin_unreachable(); \ |
Joe Perches | 86d8a08 | 2008-03-23 01:01:46 -0700 | [diff] [blame] | 70 | } while (0) |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 71 | |
Peter Zijlstra | 8e8bb06 | 2020-06-04 11:17:40 +0200 | [diff] [blame] | 72 | /* |
| 73 | * This instrumentation_begin() is strictly speaking incorrect; but it |
| 74 | * suppresses the complaints from WARN()s in noinstr code. If such a WARN() |
| 75 | * were to trigger, we'd rather wreck the machine in an attempt to get the |
| 76 | * message out than not know about it. |
| 77 | */ |
Josh Poimboeuf | 2b5db66 | 2018-02-08 17:09:26 -0600 | [diff] [blame] | 78 | #define __WARN_FLAGS(flags) \ |
| 79 | do { \ |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 80 | __auto_type f = BUGFLAG_WARNING|(flags); \ |
Thomas Gleixner | 5916d5f | 2020-03-13 13:49:51 +0100 | [diff] [blame] | 81 | instrumentation_begin(); \ |
Nick Desaulniers | bfb1a7c | 2022-02-02 12:55:53 -0800 | [diff] [blame] | 82 | _BUG_FLAGS(ASM_UD2, f, ASM_REACHABLE); \ |
Thomas Gleixner | 5916d5f | 2020-03-13 13:49:51 +0100 | [diff] [blame] | 83 | instrumentation_end(); \ |
Josh Poimboeuf | 2b5db66 | 2018-02-08 17:09:26 -0600 | [diff] [blame] | 84 | } while (0) |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 85 | |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 86 | #include <asm-generic/bug.h> |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 87 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 88 | #endif /* _ASM_X86_BUG_H */ |