jump_label.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _LINUX_JUMP_LABEL_H
  2. #define _LINUX_JUMP_LABEL_H
  3. #include <linux/types.h>
  4. #include <linux/compiler.h>
  5. #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
  6. struct jump_label_key {
  7. atomic_t enabled;
  8. struct jump_entry *entries;
  9. #ifdef CONFIG_MODULES
  10. struct jump_label_mod *next;
  11. #endif
  12. };
  13. # include <asm/jump_label.h>
  14. # define HAVE_JUMP_LABEL
  15. #endif
  16. enum jump_label_type {
  17. JUMP_LABEL_DISABLE = 0,
  18. JUMP_LABEL_ENABLE,
  19. };
  20. struct module;
  21. #ifdef HAVE_JUMP_LABEL
  22. #ifdef CONFIG_MODULES
  23. #define JUMP_LABEL_INIT {{ 0 }, NULL, NULL}
  24. #else
  25. #define JUMP_LABEL_INIT {{ 0 }, NULL}
  26. #endif
  27. static __always_inline bool static_branch(struct jump_label_key *key)
  28. {
  29. return arch_static_branch(key);
  30. }
  31. extern struct jump_entry __start___jump_table[];
  32. extern struct jump_entry __stop___jump_table[];
  33. extern void jump_label_lock(void);
  34. extern void jump_label_unlock(void);
  35. extern void arch_jump_label_transform(struct jump_entry *entry,
  36. enum jump_label_type type);
  37. extern void arch_jump_label_text_poke_early(jump_label_t addr);
  38. extern int jump_label_text_reserved(void *start, void *end);
  39. extern void jump_label_inc(struct jump_label_key *key);
  40. extern void jump_label_dec(struct jump_label_key *key);
  41. extern bool jump_label_enabled(struct jump_label_key *key);
  42. extern void jump_label_apply_nops(struct module *mod);
  43. #else
  44. #include <asm/atomic.h>
  45. #define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
  46. struct jump_label_key {
  47. atomic_t enabled;
  48. };
  49. static __always_inline bool static_branch(struct jump_label_key *key)
  50. {
  51. if (unlikely(atomic_read(&key->enabled)))
  52. return true;
  53. return false;
  54. }
  55. static inline void jump_label_inc(struct jump_label_key *key)
  56. {
  57. atomic_inc(&key->enabled);
  58. }
  59. static inline void jump_label_dec(struct jump_label_key *key)
  60. {
  61. atomic_dec(&key->enabled);
  62. }
  63. static inline int jump_label_text_reserved(void *start, void *end)
  64. {
  65. return 0;
  66. }
  67. static inline void jump_label_lock(void) {}
  68. static inline void jump_label_unlock(void) {}
  69. static inline bool jump_label_enabled(struct jump_label_key *key)
  70. {
  71. return !!atomic_read(&key->enabled);
  72. }
  73. static inline int jump_label_apply_nops(struct module *mod)
  74. {
  75. return 0;
  76. }
  77. #endif
  78. #endif