1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 #ifndef _UAPI_LINUX_RSEQ_H
3 #define _UAPI_LINUX_RSEQ_H
8 * Restartable sequences system call API
10 * Copyright (c) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 # include <linux/types.h>
19 #include <linux/types_32_64.h>
21 enum rseq_cpu_id_state {
22 RSEQ_CPU_ID_UNINITIALIZED = -1,
23 RSEQ_CPU_ID_REGISTRATION_FAILED = -2,
27 RSEQ_FLAG_UNREGISTER = (1 << 0),
30 enum rseq_cs_flags_bit {
31 RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT = 0,
32 RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT = 1,
33 RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT = 2,
37 RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT =
38 (1U << RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT),
39 RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL =
40 (1U << RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT),
41 RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE =
42 (1U << RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT),
46 * struct rseq_cs is aligned on 4 * 8 bytes to ensure it is always
47 * contained within a single cache-line. It is usually declared as
48 * link-time constant data.
51 /* Version of this structure. */
53 /* enum rseq_cs_flags */
56 /* Offset from start_ip. */
57 __u64 post_commit_offset;
59 } __attribute__((aligned(4 * sizeof(__u64))));
62 * struct rseq is aligned on 4 * 8 bytes to ensure it is always
63 * contained within a single cache-line.
65 * A single struct rseq per thread is allowed.
69 * Restartable sequences cpu_id_start field. Updated by the
70 * kernel. Read by user-space with single-copy atomicity
71 * semantics. This field should only be read by the thread which
72 * registered this data structure. Aligned on 32-bit. Always
73 * contains a value in the range of possible CPUs, although the
74 * value may not be the actual current CPU (e.g. if rseq is not
75 * initialized). This CPU number value should always be compared
76 * against the value of the cpu_id field before performing a rseq
77 * commit or returning a value read from a data structure indexed
78 * using the cpu_id_start value.
82 * Restartable sequences cpu_id field. Updated by the kernel.
83 * Read by user-space with single-copy atomicity semantics. This
84 * field should only be read by the thread which registered this
85 * data structure. Aligned on 32-bit. Values
86 * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED
87 * have a special semantic: the former means "rseq uninitialized",
88 * and latter means "rseq initialization failed". This value is
89 * meant to be read within rseq critical sections and compared
90 * with the cpu_id_start value previously read, before performing
91 * the commit instruction, or read and compared with the
92 * cpu_id_start value before returning a value loaded from a data
93 * structure indexed using the cpu_id_start value.
97 * Restartable sequences rseq_cs field.
99 * Contains NULL when no critical section is active for the current
100 * thread, or holds a pointer to the currently active struct rseq_cs.
102 * Updated by user-space, which sets the address of the currently
103 * active rseq_cs at the beginning of assembly instruction sequence
104 * block, and set to NULL by the kernel when it restarts an assembly
105 * instruction sequence block, as well as when the kernel detects that
106 * it is preempting or delivering a signal outside of the range
107 * targeted by the rseq_cs. Also needs to be set to NULL by user-space
108 * before reclaiming memory that contains the targeted struct rseq_cs.
110 * Read and set by the kernel. Set by user-space with single-copy
111 * atomicity semantics. This field should only be updated by the
112 * thread which registered this data structure. Aligned on 64-bit.
114 LINUX_FIELD_u32_u64(rseq_cs);
116 * Restartable sequences flags field.
118 * This field should only be updated by the thread which
119 * registered this data structure. Read by the kernel.
120 * Mainly used for single-stepping through rseq critical sections
123 * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT
124 * Inhibit instruction sequence block restart on preemption
126 * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL
127 * Inhibit instruction sequence block restart on signal
128 * delivery for this thread.
129 * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE
130 * Inhibit instruction sequence block restart on migration for
134 } __attribute__((aligned(4 * sizeof(__u64))));
136 #endif /* _UAPI_LINUX_RSEQ_H */