From: Michael Jeanson Date: Mon, 22 Apr 2019 20:46:37 +0000 (-0400) Subject: Add embedded rseq/opv headers for test builds X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=7fc5861f09454482967d90d44be8da79a6a7d537;p=librseq.git Add embedded rseq/opv headers for test builds Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/extra/README b/extra/README new file mode 100644 index 0000000..fe48230 --- /dev/null +++ b/extra/README @@ -0,0 +1 @@ +Kernel includes for test builds. Do not use for real builds. diff --git a/extra/linux/cpu_opv.h b/extra/linux/cpu_opv.h new file mode 100644 index 0000000..b7e3d41 --- /dev/null +++ b/extra/linux/cpu_opv.h @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_CPU_OPV_H +#define _UAPI_LINUX_CPU_OPV_H + +/* + * linux/cpu_opv.h + * + * Per-CPU-atomic operation vector system call API + * + * Copyright (c) 2017-2018 Mathieu Desnoyers + */ + +#include + +/* Maximum size of operation structure within struct cpu_op. */ +#define CPU_OP_ARG_LEN_MAX 24 +/* Maximum data len for compare and memcpy operations. */ +#define CPU_OP_DATA_LEN_MAX 4096 +/* Maximum data len for arithmetic operations. */ +#define CPU_OP_ARITHMETIC_DATA_LEN_MAX 8 + +enum cpu_op_flags { + CPU_OP_NR_FLAG = (1U << 0), + CPU_OP_VEC_LEN_MAX_FLAG = (1U << 1), +}; + +enum cpu_op_type { + /* compare */ + CPU_COMPARE_EQ_OP, + CPU_COMPARE_NE_OP, + /* memcpy */ + CPU_MEMCPY_OP, + CPU_MEMCPY_RELEASE_OP, + /* arithmetic */ + CPU_ADD_OP, + CPU_ADD_RELEASE_OP, + + NR_CPU_OPS, +}; + +/* Vector of operations to perform. Limited to 16. */ +struct cpu_op { + /* enum cpu_op_type. */ + __s32 op; + /* data length, in bytes. */ + __u32 len; + union { + struct { + __u64 a; + __u64 b; + __u8 expect_fault_a; + __u8 expect_fault_b; + } compare_op; + struct { + __u64 dst; + __u64 src; + __u8 expect_fault_dst; + __u8 expect_fault_src; + } memcpy_op; + struct { + __u64 p; + __s64 count; + __u8 expect_fault_p; + } arithmetic_op; + char __padding[CPU_OP_ARG_LEN_MAX]; + } u; +}; + +/* + * Define the rseq system call number if not yet available in + * the system headers. + */ +#ifdef __x86_64__ + +#ifndef __NR_cpu_opv +#define __NR_cpu_opv 335 +#endif + +#elif defined(__i386__) + +#ifndef __NR_cpu_opv +#define __NR_cpu_opv 387 +#endif + +#elif defined(__AARCH64EL__) + +#ifndef __NR_cpu_opv +#define __NR_cpu_opv 295 +#endif + +#elif defined(__ARMEL__) + +#ifndef __NR_cpu_opv +#define __NR_cpu_opv 400 +#endif + +#elif defined(__PPC__) + +#ifndef __NR_cpu_opv +#define __NR_cpu_opv 389 +#endif + +#endif + +#endif /* _UAPI_LINUX_CPU_OPV_H */ diff --git a/extra/linux/rseq.h b/extra/linux/rseq.h new file mode 100644 index 0000000..306a0ba --- /dev/null +++ b/extra/linux/rseq.h @@ -0,0 +1,189 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_RSEQ_H +#define _UAPI_LINUX_RSEQ_H + +/* + * linux/rseq.h + * + * Restartable sequences system call API + * + * Copyright (c) 2015-2018 Mathieu Desnoyers + */ + +#include +#include + +enum rseq_cpu_id_state { + RSEQ_CPU_ID_UNINITIALIZED = -1, + RSEQ_CPU_ID_REGISTRATION_FAILED = -2, +}; + +enum rseq_flags { + RSEQ_FLAG_UNREGISTER = (1 << 0), +}; + +enum rseq_cs_flags_bit { + RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT = 0, + RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT = 1, + RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT = 2, +}; + +enum rseq_cs_flags { + RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT = + (1U << RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT), + RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL = + (1U << RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT), + RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE = + (1U << RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT), +}; + +/* + * struct rseq_cs is aligned on 4 * 8 bytes to ensure it is always + * contained within a single cache-line. It is usually declared as + * link-time constant data. + */ +struct rseq_cs { + /* Version of this structure. */ + __u32 version; + /* enum rseq_cs_flags */ + __u32 flags; + __u64 start_ip; + /* Offset from start_ip. */ + __u64 post_commit_offset; + __u64 abort_ip; +} __attribute__((aligned(4 * sizeof(__u64)))); + +/* + * struct rseq is aligned on 4 * 8 bytes to ensure it is always + * contained within a single cache-line. + * + * A single struct rseq per thread is allowed. + */ +struct rseq { + /* + * Restartable sequences cpu_id_start field. Updated by the + * kernel. Read by user-space with single-copy atomicity + * semantics. This field should only be read by the thread which + * registered this data structure. Aligned on 32-bit. Always + * contains a value in the range of possible CPUs, although the + * value may not be the actual current CPU (e.g. if rseq is not + * initialized). This CPU number value should always be compared + * against the value of the cpu_id field before performing a rseq + * commit or returning a value read from a data structure indexed + * using the cpu_id_start value. + */ + __u32 cpu_id_start; + /* + * Restartable sequences cpu_id field. Updated by the kernel. + * Read by user-space with single-copy atomicity semantics. This + * field should only be read by the thread which registered this + * data structure. Aligned on 32-bit. Values + * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED + * have a special semantic: the former means "rseq uninitialized", + * and latter means "rseq initialization failed". This value is + * meant to be read within rseq critical sections and compared + * with the cpu_id_start value previously read, before performing + * the commit instruction, or read and compared with the + * cpu_id_start value before returning a value loaded from a data + * structure indexed using the cpu_id_start value. + */ + __u32 cpu_id; + /* + * Restartable sequences rseq_cs field. + * + * Contains NULL when no critical section is active for the current + * thread, or holds a pointer to the currently active struct rseq_cs. + * + * Updated by user-space, which sets the address of the currently + * active rseq_cs at the beginning of assembly instruction sequence + * block, and set to NULL by the kernel when it restarts an assembly + * instruction sequence block, as well as when the kernel detects that + * it is preempting or delivering a signal outside of the range + * targeted by the rseq_cs. Also needs to be set to NULL by user-space + * before reclaiming memory that contains the targeted struct rseq_cs. + * + * Read and set by the kernel. Set by user-space with single-copy + * atomicity semantics. This field should only be updated by the + * thread which registered this data structure. Aligned on 64-bit. + */ + union { + __u64 ptr64; +#ifdef __LP64__ + __u64 ptr; +#else + struct { +#if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || defined(__BIG_ENDIAN) + __u32 padding; /* Initialized to zero. */ + __u32 ptr32; +#else /* LITTLE */ + __u32 ptr32; + __u32 padding; /* Initialized to zero. */ +#endif /* ENDIAN */ + } ptr; +#endif + } rseq_cs; + + /* + * Restartable sequences flags field. + * + * This field should only be updated by the thread which + * registered this data structure. Read by the kernel. + * Mainly used for single-stepping through rseq critical sections + * with debuggers. + * + * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT + * Inhibit instruction sequence block restart on preemption + * for this thread. + * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL + * Inhibit instruction sequence block restart on signal + * delivery for this thread. + * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE + * Inhibit instruction sequence block restart on migration for + * this thread. + */ + __u32 flags; +} __attribute__((aligned(4 * sizeof(__u64)))); + +/* + * Define the rseq system call number if not yet available in + * the system headers. + */ +#ifdef __x86_64__ + +#ifndef __NR_rseq +#define __NR_rseq 334 +#endif + +#elif defined(__i386__) + +#ifndef __NR_rseq +#define __NR_rseq 386 +#endif + +#elif defined(__AARCH64EL__) + +#ifndef __NR_rseq +#define __NR_rseq 293 +#endif + +#elif defined(__ARMEL__) + +#ifndef __NR_rseq +#define __NR_rseq 398 +#endif + +#elif defined(__PPC__) + +#ifndef __NR_rseq +#define __NR_rseq 387 +#endif + +#elif defined(__s390__) + +#ifndef __NR_rseq +#define __NR_rseq 383 +#endif + +#endif + +#endif /* _UAPI_LINUX_RSEQ_H */