rseq-s390.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2. /*
  3. * RSEQ_SIG uses the trap4 instruction. As Linux does not make use of the
  4. * access-register mode nor the linkage stack this instruction will always
  5. * cause a special-operation exception (the trap-enabled bit in the DUCT
  6. * is and will stay 0). The instruction pattern is
  7. * b2 ff 0f ff trap4 4095(%r0)
  8. */
  9. #define RSEQ_SIG 0xB2FF0FFF
  10. #define rseq_smp_mb() __asm__ __volatile__ ("bcr 15,0" ::: "memory")
  11. #define rseq_smp_rmb() rseq_smp_mb()
  12. #define rseq_smp_wmb() rseq_smp_mb()
  13. #define rseq_smp_load_acquire(p) \
  14. __extension__ ({ \
  15. rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
  16. rseq_barrier(); \
  17. ____p1; \
  18. })
  19. #define rseq_smp_acquire__after_ctrl_dep() rseq_smp_rmb()
  20. #define rseq_smp_store_release(p, v) \
  21. do { \
  22. rseq_barrier(); \
  23. RSEQ_WRITE_ONCE(*(p), v); \
  24. } while (0)
  25. #define LONG_L "lg"
  26. #define LONG_S "stg"
  27. #define LONG_LT_R "ltgr"
  28. #define LONG_CMP "cg"
  29. #define LONG_CMP_R "cgr"
  30. #define LONG_ADDI "aghi"
  31. #define LONG_ADD_R "agr"
  32. #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
  33. start_ip, post_commit_offset, abort_ip) \
  34. ".pushsection __rseq_cs, \"aw\"\n\t" \
  35. ".balign 32\n\t" \
  36. __rseq_str(label) ":\n\t" \
  37. ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
  38. ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \
  39. ".popsection\n\t" \
  40. ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
  41. ".quad " __rseq_str(label) "b\n\t" \
  42. ".popsection\n\t"
  43. /*
  44. * Exit points of a rseq critical section consist of all instructions outside
  45. * of the critical section where a critical section can either branch to or
  46. * reach through the normal course of its execution. The abort IP and the
  47. * post-commit IP are already part of the __rseq_cs section and should not be
  48. * explicitly defined as additional exit points. Knowing all exit points is
  49. * useful to assist debuggers stepping over the critical section.
  50. */
  51. #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
  52. ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
  53. ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \
  54. ".popsection\n\t"
  55. #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
  56. __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
  57. (post_commit_ip - start_ip), abort_ip)
  58. #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
  59. RSEQ_INJECT_ASM(1) \
  60. "larl %%r0, " __rseq_str(cs_label) "\n\t" \
  61. LONG_S " %%r0, %[" __rseq_str(rseq_cs) "]\n\t" \
  62. __rseq_str(label) ":\n\t"
  63. #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
  64. RSEQ_INJECT_ASM(2) \
  65. "c %[" __rseq_str(cpu_id) "], %[" __rseq_str(current_cpu_id) "]\n\t" \
  66. "jnz " __rseq_str(label) "\n\t"
  67. #define RSEQ_ASM_DEFINE_ABORT(label, teardown, abort_label) \
  68. ".pushsection __rseq_failure, \"ax\"\n\t" \
  69. ".long " __rseq_str(RSEQ_SIG) "\n\t" \
  70. __rseq_str(label) ":\n\t" \
  71. teardown \
  72. "jg %l[" __rseq_str(abort_label) "]\n\t" \
  73. ".popsection\n\t"
  74. #define RSEQ_ASM_DEFINE_CMPFAIL(label, teardown, cmpfail_label) \
  75. ".pushsection __rseq_failure, \"ax\"\n\t" \
  76. __rseq_str(label) ":\n\t" \
  77. teardown \
  78. "jg %l[" __rseq_str(cmpfail_label) "]\n\t" \
  79. ".popsection\n\t"
  80. /* Per-cpu-id indexing. */
  81. #define RSEQ_TEMPLATE_CPU_ID
  82. #define RSEQ_TEMPLATE_MO_RELAXED
  83. #include "rseq-s390-bits.h"
  84. #undef RSEQ_TEMPLATE_MO_RELAXED
  85. #define RSEQ_TEMPLATE_MO_RELEASE
  86. #include "rseq-s390-bits.h"
  87. #undef RSEQ_TEMPLATE_MO_RELEASE
  88. #undef RSEQ_TEMPLATE_CPU_ID
  89. /* Per-mm-cid indexing. */
  90. #define RSEQ_TEMPLATE_MM_CID
  91. #define RSEQ_TEMPLATE_MO_RELAXED
  92. #include "rseq-s390-bits.h"
  93. #undef RSEQ_TEMPLATE_MO_RELAXED
  94. #define RSEQ_TEMPLATE_MO_RELEASE
  95. #include "rseq-s390-bits.h"
  96. #undef RSEQ_TEMPLATE_MO_RELEASE
  97. #undef RSEQ_TEMPLATE_MM_CID
  98. /* APIs which are not based on cpu ids. */
  99. #define RSEQ_TEMPLATE_CPU_ID_NONE
  100. #define RSEQ_TEMPLATE_MO_RELAXED
  101. #include "rseq-s390-bits.h"
  102. #undef RSEQ_TEMPLATE_MO_RELAXED
  103. #undef RSEQ_TEMPLATE_CPU_ID_NONE