jump_label.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 {ATOMIC_INIT(0), NULL, NULL}
  24. #else
  25. #define JUMP_LABEL_INIT {ATOMIC_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 int jump_label_text_reserved(void *start, void *end);
  38. extern void jump_label_inc(struct jump_label_key *key);
  39. extern void jump_label_dec(struct jump_label_key *key);
  40. extern bool jump_label_enabled(struct jump_label_key *key);
  41. extern void jump_label_apply_nops(struct module *mod);
  42. #else
  43. #include <linux/atomic.h>
  44. #define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
  45. struct jump_label_key {
  46. atomic_t enabled;
  47. };
  48. static __always_inline bool static_branch(struct jump_label_key *key)
  49. {
  50. if (unlikely(atomic_read(&key->enabled)))
  51. return true;
  52. return false;
  53. }
  54. static inline void jump_label_inc(struct jump_label_key *key)
  55. {
  56. atomic_inc(&key->enabled);
  57. }
  58. static inline void jump_label_dec(struct jump_label_key *key)
  59. {
  60. atomic_dec(&key->enabled);
  61. }
  62. static inline int jump_label_text_reserved(void *start, void *end)
  63. {
  64. return 0;
  65. }
  66. static inline void jump_label_lock(void) {}
  67. static inline void jump_label_unlock(void) {}
  68. static inline bool jump_label_enabled(struct jump_label_key *key)
  69. {
  70. return !!atomic_read(&key->enabled);
  71. }
  72. static inline int jump_label_apply_nops(struct module *mod)
  73. {
  74. return 0;
  75. }
  76. #endif
  77. #endif