rseq.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. #ifndef _UAPI_LINUX_RSEQ_H
  3. #define _UAPI_LINUX_RSEQ_H
  4. /*
  5. * linux/rseq.h
  6. *
  7. * Restartable sequences system call API
  8. *
  9. * Copyright (c) 2015-2018 Mathieu Desnoyers <[email protected]>
  10. */
  11. #include <linux/types.h>
  12. #include <asm/byteorder.h>
  13. enum rseq_cpu_id_state {
  14. RSEQ_CPU_ID_UNINITIALIZED = -1,
  15. RSEQ_CPU_ID_REGISTRATION_FAILED = -2,
  16. };
  17. enum rseq_flags {
  18. RSEQ_FLAG_UNREGISTER = (1 << 0),
  19. };
  20. enum rseq_cs_flags_bit {
  21. RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT = 0,
  22. RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT = 1,
  23. RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT = 2,
  24. };
  25. enum rseq_cs_flags {
  26. RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT =
  27. (1U << RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT),
  28. RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL =
  29. (1U << RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT),
  30. RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE =
  31. (1U << RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT),
  32. };
  33. /*
  34. * struct rseq_cs is aligned on 4 * 8 bytes to ensure it is always
  35. * contained within a single cache-line. It is usually declared as
  36. * link-time constant data.
  37. */
  38. struct rseq_cs {
  39. /* Version of this structure. */
  40. __u32 version;
  41. /* enum rseq_cs_flags */
  42. __u32 flags;
  43. __u64 start_ip;
  44. /* Offset from start_ip. */
  45. __u64 post_commit_offset;
  46. __u64 abort_ip;
  47. } __attribute__((aligned(4 * sizeof(__u64))));
  48. /*
  49. * struct rseq is aligned on 4 * 8 bytes to ensure it is always
  50. * contained within a single cache-line.
  51. *
  52. * A single struct rseq per thread is allowed.
  53. */
  54. struct rseq {
  55. /*
  56. * Restartable sequences cpu_id_start field. Updated by the
  57. * kernel. Read by user-space with single-copy atomicity
  58. * semantics. This field should only be read by the thread which
  59. * registered this data structure. Aligned on 32-bit. Always
  60. * contains a value in the range of possible CPUs, although the
  61. * value may not be the actual current CPU (e.g. if rseq is not
  62. * initialized). This CPU number value should always be compared
  63. * against the value of the cpu_id field before performing a rseq
  64. * commit or returning a value read from a data structure indexed
  65. * using the cpu_id_start value.
  66. */
  67. __u32 cpu_id_start;
  68. /*
  69. * Restartable sequences cpu_id field. Updated by the kernel.
  70. * Read by user-space with single-copy atomicity semantics. This
  71. * field should only be read by the thread which registered this
  72. * data structure. Aligned on 32-bit. Values
  73. * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED
  74. * have a special semantic: the former means "rseq uninitialized",
  75. * and latter means "rseq initialization failed". This value is
  76. * meant to be read within rseq critical sections and compared
  77. * with the cpu_id_start value previously read, before performing
  78. * the commit instruction, or read and compared with the
  79. * cpu_id_start value before returning a value loaded from a data
  80. * structure indexed using the cpu_id_start value.
  81. */
  82. __u32 cpu_id;
  83. /*
  84. * Restartable sequences rseq_cs field.
  85. *
  86. * Contains NULL when no critical section is active for the current
  87. * thread, or holds a pointer to the currently active struct rseq_cs.
  88. *
  89. * Updated by user-space, which sets the address of the currently
  90. * active rseq_cs at the beginning of assembly instruction sequence
  91. * block, and set to NULL by the kernel when it restarts an assembly
  92. * instruction sequence block, as well as when the kernel detects that
  93. * it is preempting or delivering a signal outside of the range
  94. * targeted by the rseq_cs. Also needs to be set to NULL by user-space
  95. * before reclaiming memory that contains the targeted struct rseq_cs.
  96. *
  97. * Read and set by the kernel. Set by user-space with single-copy
  98. * atomicity semantics. This field should only be updated by the
  99. * thread which registered this data structure. Aligned on 64-bit.
  100. *
  101. * 32-bit architectures should update the low order bits of the
  102. * rseq_cs field, leaving the high order bits initialized to 0.
  103. */
  104. __u64 rseq_cs;
  105. /*
  106. * Restartable sequences flags field.
  107. *
  108. * This field should only be updated by the thread which
  109. * registered this data structure. Read by the kernel.
  110. * Mainly used for single-stepping through rseq critical sections
  111. * with debuggers.
  112. *
  113. * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT
  114. * Inhibit instruction sequence block restart on preemption
  115. * for this thread.
  116. * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL
  117. * Inhibit instruction sequence block restart on signal
  118. * delivery for this thread.
  119. * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE
  120. * Inhibit instruction sequence block restart on migration for
  121. * this thread.
  122. */
  123. __u32 flags;
  124. } __attribute__((aligned(4 * sizeof(__u64))));
  125. #endif /* _UAPI_LINUX_RSEQ_H */