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> |
| 6 | |
| 7 | /* |
Peter Zijlstra | 3b3a371 | 2018-02-09 13:16:59 +0100 | [diff] [blame] | 8 | * Despite that some emulators terminate on UD2, we use it for WARN(). |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 9 | * |
Peter Zijlstra | 3b3a371 | 2018-02-09 13:16:59 +0100 | [diff] [blame] | 10 | * Since various instruction decoders/specs disagree on the encoding of |
| 11 | * UD0/UD1. |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
Peter Zijlstra | 3b3a371 | 2018-02-09 13:16:59 +0100 | [diff] [blame] | 14 | #define ASM_UD0 ".byte 0x0f, 0xff" /* + ModRM (for Intel) */ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 15 | #define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */ |
| 16 | #define ASM_UD2 ".byte 0x0f, 0x0b" |
| 17 | |
| 18 | #define INSN_UD0 0xff0f |
| 19 | #define INSN_UD2 0x0b0f |
| 20 | |
Peter Zijlstra | 3b3a371 | 2018-02-09 13:16:59 +0100 | [diff] [blame] | 21 | #define LEN_UD2 2 |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 22 | |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 23 | #ifdef CONFIG_GENERIC_BUG |
| 24 | |
| 25 | #ifdef CONFIG_X86_32 |
| 26 | # define __BUG_REL(val) ".long " __stringify(val) |
| 27 | #else |
| 28 | # define __BUG_REL(val) ".long " __stringify(val) " - 2b" |
| 29 | #endif |
| 30 | |
| 31 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 32 | |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 33 | #define _BUG_FLAGS(ins, flags) \ |
| 34 | do { \ |
Rasmus Villemoes | 32ee823 | 2019-09-13 00:19:27 +0200 | [diff] [blame] | 35 | asm_inline volatile("1:\t" ins "\n" \ |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 36 | ".pushsection __bug_table,\"aw\"\n" \ |
| 37 | "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ |
| 38 | "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ |
| 39 | "\t.word %c1" "\t# bug_entry::line\n" \ |
| 40 | "\t.word %c2" "\t# bug_entry::flags\n" \ |
| 41 | "\t.org 2b+%c3\n" \ |
| 42 | ".popsection" \ |
| 43 | : : "i" (__FILE__), "i" (__LINE__), \ |
| 44 | "i" (flags), \ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 45 | "i" (sizeof(struct bug_entry))); \ |
| 46 | } while (0) |
| 47 | |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 48 | #else /* !CONFIG_DEBUG_BUGVERBOSE */ |
| 49 | |
| 50 | #define _BUG_FLAGS(ins, flags) \ |
| 51 | do { \ |
Rasmus Villemoes | 32ee823 | 2019-09-13 00:19:27 +0200 | [diff] [blame] | 52 | asm_inline volatile("1:\t" ins "\n" \ |
Ingo Molnar | ffb61c6 | 2018-12-19 11:20:50 +0100 | [diff] [blame] | 53 | ".pushsection __bug_table,\"aw\"\n" \ |
| 54 | "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ |
| 55 | "\t.word %c0" "\t# bug_entry::flags\n" \ |
| 56 | "\t.org 2b+%c1\n" \ |
| 57 | ".popsection" \ |
| 58 | : : "i" (flags), \ |
| 59 | "i" (sizeof(struct bug_entry))); \ |
| 60 | } while (0) |
| 61 | |
| 62 | #endif /* CONFIG_DEBUG_BUGVERBOSE */ |
| 63 | |
| 64 | #else |
| 65 | |
| 66 | #define _BUG_FLAGS(ins, flags) asm volatile(ins) |
| 67 | |
| 68 | #endif /* CONFIG_GENERIC_BUG */ |
| 69 | |
Arnd Bergmann | 70579a8 | 2017-03-29 23:16:31 +0200 | [diff] [blame] | 70 | #define HAVE_ARCH_BUG |
Joe Perches | 86d8a08 | 2008-03-23 01:01:46 -0700 | [diff] [blame] | 71 | #define BUG() \ |
| 72 | do { \ |
Thomas Gleixner | 5916d5f | 2020-03-13 13:49:51 +0100 | [diff] [blame^] | 73 | instrumentation_begin(); \ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 74 | _BUG_FLAGS(ASM_UD2, 0); \ |
David Daney | a5fc5eb | 2009-12-04 17:44:51 -0800 | [diff] [blame] | 75 | unreachable(); \ |
Joe Perches | 86d8a08 | 2008-03-23 01:01:46 -0700 | [diff] [blame] | 76 | } while (0) |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 77 | |
Josh Poimboeuf | 2b5db66 | 2018-02-08 17:09:26 -0600 | [diff] [blame] | 78 | #define __WARN_FLAGS(flags) \ |
| 79 | do { \ |
Thomas Gleixner | 5916d5f | 2020-03-13 13:49:51 +0100 | [diff] [blame^] | 80 | instrumentation_begin(); \ |
Peter Zijlstra | 3b3a371 | 2018-02-09 13:16:59 +0100 | [diff] [blame] | 81 | _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \ |
Josh Poimboeuf | 2b5db66 | 2018-02-08 17:09:26 -0600 | [diff] [blame] | 82 | annotate_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 */ |