Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
0002 #ifndef _RSEQ_ABI_H
0003 #define _RSEQ_ABI_H
0004 
0005 /*
0006  * rseq-abi.h
0007  *
0008  * Restartable sequences system call API
0009  *
0010  * Copyright (c) 2015-2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
0011  */
0012 
0013 #include <linux/types.h>
0014 #include <asm/byteorder.h>
0015 
0016 enum rseq_abi_cpu_id_state {
0017     RSEQ_ABI_CPU_ID_UNINITIALIZED           = -1,
0018     RSEQ_ABI_CPU_ID_REGISTRATION_FAILED     = -2,
0019 };
0020 
0021 enum rseq_abi_flags {
0022     RSEQ_ABI_FLAG_UNREGISTER = (1 << 0),
0023 };
0024 
0025 enum rseq_abi_cs_flags_bit {
0026     RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT  = 0,
0027     RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT   = 1,
0028     RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT  = 2,
0029 };
0030 
0031 enum rseq_abi_cs_flags {
0032     RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT  =
0033         (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT),
0034     RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL   =
0035         (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT),
0036     RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE  =
0037         (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT),
0038 };
0039 
0040 /*
0041  * struct rseq_abi_cs is aligned on 4 * 8 bytes to ensure it is always
0042  * contained within a single cache-line. It is usually declared as
0043  * link-time constant data.
0044  */
0045 struct rseq_abi_cs {
0046     /* Version of this structure. */
0047     __u32 version;
0048     /* enum rseq_abi_cs_flags */
0049     __u32 flags;
0050     __u64 start_ip;
0051     /* Offset from start_ip. */
0052     __u64 post_commit_offset;
0053     __u64 abort_ip;
0054 } __attribute__((aligned(4 * sizeof(__u64))));
0055 
0056 /*
0057  * struct rseq_abi is aligned on 4 * 8 bytes to ensure it is always
0058  * contained within a single cache-line.
0059  *
0060  * A single struct rseq_abi per thread is allowed.
0061  */
0062 struct rseq_abi {
0063     /*
0064      * Restartable sequences cpu_id_start field. Updated by the
0065      * kernel. Read by user-space with single-copy atomicity
0066      * semantics. This field should only be read by the thread which
0067      * registered this data structure. Aligned on 32-bit. Always
0068      * contains a value in the range of possible CPUs, although the
0069      * value may not be the actual current CPU (e.g. if rseq is not
0070      * initialized). This CPU number value should always be compared
0071      * against the value of the cpu_id field before performing a rseq
0072      * commit or returning a value read from a data structure indexed
0073      * using the cpu_id_start value.
0074      */
0075     __u32 cpu_id_start;
0076     /*
0077      * Restartable sequences cpu_id field. Updated by the kernel.
0078      * Read by user-space with single-copy atomicity semantics. This
0079      * field should only be read by the thread which registered this
0080      * data structure. Aligned on 32-bit. Values
0081      * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED
0082      * have a special semantic: the former means "rseq uninitialized",
0083      * and latter means "rseq initialization failed". This value is
0084      * meant to be read within rseq critical sections and compared
0085      * with the cpu_id_start value previously read, before performing
0086      * the commit instruction, or read and compared with the
0087      * cpu_id_start value before returning a value loaded from a data
0088      * structure indexed using the cpu_id_start value.
0089      */
0090     __u32 cpu_id;
0091     /*
0092      * Restartable sequences rseq_cs field.
0093      *
0094      * Contains NULL when no critical section is active for the current
0095      * thread, or holds a pointer to the currently active struct rseq_cs.
0096      *
0097      * Updated by user-space, which sets the address of the currently
0098      * active rseq_cs at the beginning of assembly instruction sequence
0099      * block, and set to NULL by the kernel when it restarts an assembly
0100      * instruction sequence block, as well as when the kernel detects that
0101      * it is preempting or delivering a signal outside of the range
0102      * targeted by the rseq_cs. Also needs to be set to NULL by user-space
0103      * before reclaiming memory that contains the targeted struct rseq_cs.
0104      *
0105      * Read and set by the kernel. Set by user-space with single-copy
0106      * atomicity semantics. This field should only be updated by the
0107      * thread which registered this data structure. Aligned on 64-bit.
0108      */
0109     union {
0110         __u64 ptr64;
0111 
0112         /*
0113          * The "arch" field provides architecture accessor for
0114          * the ptr field based on architecture pointer size and
0115          * endianness.
0116          */
0117         struct {
0118 #ifdef __LP64__
0119             __u64 ptr;
0120 #elif defined(__BYTE_ORDER) ? (__BYTE_ORDER == __BIG_ENDIAN) : defined(__BIG_ENDIAN)
0121             __u32 padding;      /* Initialized to zero. */
0122             __u32 ptr;
0123 #else
0124             __u32 ptr;
0125             __u32 padding;      /* Initialized to zero. */
0126 #endif
0127         } arch;
0128     } rseq_cs;
0129 
0130     /*
0131      * Restartable sequences flags field.
0132      *
0133      * This field should only be updated by the thread which
0134      * registered this data structure. Read by the kernel.
0135      * Mainly used for single-stepping through rseq critical sections
0136      * with debuggers.
0137      *
0138      * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT
0139      *     Inhibit instruction sequence block restart on preemption
0140      *     for this thread.
0141      * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL
0142      *     Inhibit instruction sequence block restart on signal
0143      *     delivery for this thread.
0144      * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE
0145      *     Inhibit instruction sequence block restart on migration for
0146      *     this thread.
0147      */
0148     __u32 flags;
0149 } __attribute__((aligned(4 * sizeof(__u64))));
0150 
0151 #endif /* _RSEQ_ABI_H */