jump_label.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_S390_JUMP_LABEL_H
  3. #define _ASM_S390_JUMP_LABEL_H
  4. #ifndef __ASSEMBLY__
  5. #include <linux/types.h>
  6. #include <linux/stringify.h>
  7. #define JUMP_LABEL_NOP_SIZE 6
  8. #define JUMP_LABEL_NOP_OFFSET 2
  9. #if __GNUC__ < 9
  10. #define JUMP_LABEL_STATIC_KEY_CONSTRAINT "X"
  11. #else
  12. #define JUMP_LABEL_STATIC_KEY_CONSTRAINT "jdd"
  13. #endif
  14. /*
  15. * We use a brcl 0,2 instruction for jump labels at compile time so it
  16. * can be easily distinguished from a hotpatch generated instruction.
  17. */
  18. static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  19. {
  20. asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n"
  21. ".pushsection __jump_table, \"aw\"\n"
  22. ".balign 8\n"
  23. ".quad 0b, %l[label], %0+%1\n"
  24. ".popsection\n"
  25. : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
  26. return false;
  27. label:
  28. return true;
  29. }
  30. static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
  31. {
  32. asm_volatile_goto("0: brcl 15, %l[label]\n"
  33. ".pushsection __jump_table, \"aw\"\n"
  34. ".balign 8\n"
  35. ".quad 0b, %l[label], %0+%1\n"
  36. ".popsection\n"
  37. : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
  38. return false;
  39. label:
  40. return true;
  41. }
  42. typedef unsigned long jump_label_t;
  43. struct jump_entry {
  44. jump_label_t code;
  45. jump_label_t target;
  46. jump_label_t key;
  47. };
  48. #endif /* __ASSEMBLY__ */
  49. #endif