162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 262306a36Sopenharmony_ci#ifndef _UAPI_LINUX_RSEQ_H 362306a36Sopenharmony_ci#define _UAPI_LINUX_RSEQ_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci/* 662306a36Sopenharmony_ci * linux/rseq.h 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Restartable sequences system call API 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * Copyright (c) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/types.h> 1462306a36Sopenharmony_ci#include <asm/byteorder.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_cienum rseq_cpu_id_state { 1762306a36Sopenharmony_ci RSEQ_CPU_ID_UNINITIALIZED = -1, 1862306a36Sopenharmony_ci RSEQ_CPU_ID_REGISTRATION_FAILED = -2, 1962306a36Sopenharmony_ci}; 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_cienum rseq_flags { 2262306a36Sopenharmony_ci RSEQ_FLAG_UNREGISTER = (1 << 0), 2362306a36Sopenharmony_ci}; 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cienum rseq_cs_flags_bit { 2662306a36Sopenharmony_ci RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT = 0, 2762306a36Sopenharmony_ci RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT = 1, 2862306a36Sopenharmony_ci RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT = 2, 2962306a36Sopenharmony_ci}; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cienum rseq_cs_flags { 3262306a36Sopenharmony_ci RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT = 3362306a36Sopenharmony_ci (1U << RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT), 3462306a36Sopenharmony_ci RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL = 3562306a36Sopenharmony_ci (1U << RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT), 3662306a36Sopenharmony_ci RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE = 3762306a36Sopenharmony_ci (1U << RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT), 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* 4162306a36Sopenharmony_ci * struct rseq_cs is aligned on 4 * 8 bytes to ensure it is always 4262306a36Sopenharmony_ci * contained within a single cache-line. It is usually declared as 4362306a36Sopenharmony_ci * link-time constant data. 4462306a36Sopenharmony_ci */ 4562306a36Sopenharmony_cistruct rseq_cs { 4662306a36Sopenharmony_ci /* Version of this structure. */ 4762306a36Sopenharmony_ci __u32 version; 4862306a36Sopenharmony_ci /* enum rseq_cs_flags */ 4962306a36Sopenharmony_ci __u32 flags; 5062306a36Sopenharmony_ci __u64 start_ip; 5162306a36Sopenharmony_ci /* Offset from start_ip. */ 5262306a36Sopenharmony_ci __u64 post_commit_offset; 5362306a36Sopenharmony_ci __u64 abort_ip; 5462306a36Sopenharmony_ci} __attribute__((aligned(4 * sizeof(__u64)))); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/* 5762306a36Sopenharmony_ci * struct rseq is aligned on 4 * 8 bytes to ensure it is always 5862306a36Sopenharmony_ci * contained within a single cache-line. 5962306a36Sopenharmony_ci * 6062306a36Sopenharmony_ci * A single struct rseq per thread is allowed. 6162306a36Sopenharmony_ci */ 6262306a36Sopenharmony_cistruct rseq { 6362306a36Sopenharmony_ci /* 6462306a36Sopenharmony_ci * Restartable sequences cpu_id_start field. Updated by the 6562306a36Sopenharmony_ci * kernel. Read by user-space with single-copy atomicity 6662306a36Sopenharmony_ci * semantics. This field should only be read by the thread which 6762306a36Sopenharmony_ci * registered this data structure. Aligned on 32-bit. Always 6862306a36Sopenharmony_ci * contains a value in the range of possible CPUs, although the 6962306a36Sopenharmony_ci * value may not be the actual current CPU (e.g. if rseq is not 7062306a36Sopenharmony_ci * initialized). This CPU number value should always be compared 7162306a36Sopenharmony_ci * against the value of the cpu_id field before performing a rseq 7262306a36Sopenharmony_ci * commit or returning a value read from a data structure indexed 7362306a36Sopenharmony_ci * using the cpu_id_start value. 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci __u32 cpu_id_start; 7662306a36Sopenharmony_ci /* 7762306a36Sopenharmony_ci * Restartable sequences cpu_id field. Updated by the kernel. 7862306a36Sopenharmony_ci * Read by user-space with single-copy atomicity semantics. This 7962306a36Sopenharmony_ci * field should only be read by the thread which registered this 8062306a36Sopenharmony_ci * data structure. Aligned on 32-bit. Values 8162306a36Sopenharmony_ci * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED 8262306a36Sopenharmony_ci * have a special semantic: the former means "rseq uninitialized", 8362306a36Sopenharmony_ci * and latter means "rseq initialization failed". This value is 8462306a36Sopenharmony_ci * meant to be read within rseq critical sections and compared 8562306a36Sopenharmony_ci * with the cpu_id_start value previously read, before performing 8662306a36Sopenharmony_ci * the commit instruction, or read and compared with the 8762306a36Sopenharmony_ci * cpu_id_start value before returning a value loaded from a data 8862306a36Sopenharmony_ci * structure indexed using the cpu_id_start value. 8962306a36Sopenharmony_ci */ 9062306a36Sopenharmony_ci __u32 cpu_id; 9162306a36Sopenharmony_ci /* 9262306a36Sopenharmony_ci * Restartable sequences rseq_cs field. 9362306a36Sopenharmony_ci * 9462306a36Sopenharmony_ci * Contains NULL when no critical section is active for the current 9562306a36Sopenharmony_ci * thread, or holds a pointer to the currently active struct rseq_cs. 9662306a36Sopenharmony_ci * 9762306a36Sopenharmony_ci * Updated by user-space, which sets the address of the currently 9862306a36Sopenharmony_ci * active rseq_cs at the beginning of assembly instruction sequence 9962306a36Sopenharmony_ci * block, and set to NULL by the kernel when it restarts an assembly 10062306a36Sopenharmony_ci * instruction sequence block, as well as when the kernel detects that 10162306a36Sopenharmony_ci * it is preempting or delivering a signal outside of the range 10262306a36Sopenharmony_ci * targeted by the rseq_cs. Also needs to be set to NULL by user-space 10362306a36Sopenharmony_ci * before reclaiming memory that contains the targeted struct rseq_cs. 10462306a36Sopenharmony_ci * 10562306a36Sopenharmony_ci * Read and set by the kernel. Set by user-space with single-copy 10662306a36Sopenharmony_ci * atomicity semantics. This field should only be updated by the 10762306a36Sopenharmony_ci * thread which registered this data structure. Aligned on 64-bit. 10862306a36Sopenharmony_ci * 10962306a36Sopenharmony_ci * 32-bit architectures should update the low order bits of the 11062306a36Sopenharmony_ci * rseq_cs field, leaving the high order bits initialized to 0. 11162306a36Sopenharmony_ci */ 11262306a36Sopenharmony_ci __u64 rseq_cs; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci /* 11562306a36Sopenharmony_ci * Restartable sequences flags field. 11662306a36Sopenharmony_ci * 11762306a36Sopenharmony_ci * This field should only be updated by the thread which 11862306a36Sopenharmony_ci * registered this data structure. Read by the kernel. 11962306a36Sopenharmony_ci * Mainly used for single-stepping through rseq critical sections 12062306a36Sopenharmony_ci * with debuggers. 12162306a36Sopenharmony_ci * 12262306a36Sopenharmony_ci * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT 12362306a36Sopenharmony_ci * Inhibit instruction sequence block restart on preemption 12462306a36Sopenharmony_ci * for this thread. 12562306a36Sopenharmony_ci * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL 12662306a36Sopenharmony_ci * Inhibit instruction sequence block restart on signal 12762306a36Sopenharmony_ci * delivery for this thread. 12862306a36Sopenharmony_ci * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE 12962306a36Sopenharmony_ci * Inhibit instruction sequence block restart on migration for 13062306a36Sopenharmony_ci * this thread. 13162306a36Sopenharmony_ci */ 13262306a36Sopenharmony_ci __u32 flags; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci /* 13562306a36Sopenharmony_ci * Restartable sequences node_id field. Updated by the kernel. Read by 13662306a36Sopenharmony_ci * user-space with single-copy atomicity semantics. This field should 13762306a36Sopenharmony_ci * only be read by the thread which registered this data structure. 13862306a36Sopenharmony_ci * Aligned on 32-bit. Contains the current NUMA node ID. 13962306a36Sopenharmony_ci */ 14062306a36Sopenharmony_ci __u32 node_id; 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci /* 14362306a36Sopenharmony_ci * Restartable sequences mm_cid field. Updated by the kernel. Read by 14462306a36Sopenharmony_ci * user-space with single-copy atomicity semantics. This field should 14562306a36Sopenharmony_ci * only be read by the thread which registered this data structure. 14662306a36Sopenharmony_ci * Aligned on 32-bit. Contains the current thread's concurrency ID 14762306a36Sopenharmony_ci * (allocated uniquely within a memory map). 14862306a36Sopenharmony_ci */ 14962306a36Sopenharmony_ci __u32 mm_cid; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci /* 15262306a36Sopenharmony_ci * Flexible array member at end of structure, after last feature field. 15362306a36Sopenharmony_ci */ 15462306a36Sopenharmony_ci char end[]; 15562306a36Sopenharmony_ci} __attribute__((aligned(4 * sizeof(__u64)))); 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci#endif /* _UAPI_LINUX_RSEQ_H */ 158