jump_label.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2018 Cadence Design Systems Inc. */
  3. #ifndef _ASM_XTENSA_JUMP_LABEL_H
  4. #define _ASM_XTENSA_JUMP_LABEL_H
  5. #ifndef __ASSEMBLY__
  6. #include <linux/types.h>
  7. #define JUMP_LABEL_NOP_SIZE 3
  8. static __always_inline bool arch_static_branch(struct static_key *key,
  9. bool branch)
  10. {
  11. asm_volatile_goto("1:\n\t"
  12. "_nop\n\t"
  13. ".pushsection __jump_table, \"aw\"\n\t"
  14. ".word 1b, %l[l_yes], %c0\n\t"
  15. ".popsection\n\t"
  16. : : "i" (&((char *)key)[branch]) : : l_yes);
  17. return false;
  18. l_yes:
  19. return true;
  20. }
  21. static __always_inline bool arch_static_branch_jump(struct static_key *key,
  22. bool branch)
  23. {
  24. /*
  25. * Xtensa assembler will mark certain points in the code
  26. * as unreachable, so that later assembler or linker relaxation
  27. * passes could use them. A spot right after the J instruction
  28. * is one such point. Assembler and/or linker may insert padding
  29. * or literals here, breaking code flow in case the J instruction
  30. * is later replaced with NOP. Put a label right after the J to
  31. * make it reachable and wrap both into a no-transform block
  32. * to avoid any assembler interference with this.
  33. */
  34. asm_volatile_goto("1:\n\t"
  35. ".begin no-transform\n\t"
  36. "_j %l[l_yes]\n\t"
  37. "2:\n\t"
  38. ".end no-transform\n\t"
  39. ".pushsection __jump_table, \"aw\"\n\t"
  40. ".word 1b, %l[l_yes], %c0\n\t"
  41. ".popsection\n\t"
  42. : : "i" (&((char *)key)[branch]) : : l_yes);
  43. return false;
  44. l_yes:
  45. return true;
  46. }
  47. typedef u32 jump_label_t;
  48. struct jump_entry {
  49. jump_label_t code;
  50. jump_label_t target;
  51. jump_label_t key;
  52. };
  53. #endif /* __ASSEMBLY__ */
  54. #endif