Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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/*
6 * linux/rseq.h
7 *
8 * Restartable sequences system call API
9 *
10 * Copyright (c) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 */
12
13#include <linux/types.h>
14#include <asm/byteorder.h>
15
16enum rseq_cpu_id_state {
17 RSEQ_CPU_ID_UNINITIALIZED = -1,
18 RSEQ_CPU_ID_REGISTRATION_FAILED = -2,
19};
20
21enum rseq_flags {
22 RSEQ_FLAG_UNREGISTER = (1 << 0),
23 RSEQ_FLAG_SLICE_EXT_DEFAULT_ON = (1 << 1),
24};
25
26enum rseq_cs_flags_bit {
27 /* Historical and unsupported bits */
28 RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT = 0,
29 RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT = 1,
30 RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT = 2,
31 /* (3) Intentional gap to put new bits into a separate byte */
32
33 /* User read only feature flags */
34 RSEQ_CS_FLAG_SLICE_EXT_AVAILABLE_BIT = 4,
35 RSEQ_CS_FLAG_SLICE_EXT_ENABLED_BIT = 5,
36};
37
38enum rseq_cs_flags {
39 RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT =
40 (1U << RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT),
41 RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL =
42 (1U << RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT),
43 RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE =
44 (1U << RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT),
45
46 RSEQ_CS_FLAG_SLICE_EXT_AVAILABLE =
47 (1U << RSEQ_CS_FLAG_SLICE_EXT_AVAILABLE_BIT),
48 RSEQ_CS_FLAG_SLICE_EXT_ENABLED =
49 (1U << RSEQ_CS_FLAG_SLICE_EXT_ENABLED_BIT),
50};
51
52/*
53 * struct rseq_cs is aligned on 4 * 8 bytes to ensure it is always
54 * contained within a single cache-line. It is usually declared as
55 * link-time constant data.
56 */
57struct rseq_cs {
58 /* Version of this structure. */
59 __u32 version;
60 /* enum rseq_cs_flags */
61 __u32 flags;
62 __u64 start_ip;
63 /* Offset from start_ip. */
64 __u64 post_commit_offset;
65 __u64 abort_ip;
66} __attribute__((aligned(4 * sizeof(__u64))));
67
68/**
69 * rseq_slice_ctrl - Time slice extension control structure
70 * @all: Compound value
71 * @request: Request for a time slice extension
72 * @granted: Granted time slice extension
73 *
74 * @request is set by user space and can be cleared by user space or kernel
75 * space. @granted is set and cleared by the kernel and must only be read
76 * by user space.
77 */
78struct rseq_slice_ctrl {
79 union {
80 __u32 all;
81 struct {
82 __u8 request;
83 __u8 granted;
84 __u16 __reserved;
85 };
86 };
87};
88
89/*
90 * struct rseq is aligned on 4 * 8 bytes to ensure it is always
91 * contained within a single cache-line.
92 *
93 * A single struct rseq per thread is allowed.
94 */
95struct rseq {
96 /*
97 * Restartable sequences cpu_id_start field. Updated by the
98 * kernel. Read by user-space with single-copy atomicity
99 * semantics. This field should only be read by the thread which
100 * registered this data structure. Aligned on 32-bit. Always
101 * contains a value in the range of possible CPUs, although the
102 * value may not be the actual current CPU (e.g. if rseq is not
103 * initialized). This CPU number value should always be compared
104 * against the value of the cpu_id field before performing a rseq
105 * commit or returning a value read from a data structure indexed
106 * using the cpu_id_start value.
107 */
108 __u32 cpu_id_start;
109 /*
110 * Restartable sequences cpu_id field. Updated by the kernel.
111 * Read by user-space with single-copy atomicity semantics. This
112 * field should only be read by the thread which registered this
113 * data structure. Aligned on 32-bit. Values
114 * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED
115 * have a special semantic: the former means "rseq uninitialized",
116 * and latter means "rseq initialization failed". This value is
117 * meant to be read within rseq critical sections and compared
118 * with the cpu_id_start value previously read, before performing
119 * the commit instruction, or read and compared with the
120 * cpu_id_start value before returning a value loaded from a data
121 * structure indexed using the cpu_id_start value.
122 */
123 __u32 cpu_id;
124 /*
125 * Restartable sequences rseq_cs field.
126 *
127 * Contains NULL when no critical section is active for the current
128 * thread, or holds a pointer to the currently active struct rseq_cs.
129 *
130 * Updated by user-space, which sets the address of the currently
131 * active rseq_cs at the beginning of assembly instruction sequence
132 * block, and set to NULL by the kernel when it restarts an assembly
133 * instruction sequence block, as well as when the kernel detects that
134 * it is preempting or delivering a signal outside of the range
135 * targeted by the rseq_cs. Also needs to be set to NULL by user-space
136 * before reclaiming memory that contains the targeted struct rseq_cs.
137 *
138 * Read and set by the kernel. Set by user-space with single-copy
139 * atomicity semantics. This field should only be updated by the
140 * thread which registered this data structure. Aligned on 64-bit.
141 *
142 * 32-bit architectures should update the low order bits of the
143 * rseq_cs field, leaving the high order bits initialized to 0.
144 */
145 __u64 rseq_cs;
146
147 /*
148 * Restartable sequences flags field.
149 *
150 * This field was initially intended to allow event masking for
151 * single-stepping through rseq critical sections with debuggers.
152 * The kernel does not support this anymore and the relevant bits
153 * are checked for being always false:
154 * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT
155 * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL
156 * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE
157 */
158 __u32 flags;
159
160 /*
161 * Restartable sequences node_id 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 NUMA node ID.
165 */
166 __u32 node_id;
167
168 /*
169 * Restartable sequences mm_cid field. Updated by the kernel. Read by
170 * user-space with single-copy atomicity semantics. This field should
171 * only be read by the thread which registered this data structure.
172 * Aligned on 32-bit. Contains the current thread's concurrency ID
173 * (allocated uniquely within a memory map).
174 */
175 __u32 mm_cid;
176
177 /*
178 * Time slice extension control structure. CPU local updates from
179 * kernel and user space.
180 */
181 struct rseq_slice_ctrl slice_ctrl;
182
183 /*
184 * Flexible array member at end of structure, after last feature field.
185 */
186 char end[];
187} __attribute__((aligned(4 * sizeof(__u64))));
188
189#endif /* _UAPI_LINUX_RSEQ_H */