jump_label.h 870 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef _ASM_X86_JUMP_LABEL_H
  2. #define _ASM_X86_JUMP_LABEL_H
  3. #ifdef __KERNEL__
  4. #include <linux/stringify.h>
  5. #include <linux/types.h>
  6. #include <asm/nops.h>
  7. #include <asm/asm.h>
  8. #define JUMP_LABEL_NOP_SIZE 5
  9. #ifdef CONFIG_X86_64
  10. # define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC
  11. #else
  12. # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
  13. #endif
  14. static __always_inline bool arch_static_branch(struct static_key *key)
  15. {
  16. asm goto("1:"
  17. ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
  18. ".pushsection __jump_table, \"aw\" \n\t"
  19. _ASM_ALIGN "\n\t"
  20. _ASM_PTR "1b, %l[l_yes], %c0 \n\t"
  21. ".popsection \n\t"
  22. : : "i" (key) : : l_yes);
  23. return false;
  24. l_yes:
  25. return true;
  26. }
  27. #endif /* __KERNEL__ */
  28. #ifdef CONFIG_X86_64
  29. typedef u64 jump_label_t;
  30. #else
  31. typedef u32 jump_label_t;
  32. #endif
  33. struct jump_entry {
  34. jump_label_t code;
  35. jump_label_t target;
  36. jump_label_t key;
  37. };
  38. #endif