bug.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_BUG_H
  3. #define _ASM_X86_BUG_H
  4. #include <linux/stringify.h>
  5. #include <linux/instrumentation.h>
  6. #include <linux/objtool.h>
  7. /*
  8. * Despite that some emulators terminate on UD2, we use it for WARN().
  9. */
  10. #define ASM_UD2 ".byte 0x0f, 0x0b"
  11. #define INSN_UD2 0x0b0f
  12. #define LEN_UD2 2
  13. #ifdef CONFIG_GENERIC_BUG
  14. #ifdef CONFIG_X86_32
  15. # define __BUG_REL(val) ".long " __stringify(val)
  16. #else
  17. # define __BUG_REL(val) ".long " __stringify(val) " - ."
  18. #endif
  19. #ifdef CONFIG_DEBUG_BUGVERBOSE
  20. #define _BUG_FLAGS(ins, flags, extra) \
  21. do { \
  22. asm_inline volatile("1:\t" ins "\n" \
  23. ".pushsection __bug_table,\"aw\"\n" \
  24. "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
  25. "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
  26. "\t.word %c1" "\t# bug_entry::line\n" \
  27. "\t.word %c2" "\t# bug_entry::flags\n" \
  28. "\t.org 2b+%c3\n" \
  29. ".popsection\n" \
  30. extra \
  31. : : "i" (__FILE__), "i" (__LINE__), \
  32. "i" (flags), \
  33. "i" (sizeof(struct bug_entry))); \
  34. } while (0)
  35. #else /* !CONFIG_DEBUG_BUGVERBOSE */
  36. #define _BUG_FLAGS(ins, flags, extra) \
  37. do { \
  38. asm_inline volatile("1:\t" ins "\n" \
  39. ".pushsection __bug_table,\"aw\"\n" \
  40. "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
  41. "\t.word %c0" "\t# bug_entry::flags\n" \
  42. "\t.org 2b+%c1\n" \
  43. ".popsection\n" \
  44. extra \
  45. : : "i" (flags), \
  46. "i" (sizeof(struct bug_entry))); \
  47. } while (0)
  48. #endif /* CONFIG_DEBUG_BUGVERBOSE */
  49. #else
  50. #define _BUG_FLAGS(ins, flags, extra) asm volatile(ins)
  51. #endif /* CONFIG_GENERIC_BUG */
  52. #define HAVE_ARCH_BUG
  53. #define BUG() \
  54. do { \
  55. instrumentation_begin(); \
  56. _BUG_FLAGS(ASM_UD2, 0, ""); \
  57. __builtin_unreachable(); \
  58. } while (0)
  59. /*
  60. * This instrumentation_begin() is strictly speaking incorrect; but it
  61. * suppresses the complaints from WARN()s in noinstr code. If such a WARN()
  62. * were to trigger, we'd rather wreck the machine in an attempt to get the
  63. * message out than not know about it.
  64. */
  65. #define __WARN_FLAGS(flags) \
  66. do { \
  67. __auto_type __flags = BUGFLAG_WARNING|(flags); \
  68. instrumentation_begin(); \
  69. _BUG_FLAGS(ASM_UD2, __flags, ASM_REACHABLE); \
  70. instrumentation_end(); \
  71. } while (0)
  72. #include <asm-generic/bug.h>
  73. #endif /* _ASM_X86_BUG_H */