Commit | Line | Data |
---|---|---|
f2d7b530 MJ |
1 | /* SPDX-License-Identifier: GPL-2.0-or-later WITH Linux-syscall-note */ |
2 | /* SPDX-FileCopyrightText: 2015-2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */ | |
af73b478 MD |
3 | #ifndef _RSEQ_ABI_H |
4 | #define _RSEQ_ABI_H | |
7fc5861f MJ |
5 | |
6 | /* | |
2d533093 | 7 | * rseq/rseq-abi.h |
7fc5861f MJ |
8 | * |
9 | * Restartable sequences system call API | |
7fc5861f MJ |
10 | */ |
11 | ||
12 | #include <linux/types.h> | |
13 | #include <asm/byteorder.h> | |
14 | ||
2d533093 | 15 | enum rseq_abi_cpu_id_state { |
af73b478 | 16 | RSEQ_ABI_CPU_ID_UNINITIALIZED = -1, |
2d533093 | 17 | RSEQ_ABI_CPU_ID_REGISTRATION_FAILED = -2, |
7fc5861f MJ |
18 | }; |
19 | ||
2d533093 MD |
20 | enum rseq_abi_flags { |
21 | RSEQ_ABI_FLAG_UNREGISTER = (1 << 0), | |
7fc5861f MJ |
22 | }; |
23 | ||
2d533093 MD |
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, | |
7fc5861f MJ |
28 | }; |
29 | ||
2d533093 MD |
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), | |
7fc5861f MJ |
37 | }; |
38 | ||
39 | /* | |
2d533093 | 40 | * struct rseq_abi_cs is aligned on 4 * 8 bytes to ensure it is always |
7fc5861f MJ |
41 | * contained within a single cache-line. It is usually declared as |
42 | * link-time constant data. | |
43 | */ | |
2d533093 | 44 | struct rseq_abi_cs { |
7fc5861f MJ |
45 | /* Version of this structure. */ |
46 | __u32 version; | |
2d533093 | 47 | /* enum rseq_abi_cs_flags */ |
7fc5861f MJ |
48 | __u32 flags; |
49 | __u64 start_ip; | |
50 | /* Offset from start_ip. */ | |
51 | __u64 post_commit_offset; | |
52 | __u64 abort_ip; | |
53 | } __attribute__((aligned(4 * sizeof(__u64)))); | |
54 | ||
55 | /* | |
af73b478 | 56 | * struct rseq is aligned on 4 * 8 bytes to ensure it is always |
7fc5861f MJ |
57 | * contained within a single cache-line. |
58 | * | |
af73b478 | 59 | * A single struct rseq per thread is allowed. |
7fc5861f | 60 | */ |
2d533093 | 61 | struct rseq_abi { |
7fc5861f MJ |
62 | /* |
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. | |
73 | */ | |
74 | __u32 cpu_id_start; | |
75 | /* | |
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 | |
af73b478 | 80 | * RSEQ_ABI_CPU_ID_UNINITIALIZED and RSEQ_ABI_CPU_ID_REGISTRATION_FAILED |
7fc5861f MJ |
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. | |
88 | */ | |
89 | __u32 cpu_id; | |
90 | /* | |
91 | * Restartable sequences rseq_cs field. | |
92 | * | |
93 | * Contains NULL when no critical section is active for the current | |
af73b478 | 94 | * thread, or holds a pointer to the currently active struct rseq_abi_cs. |
7fc5861f MJ |
95 | * |
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 | |
af73b478 | 102 | * before reclaiming memory that contains the targeted struct rseq_abi_cs. |
7fc5861f MJ |
103 | * |
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. | |
af73b478 MD |
107 | * |
108 | * 32-bit architectures should update the low order bits of the | |
109 | * rseq_cs field, leaving the high order bits initialized to 0. | |
7fc5861f | 110 | */ |
5b40603c MD |
111 | union { |
112 | __u64 ptr64; | |
113 | ||
114 | /* | |
115 | * The "arch" field provides architecture accessor for | |
116 | * the ptr field based on architecture pointer size and | |
117 | * endianness. | |
118 | */ | |
119 | struct { | |
120 | #ifdef __LP64__ | |
121 | __u64 ptr; | |
122 | #elif defined(__BYTE_ORDER) ? (__BYTE_ORDER == __BIG_ENDIAN) : defined(__BIG_ENDIAN) | |
123 | __u32 padding; /* Initialized to zero. */ | |
124 | __u32 ptr; | |
125 | #else | |
126 | __u32 ptr; | |
127 | __u32 padding; /* Initialized to zero. */ | |
128 | #endif | |
129 | } arch; | |
130 | } rseq_cs; | |
7fc5861f MJ |
131 | |
132 | /* | |
133 | * Restartable sequences flags field. | |
134 | * | |
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 | |
138 | * with debuggers. | |
139 | * | |
2d533093 | 140 | * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT |
7fc5861f MJ |
141 | * Inhibit instruction sequence block restart on preemption |
142 | * for this thread. | |
2d533093 | 143 | * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL |
7fc5861f MJ |
144 | * Inhibit instruction sequence block restart on signal |
145 | * delivery for this thread. | |
2d533093 | 146 | * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE |
7fc5861f MJ |
147 | * Inhibit instruction sequence block restart on migration for |
148 | * this thread. | |
149 | */ | |
150 | __u32 flags; | |
af73b478 MD |
151 | |
152 | /* | |
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. | |
157 | */ | |
158 | __u32 node_id; | |
159 | ||
160 | /* | |
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). | |
166 | */ | |
167 | __u32 mm_cid; | |
168 | ||
169 | /* | |
170 | * Flexible array member at end of structure, after last feature field. | |
171 | */ | |
172 | char end[]; | |
7fc5861f MJ |
173 | } __attribute__((aligned(4 * sizeof(__u64)))); |
174 | ||
175 | /* | |
176 | * Define the rseq system call number if not yet available in | |
177 | * the system headers. | |
178 | */ | |
179 | #ifdef __x86_64__ | |
180 | ||
181 | #ifndef __NR_rseq | |
182 | #define __NR_rseq 334 | |
183 | #endif | |
184 | ||
185 | #elif defined(__i386__) | |
186 | ||
187 | #ifndef __NR_rseq | |
188 | #define __NR_rseq 386 | |
189 | #endif | |
190 | ||
191 | #elif defined(__AARCH64EL__) | |
192 | ||
193 | #ifndef __NR_rseq | |
194 | #define __NR_rseq 293 | |
195 | #endif | |
196 | ||
197 | #elif defined(__ARMEL__) | |
198 | ||
199 | #ifndef __NR_rseq | |
200 | #define __NR_rseq 398 | |
201 | #endif | |
202 | ||
203 | #elif defined(__PPC__) | |
204 | ||
205 | #ifndef __NR_rseq | |
206 | #define __NR_rseq 387 | |
207 | #endif | |
208 | ||
209 | #elif defined(__s390__) | |
210 | ||
211 | #ifndef __NR_rseq | |
212 | #define __NR_rseq 383 | |
213 | #endif | |
214 | ||
074b1077 MJ |
215 | #elif defined(__riscv) |
216 | ||
217 | #ifndef __NR_rseq | |
218 | #define __NR_rseq 293 | |
219 | #endif | |
220 | ||
7fc5861f MJ |
221 | #endif |
222 | ||
2d533093 | 223 | #endif /* _RSEQ_ABI_H */ |