jump_label.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2013 Huawei Ltd.
  3. * Author: Jiang Liu <liuj97@gmail.com>
  4. *
  5. * Based on arch/arm/include/asm/jump_label.h
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_JUMP_LABEL_H
  20. #define __ASM_JUMP_LABEL_H
  21. #ifndef __ASSEMBLY__
  22. #include <linux/types.h>
  23. #include <asm/insn.h>
  24. #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE
  25. static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  26. {
  27. asm_volatile_goto("1: nop\n\t"
  28. ".pushsection __jump_table, \"aw\"\n\t"
  29. ".align 3\n\t"
  30. ".quad 1b, %l[l_yes], %c0\n\t"
  31. ".popsection\n\t"
  32. : : "i"(&((char *)key)[branch]) : : l_yes);
  33. return false;
  34. l_yes:
  35. return true;
  36. }
  37. static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
  38. {
  39. asm_volatile_goto("1: b %l[l_yes]\n\t"
  40. ".pushsection __jump_table, \"aw\"\n\t"
  41. ".align 3\n\t"
  42. ".quad 1b, %l[l_yes], %c0\n\t"
  43. ".popsection\n\t"
  44. : : "i"(&((char *)key)[branch]) : : l_yes);
  45. return false;
  46. l_yes:
  47. return true;
  48. }
  49. typedef u64 jump_label_t;
  50. struct jump_entry {
  51. jump_label_t code;
  52. jump_label_t target;
  53. jump_label_t key;
  54. };
  55. #endif /* __ASSEMBLY__ */
  56. #endif /* __ASM_JUMP_LABEL_H */