jump_label.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_JUMP_LABEL_H
  3. #define _ASM_X86_JUMP_LABEL_H
  4. #define HAVE_JUMP_LABEL_BATCH
  5. #include <asm/asm.h>
  6. #include <asm/nops.h>
  7. #ifndef __ASSEMBLY__
  8. #include <linux/stringify.h>
  9. #include <linux/types.h>
  10. #define JUMP_TABLE_ENTRY \
  11. ".pushsection __jump_table, \"aw\" \n\t" \
  12. _ASM_ALIGN "\n\t" \
  13. ".long 1b - . \n\t" \
  14. ".long %l[l_yes] - . \n\t" \
  15. _ASM_PTR "%c0 + %c1 - .\n\t" \
  16. ".popsection \n\t"
  17. #ifdef CONFIG_HAVE_JUMP_LABEL_HACK
  18. static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  19. {
  20. asm_volatile_goto("1:"
  21. "jmp %l[l_yes] # objtool NOPs this \n\t"
  22. JUMP_TABLE_ENTRY
  23. : : "i" (key), "i" (2 | branch) : : l_yes);
  24. return false;
  25. l_yes:
  26. return true;
  27. }
  28. #else /* !CONFIG_HAVE_JUMP_LABEL_HACK */
  29. static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
  30. {
  31. asm_volatile_goto("1:"
  32. ".byte " __stringify(BYTES_NOP5) "\n\t"
  33. JUMP_TABLE_ENTRY
  34. : : "i" (key), "i" (branch) : : l_yes);
  35. return false;
  36. l_yes:
  37. return true;
  38. }
  39. #endif /* CONFIG_HAVE_JUMP_LABEL_HACK */
  40. static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
  41. {
  42. asm_volatile_goto("1:"
  43. "jmp %l[l_yes]\n\t"
  44. JUMP_TABLE_ENTRY
  45. : : "i" (key), "i" (branch) : : l_yes);
  46. return false;
  47. l_yes:
  48. return true;
  49. }
  50. extern int arch_jump_entry_size(struct jump_entry *entry);
  51. #endif /* __ASSEMBLY__ */
  52. #endif