1 /* SPDX-License-Identifier: GPL-2.0-or-later WITH Linux-syscall-note */
2 /* SPDX-FileCopyrightText: 2015-2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */
9 * Restartable sequences system call ABI
12 #include <linux/types.h>
13 #include <asm/byteorder.h>
15 enum rseq_abi_cpu_id_state
{
16 RSEQ_ABI_CPU_ID_UNINITIALIZED
= -1,
17 RSEQ_ABI_CPU_ID_REGISTRATION_FAILED
= -2,
21 RSEQ_ABI_FLAG_UNREGISTER
= (1 << 0),
24 enum rseq_abi_cs_flags_bit
{
25 RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT
= 0,
26 RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT
= 1,
27 RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT
= 2,
30 enum rseq_abi_cs_flags
{
31 RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT
=
32 (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT
),
33 RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL
=
34 (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT
),
35 RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE
=
36 (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT
),
40 * struct rseq_abi_cs is aligned on 4 * 8 bytes to ensure it is always
41 * contained within a single cache-line. It is usually declared as
42 * link-time constant data.
45 /* Version of this structure. */
47 /* enum rseq_abi_cs_flags */
50 /* Offset from start_ip. */
51 __u64 post_commit_offset
;
53 } __attribute__((aligned(4 * sizeof(__u64
))));
56 * struct rseq is aligned on 4 * 8 bytes to ensure it is always
57 * contained within a single cache-line.
59 * A single struct rseq per thread is allowed.
63 * Restartable sequences cpu_id_start field. Updated by the
64 * kernel. Read by user-space with single-copy atomicity
65 * semantics. This field should only be read by the thread which
66 * registered this data structure. Aligned on 32-bit. Always
67 * contains a value in the range of possible CPUs, although the
68 * value may not be the actual current CPU (e.g. if rseq is not
69 * initialized). This CPU number value should always be compared
70 * against the value of the cpu_id field before performing a rseq
71 * commit or returning a value read from a data structure indexed
72 * using the cpu_id_start value.
76 * Restartable sequences cpu_id field. Updated by the kernel.
77 * Read by user-space with single-copy atomicity semantics. This
78 * field should only be read by the thread which registered this
79 * data structure. Aligned on 32-bit. Values
80 * RSEQ_ABI_CPU_ID_UNINITIALIZED and RSEQ_ABI_CPU_ID_REGISTRATION_FAILED
81 * have a special semantic: the former means "rseq uninitialized",
82 * and latter means "rseq initialization failed". This value is
83 * meant to be read within rseq critical sections and compared
84 * with the cpu_id_start value previously read, before performing
85 * the commit instruction, or read and compared with the
86 * cpu_id_start value before returning a value loaded from a data
87 * structure indexed using the cpu_id_start value.
91 * Restartable sequences rseq_cs field.
93 * Contains NULL when no critical section is active for the current
94 * thread, or holds a pointer to the currently active struct rseq_abi_cs.
96 * Updated by user-space, which sets the address of the currently
97 * active rseq_cs at the beginning of assembly instruction sequence
98 * block, and set to NULL by the kernel when it restarts an assembly
99 * instruction sequence block, as well as when the kernel detects that
100 * it is preempting or delivering a signal outside of the range
101 * targeted by the rseq_cs. Also needs to be set to NULL by user-space
102 * before reclaiming memory that contains the targeted struct rseq_abi_cs.
104 * Read and set by the kernel. Set by user-space with single-copy
105 * atomicity semantics. This field should only be updated by the
106 * thread which registered this data structure. Aligned on 64-bit.
108 * 32-bit architectures should update the low order bits of the
109 * rseq_cs field, leaving the high order bits initialized to 0.
115 * The "arch" field provides architecture accessor for
116 * the ptr field based on architecture pointer size and
122 #elif defined(__BYTE_ORDER) ? (__BYTE_ORDER == __BIG_ENDIAN) : defined(__BIG_ENDIAN)
123 __u32 padding
; /* Initialized to zero. */
127 __u32 padding
; /* Initialized to zero. */
133 * Restartable sequences flags field.
135 * This field should only be updated by the thread which
136 * registered this data structure. Read by the kernel.
137 * Mainly used for single-stepping through rseq critical sections
140 * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT
141 * Inhibit instruction sequence block restart on preemption
143 * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL
144 * Inhibit instruction sequence block restart on signal
145 * delivery for this thread.
146 * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE
147 * Inhibit instruction sequence block restart on migration for
153 * Restartable sequences node_id field. Updated by the kernel. Read by
154 * user-space with single-copy atomicity semantics. This field should
155 * only be read by the thread which registered this data structure.
156 * Aligned on 32-bit. Contains the current NUMA node ID.
161 * Restartable sequences mm_cid field. Updated by the kernel. Read by
162 * user-space with single-copy atomicity semantics. This field should
163 * only be read by the thread which registered this data structure.
164 * Aligned on 32-bit. Contains the current thread's concurrency ID
165 * (allocated uniquely within a memory map).
170 * Flexible array member at end of structure, after last feature field.
173 } __attribute__((aligned(4 * sizeof(__u64
))));
176 * Define the rseq system call number if not yet available in
177 * the system headers.
182 #define __NR_rseq 334
185 #elif defined(__i386__)
188 #define __NR_rseq 386
191 #elif defined(__AARCH64EL__)
194 #define __NR_rseq 293
197 #elif defined(__ARMEL__)
200 #define __NR_rseq 398
203 #elif defined(__PPC__)
206 #define __NR_rseq 387
209 #elif defined(__s390__)
212 #define __NR_rseq 383
215 #elif defined(__riscv)
218 #define __NR_rseq 293
223 #endif /* _RSEQ_ABI_H */