RSEQ node id and mm concurrency id extensions
Subsystems (12)
Mathieu Desnoyers
maintainercover RSEQ node id and mm concurrency id extensions
Extend the rseq ABI to expose NUMA node ID, mm_cid, and mm_numa_cid fields.
The NUMA node ID field allows implementing a faster getcpu(2) in libc.
The per-memory-map concurrency id (mm_cid) [1] allows ideal scaling (down or up) of user-space per-cpu data structures. The concurrency ids allocated within a memory map are tracked by the scheduler, which takes into account the number of concurrently running threads, thus implicitly considering the number of threads, the cpu affinity, the cpusets applying to those threads, and the number of logical cores on the system.
The NUMA-aware concurrency id (mm_numa_cid) is similar to the mm_cid, except that it keeps track of the NUMA node ids with which each cid has been associated. On NUMA systems, when a NUMA-aware concurrency ID is observed by user-space to be associated with a NUMA node, it is guaranteed to never change NUMA node unless a kernel-level NUMA configuration change happens. This is useful for NUMA-aware per-cpu data structures running in environments where a process or a set of processes belonging to cpuset are pinned to a set of cores which belong to a subset of the system's NUMA nodes.
This series is based on tip/sched/core
commit 52b33d87b9197 ("sched/psi: Use task->psi_flags to clear in CPU migration")
Thanks,
Mathieu
[1] was previously known as vcpu_id in earlier versions of this patch set.
Mathieu Desnoyers (30):
selftests/rseq: Fix: Fail thread registration when CONFIG_RSEQ=n
rseq: Introduce feature size and alignment ELF auxiliary vector
entries
rseq: Introduce extensible rseq ABI
rseq: Extend struct rseq with numa node id
selftests/rseq: Use ELF auxiliary vector for extensible rseq selftests/rseq: Implement rseq numa node id field selftest
sched: Introduce per-memory-map concurrency ID
rseq: Extend struct rseq with per-memory-map concurrency ID selftests/rseq: Remove RSEQ_SKIP_FASTPATH code selftests/rseq: Implement rseq mm_cid field support selftests/rseq: x86: Template memory ordering and percpu access mode selftests/rseq: arm: Template memory ordering and percpu access mode selftests/rseq: arm64: Template memory ordering and percpu access mode selftests/rseq: mips: Template memory ordering and percpu access mode selftests/rseq: ppc: Template memory ordering and percpu access mode selftests/rseq: s390: Template memory ordering and percpu access mode selftests/rseq: riscv: Template memory ordering and percpu access mode selftests/rseq: Implement basic percpu ops mm_cid test selftests/rseq: Implement parametrized mm_cid test selftests/rseq: parametrized test: Report/abort on negative
concurrency ID
tracing/rseq: Add mm_cid field to rseq_update
lib: Implement find_{first,next,nth}_notandnot_bit,
find_first_andnot_bit
cpumask: Implement cpumask_{first,next}_{not,}andnot
sched: NUMA-aware per-memory-map concurrency ID
rseq: Extend struct rseq with per-memory-map NUMA-aware Concurrency ID selftests/rseq: x86: Implement rseq_load_u32_u32 selftests/rseq: Implement mm_numa_cid accessors in headers selftests/rseq: Implement numa node id vs mm_numa_cid invariant test selftests/rseq: Implement mm_numa_cid tests
tracing/rseq: Add mm_numa_cid field to rseq_update
fs/binfmt_elf.c | 5 + fs/exec.c | 4 + include/linux/cpumask.h | 60 + include/linux/find.h | 123 +- include/linux/mm.h | 43 + include/linux/mm_types.h | 109 +- include/linux/sched.h | 12 + include/trace/events/rseq.h | 9 +- include/uapi/linux/auxvec.h | 2 + include/uapi/linux/rseq.h | 31 + init/Kconfig | 4 + kernel/fork.c | 11 +- kernel/ptrace.c | 2 +- kernel/rseq.c | 73 +- kernel/sched/core.c | 49 + kernel/sched/sched.h | 192 +++ kernel/signal.c | 2 + lib/find_bit.c | 42 + tools/testing/selftests/rseq/.gitignore | 9 + tools/testing/selftests/rseq/Makefile | 34 +- .../testing/selftests/rseq/basic_numa_test.c | 117 ++ .../selftests/rseq/basic_percpu_ops_test.c | 58 +- tools/testing/selftests/rseq/basic_test.c | 4 + tools/testing/selftests/rseq/compiler.h | 6 + tools/testing/selftests/rseq/param_test.c | 181 ++- tools/testing/selftests/rseq/rseq-abi.h | 31 + tools/testing/selftests/rseq/rseq-arm-bits.h | 505 +++++++ tools/testing/selftests/rseq/rseq-arm.h | 707 +--------- .../testing/selftests/rseq/rseq-arm64-bits.h | 392 ++++++ tools/testing/selftests/rseq/rseq-arm64.h | 532 +------- .../testing/selftests/rseq/rseq-bits-reset.h | 11 + .../selftests/rseq/rseq-bits-template.h | 51 + tools/testing/selftests/rseq/rseq-mips-bits.h | 462 +++++++ tools/testing/selftests/rseq/rseq-mips.h | 652 +-------- tools/testing/selftests/rseq/rseq-ppc-bits.h | 454 +++++++ tools/testing/selftests/rseq/rseq-ppc.h | 629 +-------- .../testing/selftests/rseq/rseq-riscv-bits.h | 410 ++++++ tools/testing/selftests/rseq/rseq-riscv.h | 541 +------- tools/testing/selftests/rseq/rseq-s390-bits.h | 474 +++++++ tools/testing/selftests/rseq/rseq-s390.h | 501 +------ tools/testing/selftests/rseq/rseq-skip.h | 65 - tools/testing/selftests/rseq/rseq-x86-bits.h | 1036 ++++++++++++++ tools/testing/selftests/rseq/rseq-x86.h | 1204 +---------------- tools/testing/selftests/rseq/rseq.c | 91 +- tools/testing/selftests/rseq/rseq.h | 258 +++- .../testing/selftests/rseq/run_param_test.sh | 5 + 46 files changed, 5532 insertions(+), 4661 deletions(-) create mode 100644 tools/testing/selftests/rseq/basic_numa_test.c create mode 100644 tools/testing/selftests/rseq/rseq-arm-bits.h create mode 100644 tools/testing/selftests/rseq/rseq-arm64-bits.h create mode 100644 tools/testing/selftests/rseq/rseq-bits-reset.h create mode 100644 tools/testing/selftests/rseq/rseq-bits-template.h create mode 100644 tools/testing/selftests/rseq/rseq-mips-bits.h create mode 100644 tools/testing/selftests/rseq/rseq-ppc-bits.h create mode 100644 tools/testing/selftests/rseq/rseq-riscv-bits.h create mode 100644 tools/testing/selftests/rseq/rseq-s390-bits.h delete mode 100644 tools/testing/selftests/rseq/rseq-skip.h create mode 100644 tools/testing/selftests/rseq/rseq-x86-bits.h
Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 1/30 selftests/rseq: Fix: Fail thread registration when CONFIG_RSEQ=n
When linking the selftests against a libc which does not handle rseq registration (before 2.35), rseq thread registration silently succeed even with CONFIG_RSEQ=n because it erroneously thinks that libc is handling rseq registration.
This is caused by setting the rseq ownership flag only after the rseq_available() check. It should rather be set before the rseq_available() check.
Set the rseq_size to 0 (error value) immediately after the rseq_available() check fails rather than in the thread registration functions.
--- tools/testing/selftests/rseq/rseq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/rseq/rseq.c +4 -2
@@ -119,9 +119,11 @@ void rseq_init(void) rseq_flags = *libc_rseq_flags_p;return ; } -if (!rseq_available ()) -return ; rseq_ownership =1 ; +if (!rseq_available ()) { + rseq_size =0 ; +return ; + } rseq_offset = (void *)&__rseq_abi -rseq_thread_pointer (); rseq_size =sizeof (struct rseq_abi ); rseq_flags =0 ;
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: Fix: Fail thread registration when CONFIG_RSEQ=n
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 4842dadfc66f627083ec46c4e9a426e805c765f3 Gitweb: https://git.kernel.org/tip/4842dadfc66f627083ec46c4e9a426e805c765f3 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:03 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:10 +01:00
selftests/rseq: Fix: Fail thread registration when CONFIG_RSEQ=n
When linking the selftests against a libc which does not handle rseq registration (before 2.35), rseq thread registration silently succeed even with CONFIG_RSEQ=n because it erroneously thinks that libc is handling rseq registration.
This is caused by setting the rseq ownership flag only after the rseq_available() check. It should rather be set before the rseq_available() check.
Set the rseq_size to 0 (error value) immediately after the rseq_available() check fails rather than in the thread registration functions.
--- tools/testing/selftests/rseq/rseq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/rseq/rseq.c +4 -2
@@ -119,9 +119,11 @@ void rseq_init(void) rseq_flags = *libc_rseq_flags_p;return ; } -if (!rseq_available ()) -return ; rseq_ownership =1 ; +if (!rseq_available ()) { + rseq_size =0 ; +return ; + } rseq_offset = (void *)&__rseq_abi -rseq_thread_pointer (); rseq_size =sizeof (struct rseq_abi ); rseq_flags =0 ;
Mathieu Desnoyers
maintainerPATCH 2/30 rseq: Introduce feature size and alignment ELF auxiliary vector entries
In reply to Mathieu DesnoyersExport the rseq feature size supported by the kernel as well as the required allocation alignment for the rseq per-thread area to user-space through ELF auxiliary vector entries.
This is part of the extensible rseq ABI.
--- fs/binfmt_elf.c | 5 +++++ include/uapi/linux/auxvec.h | 2 ++ include/uapi/linux/rseq.h | 5 +++++ 3 files changed, 12 insertions(+)
fs/binfmt_elf.c +5 -0
@@ -46,6 +46,7 @@#include <linux/cred.h> #include <linux/dax.h> #include <linux/uaccess.h> +#include <linux/rseq.h> #include <asm/param.h> #include <asm/page.h>
@@ -288,6 +289,10 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec,if (bprm->have_execfd) {NEW_AUX_ENT (AT_EXECFD , bprm->execfd); } +#ifdef CONFIG_RSEQ +NEW_AUX_ENT (AT_RSEQ_FEATURE_SIZE , offsetof(struct rseq , end)); +NEW_AUX_ENT (AT_RSEQ_ALIGN , __alignof__(struct rseq )); +#endif #undef NEW_AUX_ENT/* AT_NULL is zero; clear the rest too */ memset(elf_info, 0, (char *)mm->saved_auxv +
include/uapi/linux/auxvec.h +2 -0
@@ -30,6 +30,8 @@* differ from AT_PLATFORM. */ #define AT_RANDOM 25/* address of 16 random bytes */ #define AT_HWCAP2 26/* extension of AT_HWCAP */ +#define AT_RSEQ_FEATURE_SIZE 27/* rseq supported feature size */ +#define AT_RSEQ_ALIGN 28/* rseq allocation alignment */ #define AT_EXECFN 31/* filename of program */
include/uapi/linux/rseq.h +5 -0
@@ -130,6 +130,11 @@ struct rseq {* this thread. */ __u32 flags; + +/* +* Flexible array member at end of structure, after last feature field. +*/ +char end[]; } __attribute__((aligned(4 * sizeof(__u64))));#endif /* _UAPI_LINUX_RSEQ_H */
Signature · 1 line
2.25.1
[tip: sched/core] rseq: Introduce feature size and alignment ELF auxiliary vector entries
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 317c8194e6aeb8b3b573ad139fc2a0635856498e Gitweb: https://git.kernel.org/tip/317c8194e6aeb8b3b573ad139fc2a0635856498e Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:04 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:10 +01:00
rseq: Introduce feature size and alignment ELF auxiliary vector entries
Export the rseq feature size supported by the kernel as well as the required allocation alignment for the rseq per-thread area to user-space through ELF auxiliary vector entries.
This is part of the extensible rseq ABI.
--- fs/binfmt_elf.c | 5 +++++ include/uapi/linux/auxvec.h | 2 ++ include/uapi/linux/rseq.h | 5 +++++ 3 files changed, 12 insertions(+)
fs/binfmt_elf.c +5 -0
@@ -46,6 +46,7 @@#include <linux/cred.h> #include <linux/dax.h> #include <linux/uaccess.h> +#include <linux/rseq.h> #include <asm/param.h> #include <asm/page.h>
@@ -288,6 +289,10 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec,if (bprm->have_execfd) {NEW_AUX_ENT (AT_EXECFD , bprm->execfd); } +#ifdef CONFIG_RSEQ +NEW_AUX_ENT (AT_RSEQ_FEATURE_SIZE , offsetof(struct rseq , end)); +NEW_AUX_ENT (AT_RSEQ_ALIGN , __alignof__(struct rseq )); +#endif #undef NEW_AUX_ENT/* AT_NULL is zero; clear the rest too */ memset(elf_info, 0, (char *)mm->saved_auxv +
include/uapi/linux/auxvec.h +2 -0
@@ -30,6 +30,8 @@* differ from AT_PLATFORM. */ #define AT_RANDOM 25/* address of 16 random bytes */ #define AT_HWCAP2 26/* extension of AT_HWCAP */ +#define AT_RSEQ_FEATURE_SIZE 27/* rseq supported feature size */ +#define AT_RSEQ_ALIGN 28/* rseq allocation alignment */ #define AT_EXECFN 31/* filename of program */
include/uapi/linux/rseq.h +5 -0
@@ -130,6 +130,11 @@ struct rseq {* this thread. */ __u32 flags; + +/* +* Flexible array member at end of structure, after last feature field. +*/ +char end[]; } __attribute__((aligned(4 * sizeof(__u64))));#endif /* _UAPI_LINUX_RSEQ_H */
Re: [PATCH 02/30] rseq: Introduce feature size and alignment ELF auxiliary vector entries
In reply to Mathieu DesnoyersHi Mathieu,
Quoted 7 lines · Mathieu Desnoyers
Export the rseq feature size supported by the kernel as well as the required allocation alignment for the rseq per-thread area to user-space through ELF auxiliary vector entries.
This is part of the extensible rseq ABI.
Signed-off-by Mathieu Desnoyers <[email protected]>
I just bisected a crash with CONFIG_HARDENED_USERCOPY=y and CONFIG_RSEQ=y on 32-bit ARM to this change as commit 317c8194e6ae ("rseq: Introduce feature size and alignment ELF auxiliary vector entries") in the sched/core branch of the -tip tree:
$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- defconfig
$ scripts/config -e HARDENED_USERCOPY -e RSEQ
$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- olddefconfig zImage
$ qemu-system-arm \ -machine virt \ -kernel arch/arm/boot/zImage \ -append "console=ttyAMA0 earlycon" \ -display none \ -initrd rootfs.cpio \ -m 512m \ -nodefaults \ -no-reboot \ -serial mon:stdio ... [ 1.410707] usercopy: Kernel memory exposure attempt detected from SLUB object 'mm_struct' (offset 180, size 176)! [ 1.410964] ------------[ cut here ]------------ [ 1.411076] kernel BUG at mm/usercopy.c:102! [ 1.411163] Internal error: Oops - BUG: 0 [#2] SMP ARM [ 1.411282] Modules linked in: [ 1.411403] CPU: 0 PID: 1 Comm: init Tainted: G D 6.2.0-rc1-00004-g317c8194e6ae #1 [ 1.411606] Hardware name: Generic DT based system [ 1.411712] PC is at usercopy_abort+0x90/0x94 [ 1.411820] LR is at usercopy_abort+0x90/0x94 [ 1.411898] pc : [<c1120b3c>] lr : [<c1120b3c>] psr: 60000013 [ 1.412035] sp : e080de40 ip : 0000bff4 fp : b6f18148 [ 1.412135] r10: 000000b0 r9 : 00000000 r8 : c22d62f4 [ 1.412235] r7 : 00000001 r6 : 000000b0 r5 : 000000b0 r4 : 000000b4 [ 1.412366] r3 : c20b8000 r2 : 00000000 r1 : 00000000 r0 : 00000066 [ 1.412502] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none [ 1.412684] Control: 10c5387d Table: 425a406a DAC: 00000051 [ 1.412796] Register r0 information: non-paged memory [ 1.412914] Register r1 information: NULL pointer [ 1.413022] Register r2 information: NULL pointer [ 1.413134] Register r3 information: slab task_struct start c20b8000 pointer offset 0 size 2176 [ 1.413365] Register r4 information: non-paged memory [ 1.413468] Register r5 information: non-paged memory [ 1.413580] Register r6 information: non-paged memory [ 1.413691] Register r7 information: non-paged memory [ 1.413807] Register r8 information: slab mm_struct start c22d6240 pointer offset 180 size 564 [ 1.414022] Register r9 information: NULL pointer [ 1.414132] Register r10 information: non-paged memory [ 1.414246] Register r11 information: non-paged memory [ 1.414353] Register r12 information: non-paged memory [ 1.414466] Process init (pid: 1, stack limit = 0xfdcb78d5) [ 1.414601] Stack: (0xe080de40 to 0xe080e000) [ 1.414702] de40: c164cf44 c16362a4 c1645208 000000b4 000000b0 00000240 60000000 c04ba5a4 [ 1.414894] de60: 000000b0 d381ab2f c22d62f4 dbc1eac0 000000b0 00000001 c22d63a4 c04bf0a8 [ 1.415073] de80: c22d6278 000000b0 c22d6240 c22d6240 c3007400 c22d62f4 c20b8000 00000000 [ 1.415250] dea0: be953f0c c0522aa8 00000012 00000000 00000002 c22ba3c0 00000002 00000002 [ 1.415410] dec0: 000000b0 c22d62f4 c258b1f8 c1b04cc8 b6f2e09c 004c79fc 005a001d 004c0034 [ 1.415590] dee0: 00000005 0058dbb0 0059e7d8 004c0000 00000034 00000000 00000100 7b30eb30 [ 1.415791] df00: be882ab5 0881c2d0 414ecb5e d381ab2f 00000000 fffffff8 c3007400 c1ba28c4 [ 1.415962] df20: c1d951ac c1ba6b08 00000002 c300745c c1ba287c c04cc468 dbc0efe0 00000005 [ 1.416129] df40: c20b8000 00000000 00000001 00000001 00000100 00000000 c20b8000 d381ab2f [ 1.416315] df60: ffffffff 00000000 c3007400 c20c1000 c1b09214 c1b092a0 00000000 00000000 [ 1.416490] df80: 00000000 c04ccb94 c1b04cc0 c1b09214 00000000 00000000 00000000 c1133d70 [ 1.416655] dfa0: 00000000 c1133d04 00000000 c03001a8 00000000 00000000 00000000 00000000 [ 1.416834] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 1.417014] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000 [ 1.417194] usercopy_abort from __check_heap_object+0xe0/0xfc [ 1.417332] __check_heap_object from __check_object_size+0x25c/0x2dc [ 1.417482] __check_object_size from load_elf_binary+0x11e0/0x1484 [ 1.417637] load_elf_binary from bprm_execve+0x200/0x568 [ 1.417761] bprm_execve from kernel_execve+0x12c/0x1d0 [ 1.417866] kernel_execve from kernel_init+0x6c/0x12c [ 1.417982] kernel_init from ret_from_fork+0x14/0x2c [ 1.418097] Exception stack(0xe080dfb0 to 0xe080dff8) [ 1.418229] dfa0: 00000000 00000000 00000000 00000000 [ 1.418414] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 1.418606] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 1.418742] Code: e98d4001 e30c0f48 e34c0164 ebfff87f (e7f001f2) [ 1.418968] ---[ end trace 0000000000000000 ]--- [ 1.419207] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b [ 1.419558] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
If there is any more information I can provide, I am more than happy to do so. The rootfs is available at [1]; that repo also has a script that can help drive QEMU if you would like.
Cheers,
Nathan
# bad: [b9fdd2ea1a7cff56550990ee920e44f2394da0b6] Add linux-next specific files for 20230103
# good: [69b41ac87e4a664de78a395ff97166f0b2943210] Merge tag 'for-6.2-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
git bisect start 'b9fdd2ea1a7cff56550990ee920e44f2394da0b6' '69b41ac87e4a664de78a395ff97166f0b2943210'
# good: [9d1919d3a74d454501e4431ff50b96bd7419ec7b] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
git bisect good 9d1919d3a74d454501e4431ff50b96bd7419ec7b
# bad: [b705cff481d9ed62a845e9393463b8d57264e75b] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
git bisect bad b705cff481d9ed62a845e9393463b8d57264e75b
# good: [065024e724f54ff6fbdfa980849d845641e2c750] Merge branch 'hwmon-next' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
git bisect good 065024e724f54ff6fbdfa980849d845641e2c750
# good: [a6863e831038c4bea7119c912c06442284d13a79] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
git bisect good a6863e831038c4bea7119c912c06442284d13a79
# bad: [08d1485bcd896e9516da6585c6dbce18ff466694] Merge branch into tip/master: 'perf/urgent'
git bisect bad 08d1485bcd896e9516da6585c6dbce18ff466694
# bad: [b344b8f2d88dbf095caf97ac57fd3645843fa70f] selftests/rseq: Add mm_numa_cid to test script
git bisect bad b344b8f2d88dbf095caf97ac57fd3645843fa70f
# bad: [18c2355838e76788f61849f4d83513b103d68b95] selftests/rseq: Implement rseq mm_cid field support
git bisect bad 18c2355838e76788f61849f4d83513b103d68b95
# bad: [cbae6bac29a8c5cf2f1cb5c6bce35af00cec164b] rseq: Extend struct rseq with numa node id
git bisect bad cbae6bac29a8c5cf2f1cb5c6bce35af00cec164b
# good: [4842dadfc66f627083ec46c4e9a426e805c765f3] selftests/rseq: Fix: Fail thread registration when CONFIG_RSEQ=n
git bisect good 4842dadfc66f627083ec46c4e9a426e805c765f3
# bad: [ee3e3ac05c2631ce1f12d88c9cc9a092f8fe947a] rseq: Introduce extensible rseq ABI
git bisect bad ee3e3ac05c2631ce1f12d88c9cc9a092f8fe947a
# bad: [317c8194e6aeb8b3b573ad139fc2a0635856498e] rseq: Introduce feature size and alignment ELF auxiliary vector entries
git bisect bad 317c8194e6aeb8b3b573ad139fc2a0635856498e
# first bad commit: [317c8194e6aeb8b3b573ad139fc2a0635856498e] rseq: Introduce feature size and alignment ELF auxiliary vector entries
Mathieu Desnoyers
maintainerRe: [PATCH 02/30] rseq: Introduce feature size and alignment ELF auxiliary vector entries
Quoted 7 lines · Nathan Chancellor
Hi Mathieu,
Quoted 4 lines · Mathieu Desnoyers
Export the rseq feature size supported by the kernel as well as the required allocation alignment for the rseq per-thread area to user-space through ELF auxiliary vector entries.
Quoted 8 lines
Quoted 3 lines
This is part of the extensible rseq ABI.
Signed-off-by Mathieu Desnoyers <[email protected]>I just bisected a crash with
CONFIG_HARDENED_USERCOPY=yandCONFIG_RSEQ=yon 32-bit ARM to this change as commit317c8194e6ae("rseq: Introduce feature size and alignment ELF auxiliary vector entries") in the sched/core branch of the -tip tree:
I suspect I missed bumping
include/linux/auxvec.h:
#define AT_VECTOR_SIZE_BASE 20 /* NEW_AUX_ENT entries in auxiliary table */
from 20 to 22. I'm doing some testing and will send a patch soon.
Thanks for the bug report!
Mathieu
Quoted 114 lines
$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- defconfig$ scripts/config -e HARDENED_USERCOPY -e RSEQ$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- olddefconfig zImage$ qemu-system-arm \(quoted diff) +0
-9-machine virt \ -kernel arch/arm/boot/zImage \ -append "console=ttyAMA0 earlycon" \ -display none \ -initrd rootfs.cpio \ -m 512m \ -nodefaults \ -no-reboot \ -serial mon:stdio[ 1.410707] usercopy: Kernel memory exposure attempt detected from SLUB object 'mm_struct' (offset 180, size 176)! [ 1.410964] ------------[ cut here ]------------ [ 1.411076] kernel BUG at mm/usercopy.c:102! [ 1.411163] Internal error: Oops - BUG: 0 [#2] SMP ARM [ 1.411282] Modules linked in: [ 1.411403] CPU: 0 PID: 1 Comm: init Tainted: G D 6.2.0-rc1-00004-g317c8194e6ae #1 [ 1.411606] Hardware name: Generic DT based system [ 1.411712] PC is at usercopy_abort+0x90/0x94 [ 1.411820] LR is at usercopy_abort+0x90/0x94 [ 1.411898] pc : [<c1120b3c>] lr : [<c1120b3c>] psr: 60000013 [ 1.412035] sp : e080de40 ip : 0000bff4 fp : b6f18148 [ 1.412135] r10: 000000b0 r9 : 00000000 r8 : c22d62f4 [ 1.412235] r7 : 00000001 r6 : 000000b0 r5 : 000000b0 r4 : 000000b4 [ 1.412366] r3 : c20b8000 r2 : 00000000 r1 : 00000000 r0 : 00000066 [ 1.412502] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none [ 1.412684] Control: 10c5387d Table: 425a406a DAC: 00000051 [ 1.412796] Register r0 information: non-paged memory [ 1.412914] Register r1 information: NULL pointer [ 1.413022] Register r2 information: NULL pointer [ 1.413134] Register r3 information: slab task_struct start c20b8000 pointer offset 0 size 2176 [ 1.413365] Register r4 information: non-paged memory [ 1.413468] Register r5 information: non-paged memory [ 1.413580] Register r6 information: non-paged memory [ 1.413691] Register r7 information: non-paged memory [ 1.413807] Register r8 information: slab mm_struct start c22d6240 pointer offset 180 size 564 [ 1.414022] Register r9 information: NULL pointer [ 1.414132] Register r10 information: non-paged memory [ 1.414246] Register r11 information: non-paged memory [ 1.414353] Register r12 information: non-paged memory [ 1.414466] Process init (pid: 1, stack limit = 0xfdcb78d5) [ 1.414601] Stack: (0xe080de40 to 0xe080e000) [ 1.414702] de40: c164cf44 c16362a4 c1645208 000000b4 000000b0 00000240 60000000 c04ba5a4 [ 1.414894] de60: 000000b0 d381ab2f c22d62f4 dbc1eac0 000000b0 00000001 c22d63a4 c04bf0a8 [ 1.415073] de80: c22d6278 000000b0 c22d6240 c22d6240 c3007400 c22d62f4 c20b8000 00000000 [ 1.415250] dea0: be953f0c c0522aa8 00000012 00000000 00000002 c22ba3c0 00000002 00000002 [ 1.415410] dec0: 000000b0 c22d62f4 c258b1f8 c1b04cc8 b6f2e09c 004c79fc 005a001d 004c0034 [ 1.415590] dee0: 00000005 0058dbb0 0059e7d8 004c0000 00000034 00000000 00000100 7b30eb30 [ 1.415791] df00: be882ab5 0881c2d0 414ecb5e d381ab2f 00000000 fffffff8 c3007400 c1ba28c4 [ 1.415962] df20: c1d951ac c1ba6b08 00000002 c300745c c1ba287c c04cc468 dbc0efe0 00000005 [ 1.416129] df40: c20b8000 00000000 00000001 00000001 00000100 00000000 c20b8000 d381ab2f [ 1.416315] df60: ffffffff 00000000 c3007400 c20c1000 c1b09214 c1b092a0 00000000 00000000 [ 1.416490] df80: 00000000 c04ccb94 c1b04cc0 c1b09214 00000000 00000000 00000000 c1133d70 [ 1.416655] dfa0: 00000000 c1133d04 00000000 c03001a8 00000000 00000000 00000000 00000000 [ 1.416834] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 1.417014] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000 [ 1.417194] usercopy_abort from __check_heap_object+0xe0/0xfc [ 1.417332] __check_heap_object from __check_object_size+0x25c/0x2dc [ 1.417482] __check_object_size from load_elf_binary+0x11e0/0x1484 [ 1.417637] load_elf_binary from bprm_execve+0x200/0x568 [ 1.417761] bprm_execve from kernel_execve+0x12c/0x1d0 [ 1.417866] kernel_execve from kernel_init+0x6c/0x12c [ 1.417982] kernel_init from ret_from_fork+0x14/0x2c [ 1.418097] Exception stack(0xe080dfb0 to 0xe080dff8) [ 1.418229] dfa0: 00000000 00000000 00000000 00000000 [ 1.418414] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 1.418606] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 1.418742] Code: e98d4001 e30c0f48 e34c0164 ebfff87f (e7f001f2) [ 1.418968] ---[ end trace 0000000000000000 ]--- [ 1.419207] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b [ 1.419558] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---If there is any more information I can provide, I am more than happy to do so. The rootfs is available at [1]; that repo also has a script that can help drive QEMU if you would like.
Cheers,
Nathan# bad: [
b9fdd2ea1a7cff56550990ee920e44f2394da0b6] Add linux-next specific files for 20230103
# good: [69b41ac87e4a664de78a395ff97166f0b2943210] Merge tag 'for-6.2-rc2-tag' ofgit://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
git bisect start 'b9fdd2ea1a7cff56550990ee920e44f2394da0b6' '69b41ac87e4a664de78a395ff97166f0b2943210'
# good: [9d1919d3a74d454501e4431ff50b96bd7419ec7b] Merge branch 'for-next' ofgit://git.kernel.org/pub/scm/linux/kernel/git/cel/linux
git bisect good9d1919d3a74d454501e4431ff50b96bd7419ec7b
# bad: [b705cff481d9ed62a845e9393463b8d57264e75b] Merge branch 'for-next' ofgit://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
git bisect badb705cff481d9ed62a845e9393463b8d57264e75b
# good: [065024e724f54ff6fbdfa980849d845641e2c750] Merge branch 'hwmon-next' ofgit://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
git bisect good065024e724f54ff6fbdfa980849d845641e2c750
# good: [a6863e831038c4bea7119c912c06442284d13a79] Merge branch 'for-next' ofgit://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
git bisect gooda6863e831038c4bea7119c912c06442284d13a79
# bad: [08d1485bcd896e9516da6585c6dbce18ff466694] Merge branch into tip/master: 'perf/urgent'
git bisect bad08d1485bcd896e9516da6585c6dbce18ff466694
# bad: [b344b8f2d88dbf095caf97ac57fd3645843fa70f] selftests/rseq: Addmm_numa_cidto test script
git bisect badb344b8f2d88dbf095caf97ac57fd3645843fa70f
# bad: [18c2355838e76788f61849f4d83513b103d68b95] selftests/rseq: Implement rseqmm_cidfield support
git bisect bad18c2355838e76788f61849f4d83513b103d68b95
# bad: [cbae6bac29a8c5cf2f1cb5c6bce35af00cec164b] rseq: Extend struct rseq with numa node id
git bisect badcbae6bac29a8c5cf2f1cb5c6bce35af00cec164b
# good: [4842dadfc66f627083ec46c4e9a426e805c765f3] selftests/rseq: Fix: Fail thread registration whenCONFIG_RSEQ=n
git bisect good4842dadfc66f627083ec46c4e9a426e805c765f3
# bad: [ee3e3ac05c2631ce1f12d88c9cc9a092f8fe947a] rseq: Introduce extensible rseq ABI
git bisect badee3e3ac05c2631ce1f12d88c9cc9a092f8fe947a
# bad: [317c8194e6aeb8b3b573ad139fc2a0635856498e] rseq: Introduce feature size and alignment ELF auxiliary vector entries
git bisect bad317c8194e6aeb8b3b573ad139fc2a0635856498e# first bad commit: [317c8194e6aeb8b3b573ad139fc2a0635856498e] rseq: Introduce feature size and alignment ELF auxiliary vector entries
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Mathieu Desnoyers
maintainerPATCH 3/30 rseq: Introduce extensible rseq ABI
In reply to Mathieu DesnoyersIntroduce the extensible rseq ABI, where the feature size supported by the kernel and the required alignment are communicated to user-space through ELF auxiliary vectors.
This allows user-space to call rseq registration with a rseq_len of either 32 bytes for the original struct rseq size (which includes padding), or larger.
If rseq_len is larger than 32 bytes, then it must be large enough to contain the feature size communicated to user-space through ELF auxiliary vectors.
---
Changes since v4:
- Accept original rseq alignment for original rseq size.
--- include/linux/sched.h | 4 ++++ kernel/ptrace.c | 2 +- kernel/rseq.c | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 8 deletions(-)
include/linux/sched.h +4 -0
@@ -1305,6 +1305,7 @@ struct task_struct {#ifdef CONFIG_RSEQ struct rseq __user *rseq; +u32 rseq_len;u32 rseq_sig;/* * RmW on rseq_event_mask must be performed atomically
@@ -2355,10 +2356,12 @@ static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags) {if (clone_flags &CLONE_VM ) { t->rseq =NULL ; + t->rseq_len =0 ; t->rseq_sig =0 ; t->rseq_event_mask =0 ; }else { t->rseq = current->rseq; + t->rseq_len = current->rseq_len; t->rseq_sig = current->rseq_sig; t->rseq_event_mask = current->rseq_event_mask; }
@@ -2367,6 +2370,7 @@ static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)static inline void rseq_execve (struct task_struct *t) { t->rseq =NULL ; + t->rseq_len =0 ; t->rseq_sig =0 ; t->rseq_event_mask =0 ; }
kernel/ptrace.c +1 -1
@@ -813,7 +813,7 @@ static long ptrace_get_rseq_configuration(struct task_struct *task, {struct ptrace_rseq_configuration conf = { .rseq_abi_pointer = (u64 )(uintptr_t )task->rseq, - .rseq_abi_size =sizeof (*task->rseq), + .rseq_abi_size = task->rseq_len, .signature = task->rseq_sig, .flags =0 , };
kernel/rseq.c +30 -7
@@ -18,6 +18,9 @@#define CREATE_TRACE_POINTS #include <trace/events/rseq.h> +/* The original rseq structure size (including padding) is 32 bytes. */ +#define ORIG_RSEQ_SIZE 32 +#define RSEQ_CS_NO_RESTART_FLAGS (RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT | \ RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL | \ RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE)
@@ -87,10 +90,15 @@ static int rseq_update_cpu_id(struct task_struct *t)u32 cpu_id =raw_smp_processor_id ();struct rseq __user *rseq = t->rseq; -if (!user_write_access_begin (rseq,sizeof (*rseq))) +if (!user_write_access_begin (rseq, t->rseq_len)) goto efault;unsafe_put_user (cpu_id, &rseq->cpu_id_start, efault_end);unsafe_put_user (cpu_id, &rseq->cpu_id, efault_end); +/* +* Additional feature fields added after ORIG_RSEQ_SIZE +* need to be conditionally updated only if +* t->rseq_len != ORIG_RSEQ_SIZE. +*/ user_write_access_end ();trace_rseq_update (t);return 0 ;
@@ -117,6 +125,11 @@ static int rseq_reset_rseq_cpu_id(struct task_struct *t)*/ if (put_user (cpu_id, &t->rseq->cpu_id))return -EFAULT ; +/* +* Additional feature fields added after ORIG_RSEQ_SIZE +* need to be conditionally reset only if +* t->rseq_len != ORIG_RSEQ_SIZE. +*/ return 0 ; }
@@ -329,7 +342,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,/* Unregister rseq for current thread. */ if (current->rseq != rseq || !current->rseq)return -EINVAL ; -if (rseq_len !=sizeof (*rseq)) +if (rseq_len != current->rseq_len)return -EINVAL ;if (current->rseq_sig != sig)return -EPERM ;
@@ -338,6 +351,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,return ret; current->rseq =NULL ; current->rseq_sig =0 ; + current->rseq_len =0 ;return 0 ; }
@@ -350,7 +364,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,* the provided address differs from the prior * one. */ -if (current->rseq != rseq || rseq_len !=sizeof (*rseq)) +if (current->rseq != rseq || rseq_len != current->rseq_len)return -EINVAL ;if (current->rseq_sig != sig)return -EPERM ;
@@ -359,15 +373,24 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len, }/* -* If there was no rseq previously registered, -* ensure the provided rseq is properly aligned and valid. +* If there was no rseq previously registered, ensure the provided rseq +* is properly aligned, as communcated to user-space through the ELF +* auxiliary vector AT_RSEQ_ALIGN. If rseq_len is the original rseq +* size, the required alignment is the original struct rseq alignment. +* +* In order to be valid, rseq_len is either the original rseq size, or +* large enough to contain all supported fields, as communicated to +* user-space through the ELF auxiliary vector AT_RSEQ_FEATURE_SIZE. */ - if (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) || - rseq_len !=sizeof (*rseq)) +if (rseq_len <ORIG_RSEQ_SIZE || + (rseq_len ==ORIG_RSEQ_SIZE && !IS_ALIGNED ((unsigned long )rseq,ORIG_RSEQ_SIZE )) || + (rseq_len != ORIG_RSEQ_SIZE && (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) || + rseq_len < offsetof(struct rseq , end))))return -EINVAL ;if (!access_ok (rseq, rseq_len))return -EFAULT ; current->rseq = rseq; + current->rseq_len = rseq_len; current->rseq_sig = sig;/* * If rseq was previously inactive, and has just been
Signature · 1 line
2.25.1
[tip: sched/core] rseq: Introduce extensible rseq ABI
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: ee3e3ac05c2631ce1f12d88c9cc9a092f8fe947a Gitweb: https://git.kernel.org/tip/ee3e3ac05c2631ce1f12d88c9cc9a092f8fe947a Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:05 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:10 +01:00
rseq: Introduce extensible rseq ABI
Introduce the extensible rseq ABI, where the feature size supported by the kernel and the required alignment are communicated to user-space through ELF auxiliary vectors.
This allows user-space to call rseq registration with a rseq_len of either 32 bytes for the original struct rseq size (which includes padding), or larger.
If rseq_len is larger than 32 bytes, then it must be large enough to contain the feature size communicated to user-space through ELF auxiliary vectors.
--- include/linux/sched.h | 4 ++++ kernel/ptrace.c | 2 +- kernel/rseq.c | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 8 deletions(-)
include/linux/sched.h +4 -0
@@ -1302,6 +1302,7 @@ struct task_struct {#ifdef CONFIG_RSEQ struct rseq __user *rseq; +u32 rseq_len;u32 rseq_sig;/* * RmW on rseq_event_mask must be performed atomically
@@ -2352,10 +2353,12 @@ static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags) {if (clone_flags &CLONE_VM ) { t->rseq =NULL ; + t->rseq_len =0 ; t->rseq_sig =0 ; t->rseq_event_mask =0 ; }else { t->rseq = current->rseq; + t->rseq_len = current->rseq_len; t->rseq_sig = current->rseq_sig; t->rseq_event_mask = current->rseq_event_mask; }
@@ -2364,6 +2367,7 @@ static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)static inline void rseq_execve (struct task_struct *t) { t->rseq =NULL ; + t->rseq_len =0 ; t->rseq_sig =0 ; t->rseq_event_mask =0 ; }
kernel/ptrace.c +1 -1
@@ -813,7 +813,7 @@ static long ptrace_get_rseq_configuration(struct task_struct *task, {struct ptrace_rseq_configuration conf = { .rseq_abi_pointer = (u64 )(uintptr_t )task->rseq, - .rseq_abi_size =sizeof (*task->rseq), + .rseq_abi_size = task->rseq_len, .signature = task->rseq_sig, .flags =0 , };
kernel/rseq.c +30 -7
@@ -18,6 +18,9 @@#define CREATE_TRACE_POINTS #include <trace/events/rseq.h> +/* The original rseq structure size (including padding) is 32 bytes. */ +#define ORIG_RSEQ_SIZE 32 +#define RSEQ_CS_NO_RESTART_FLAGS (RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT | \ RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL | \ RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE)
@@ -87,10 +90,15 @@ static int rseq_update_cpu_id(struct task_struct *t)u32 cpu_id =raw_smp_processor_id ();struct rseq __user *rseq = t->rseq; -if (!user_write_access_begin (rseq,sizeof (*rseq))) +if (!user_write_access_begin (rseq, t->rseq_len)) goto efault;unsafe_put_user (cpu_id, &rseq->cpu_id_start, efault_end);unsafe_put_user (cpu_id, &rseq->cpu_id, efault_end); +/* +* Additional feature fields added after ORIG_RSEQ_SIZE +* need to be conditionally updated only if +* t->rseq_len != ORIG_RSEQ_SIZE. +*/ user_write_access_end ();trace_rseq_update (t);return 0 ;
@@ -117,6 +125,11 @@ static int rseq_reset_rseq_cpu_id(struct task_struct *t)*/ if (put_user (cpu_id, &t->rseq->cpu_id))return -EFAULT ; +/* +* Additional feature fields added after ORIG_RSEQ_SIZE +* need to be conditionally reset only if +* t->rseq_len != ORIG_RSEQ_SIZE. +*/ return 0 ; }
@@ -344,7 +357,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,/* Unregister rseq for current thread. */ if (current->rseq != rseq || !current->rseq)return -EINVAL ; -if (rseq_len !=sizeof (*rseq)) +if (rseq_len != current->rseq_len)return -EINVAL ;if (current->rseq_sig != sig)return -EPERM ;
@@ -353,6 +366,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,return ret; current->rseq =NULL ; current->rseq_sig =0 ; + current->rseq_len =0 ;return 0 ; }
@@ -365,7 +379,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,* the provided address differs from the prior * one. */ -if (current->rseq != rseq || rseq_len !=sizeof (*rseq)) +if (current->rseq != rseq || rseq_len != current->rseq_len)return -EINVAL ;if (current->rseq_sig != sig)return -EPERM ;
@@ -374,15 +388,24 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len, }/* -* If there was no rseq previously registered, -* ensure the provided rseq is properly aligned and valid. +* If there was no rseq previously registered, ensure the provided rseq +* is properly aligned, as communcated to user-space through the ELF +* auxiliary vector AT_RSEQ_ALIGN. If rseq_len is the original rseq +* size, the required alignment is the original struct rseq alignment. +* +* In order to be valid, rseq_len is either the original rseq size, or +* large enough to contain all supported fields, as communicated to +* user-space through the ELF auxiliary vector AT_RSEQ_FEATURE_SIZE. */ - if (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) || - rseq_len !=sizeof (*rseq)) +if (rseq_len <ORIG_RSEQ_SIZE || + (rseq_len ==ORIG_RSEQ_SIZE && !IS_ALIGNED ((unsigned long )rseq,ORIG_RSEQ_SIZE )) || + (rseq_len != ORIG_RSEQ_SIZE && (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) || + rseq_len < offsetof(struct rseq , end))))return -EINVAL ;if (!access_ok (rseq, rseq_len))return -EFAULT ; current->rseq = rseq; + current->rseq_len = rseq_len; current->rseq_sig = sig;/* * If rseq was previously inactive, and has just been
Mathieu Desnoyers
maintainerPATCH 4/30 rseq: Extend struct rseq with numa node id
In reply to Mathieu DesnoyersAdding the NUMA node id to struct rseq is a straightforward thing to do, and a good way to figure out if anything in the user-space ecosystem prevents extending struct rseq.
This NUMA node id field allows memory allocators such as tcmalloc to take advantage of fast access to the current NUMA node id to perform NUMA-aware memory allocation.
It can also be useful for implementing fast-paths for NUMA-aware user-space mutexes.
It also allows implementing getcpu(2) purely in user-space.
---
Changes since v4:
- Use __entry->cpu_id as argument for cpu_to_node() in the rseq_update tracepoint.
--- include/trace/events/rseq.h | 4 +++- include/uapi/linux/rseq.h | 8 ++++++++ kernel/rseq.c | 19 +++++++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-)
include/trace/events/rseq.h +3 -1
@@ -16,13 +16,15 @@ TRACE_EVENT(rseq_update,TP_STRUCT__entry (__field (s32 ,cpu_id ) +__field (s32, node_id) ),TP_fast_assign ( __entry->cpu_id = raw_smp_processor_id(); + __entry->node_id =cpu_to_node (__entry->cpu_id); ), -TP_printk ("cpu_id=%d" , __entry->cpu_id) +TP_printk ("cpu_id=%d node_id=%d" , __entry->cpu_id, __entry->node_id) ); TRACE_EVENT(rseq_ip_fixup,
include/uapi/linux/rseq.h +8 -0
@@ -131,6 +131,14 @@ struct rseq {*/ __u32 flags; +/* +* Restartable sequences node_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. Contains the current NUMA node ID. +*/ +__u32 node_id; +/* * Flexible array member at end of structure, after last feature field. */
kernel/rseq.c +13 -6
@@ -85,15 +85,17 @@* F1. <failure> */ -static int rseq_update_cpu_id (struct task_struct *t) +static int rseq_update_cpu_node_id (struct task_struct *t) { -u32 cpu_id =raw_smp_processor_id ();struct rseq __user *rseq = t->rseq; +u32 cpu_id =raw_smp_processor_id (); +u32 node_id =cpu_to_node (cpu_id);if (!user_write_access_begin (rseq, t->rseq_len)) goto efault;unsafe_put_user (cpu_id, &rseq->cpu_id_start, efault_end);unsafe_put_user (cpu_id, &rseq->cpu_id, efault_end); +unsafe_put_user (node_id, &rseq->node_id, efault_end);/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally updated only if
@@ -109,9 +111,9 @@ static int rseq_update_cpu_id(struct task_struct *t)return -EFAULT ; } -static int rseq_reset_rseq_cpu_id (struct task_struct *t) +static int rseq_reset_rseq_cpu_node_id (struct task_struct *t) { -u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED ; +u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED , node_id =0 ;/* * Reset cpu_id_start to its initial state (0).
@@ -125,6 +127,11 @@ static int rseq_reset_rseq_cpu_id(struct task_struct *t)*/ if (put_user (cpu_id, &t->rseq->cpu_id))return -EFAULT ; +/* +* Reset node_id to its initial state (0). +*/ +if (put_user (node_id, &t->rseq->node_id)) +return -EFAULT ;/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally reset only if
@@ -299,7 +306,7 @@ void __rseq_handle_notify_resume(struct ksignal *ksig, struct pt_regs *regs)if (unlikely (ret <0 )) goto error; } -if (unlikely (rseq_update_cpu_id (t))) +if (unlikely (rseq_update_cpu_node_id (t))) goto error;return ;
@@ -346,7 +353,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,return -EINVAL ;if (current->rseq_sig != sig)return -EPERM ; - ret =rseq_reset_rseq_cpu_id (current); + ret =rseq_reset_rseq_cpu_node_id (current);if (ret)return ret; current->rseq =NULL ;
Signature · 1 line
2.25.1
[tip: sched/core] rseq: Extend struct rseq with numa node id
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: cbae6bac29a8c5cf2f1cb5c6bce35af00cec164b Gitweb: https://git.kernel.org/tip/cbae6bac29a8c5cf2f1cb5c6bce35af00cec164b Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:06 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:10 +01:00
rseq: Extend struct rseq with numa node id
Adding the NUMA node id to struct rseq is a straightforward thing to do, and a good way to figure out if anything in the user-space ecosystem prevents extending struct rseq.
This NUMA node id field allows memory allocators such as tcmalloc to take advantage of fast access to the current NUMA node id to perform NUMA-aware memory allocation.
It can also be useful for implementing fast-paths for NUMA-aware user-space mutexes.
It also allows implementing getcpu(2) purely in user-space.
--- include/trace/events/rseq.h | 4 +++- include/uapi/linux/rseq.h | 8 ++++++++ kernel/rseq.c | 19 +++++++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-)
include/trace/events/rseq.h +3 -1
@@ -16,13 +16,15 @@ TRACE_EVENT(rseq_update,TP_STRUCT__entry (__field (s32 ,cpu_id ) +__field (s32, node_id) ),TP_fast_assign ( __entry->cpu_id = raw_smp_processor_id(); + __entry->node_id =cpu_to_node (__entry->cpu_id); ), -TP_printk ("cpu_id=%d" , __entry->cpu_id) +TP_printk ("cpu_id=%d node_id=%d" , __entry->cpu_id, __entry->node_id) ); TRACE_EVENT(rseq_ip_fixup,
include/uapi/linux/rseq.h +8 -0
@@ -132,6 +132,14 @@ struct rseq {__u32 flags;/* +* Restartable sequences node_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. Contains the current NUMA node ID. +*/ +__u32 node_id; + +/* * Flexible array member at end of structure, after last feature field. */ char end[];
kernel/rseq.c +13 -6
@@ -85,15 +85,17 @@* F1. <failure> */ -static int rseq_update_cpu_id (struct task_struct *t) +static int rseq_update_cpu_node_id (struct task_struct *t) { -u32 cpu_id =raw_smp_processor_id ();struct rseq __user *rseq = t->rseq; +u32 cpu_id =raw_smp_processor_id (); +u32 node_id =cpu_to_node (cpu_id);if (!user_write_access_begin (rseq, t->rseq_len)) goto efault;unsafe_put_user (cpu_id, &rseq->cpu_id_start, efault_end);unsafe_put_user (cpu_id, &rseq->cpu_id, efault_end); +unsafe_put_user (node_id, &rseq->node_id, efault_end);/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally updated only if
@@ -109,9 +111,9 @@ efault:return -EFAULT ; } -static int rseq_reset_rseq_cpu_id (struct task_struct *t) +static int rseq_reset_rseq_cpu_node_id (struct task_struct *t) { -u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED ; +u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED , node_id =0 ;/* * Reset cpu_id_start to its initial state (0).
@@ -126,6 +128,11 @@ static int rseq_reset_rseq_cpu_id(struct task_struct *t)if (put_user (cpu_id, &t->rseq->cpu_id))return -EFAULT ;/* +* Reset node_id to its initial state (0). +*/ +if (put_user (node_id, &t->rseq->node_id)) +return -EFAULT ; +/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally reset only if * t->rseq_len != ORIG_RSEQ_SIZE.
@@ -314,7 +321,7 @@ void __rseq_handle_notify_resume(struct ksignal *ksig, struct pt_regs *regs)if (unlikely (ret <0 )) goto error; } -if (unlikely (rseq_update_cpu_id (t))) +if (unlikely (rseq_update_cpu_node_id (t))) goto error;return ;
@@ -361,7 +368,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,return -EINVAL ;if (current->rseq_sig != sig)return -EPERM ; - ret =rseq_reset_rseq_cpu_id (current); + ret =rseq_reset_rseq_cpu_node_id (current);if (ret)return ret; current->rseq =NULL ;
Mathieu Desnoyers
maintainerPATCH 5/30 selftests/rseq: Use ELF auxiliary vector for extensible rseq
In reply to Mathieu DesnoyersUse the ELF auxiliary vector AT_RSEQ_FEATURE_SIZE to detect the RSEQ features supported by the kernel.
--- tools/testing/selftests/rseq/rseq-abi.h | 5 ++ tools/testing/selftests/rseq/rseq.c | 67 ++++++++++++++++++++++--- tools/testing/selftests/rseq/rseq.h | 18 +++++-- 3 files changed, 78 insertions(+), 12 deletions(-)
tools/testing/selftests/rseq/rseq-abi.h +5 -0
@@ -146,6 +146,11 @@ struct rseq_abi {* this thread. */ __u32 flags; + +/* +* Flexible array member at end of structure, after last feature field. +*/ +char end[]; } __attribute__((aligned(4 * sizeof(__u64))));#endif /* _RSEQ_ABI_H */
tools/testing/selftests/rseq/rseq.c +59 -8
129 lines not on this page · raw message
tools/testing/selftests/rseq/rseq.h +14 -4
@@ -47,14 +47,24 @@#include "rseq-thread-pointer.h" -/* Offset from the thread pointer to the rseq area. */ +/* Offset from the thread pointer to the rseq area. */ extern ptrdiff_t rseq_offset; -/* Size of the registered rseq area. 0 if the registration was -unsuccessful. */ + +/* +* Size of the registered rseq area. 0 if the registration was +* unsuccessful. +*/ extern unsigned int rseq_size; -/* Flags used during rseq registration. */ + +/* Flags used during rseq registration. */ extern unsigned int rseq_flags; +/* +* rseq feature size supported by the kernel. 0 if the registration was +* unsuccessful. +*/ +extern unsigned int rseq_feature_size; +static inline struct rseq_abi *rseq_get_abi (void ) {return (struct rseq_abi *) ((uintptr_t )rseq_thread_pointer () + rseq_offset);
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: Use ELF auxiliary vector for extensible rseq
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 03f5c0272d1b59343144e199becc911dae52c37e Gitweb: https://git.kernel.org/tip/03f5c0272d1b59343144e199becc911dae52c37e Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:07 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:11 +01:00
selftests/rseq: Use ELF auxiliary vector for extensible rseq
Use the ELF auxiliary vector AT_RSEQ_FEATURE_SIZE to detect the RSEQ features supported by the kernel.
--- tools/testing/selftests/rseq/rseq-abi.h | 5 ++- tools/testing/selftests/rseq/rseq.c | 67 +++++++++++++++++++++--- tools/testing/selftests/rseq/rseq.h | 18 ++++-- 3 files changed, 78 insertions(+), 12 deletions(-)
tools/testing/selftests/rseq/rseq-abi.h +5 -0
@@ -146,6 +146,11 @@ struct rseq_abi {* this thread. */ __u32 flags; + +/* +* Flexible array member at end of structure, after last feature field. +*/ +char end[]; } __attribute__((aligned(4 * sizeof(__u64))));#endif /* _RSEQ_ABI_H */
tools/testing/selftests/rseq/rseq.c +59 -8
129 lines not on this page · raw message
tools/testing/selftests/rseq/rseq.h +14 -4
@@ -47,14 +47,24 @@#include "rseq-thread-pointer.h" -/* Offset from the thread pointer to the rseq area. */ +/* Offset from the thread pointer to the rseq area. */ extern ptrdiff_t rseq_offset; -/* Size of the registered rseq area. 0 if the registration was -unsuccessful. */ + +/* +* Size of the registered rseq area. 0 if the registration was +* unsuccessful. +*/ extern unsigned int rseq_size; -/* Flags used during rseq registration. */ + +/* Flags used during rseq registration. */ extern unsigned int rseq_flags; +/* +* rseq feature size supported by the kernel. 0 if the registration was +* unsuccessful. +*/ +extern unsigned int rseq_feature_size; +static inline struct rseq_abi *rseq_get_abi (void ) {return (struct rseq_abi *) ((uintptr_t )rseq_thread_pointer () + rseq_offset);
Re: [PATCH 05/30] selftests/rseq: Use ELF auxiliary vector for extensible rseq
In reply to Mathieu Desnoyers* Mathieu Desnoyers:
Quoted 5 lines
tools/testing/selftests/rseq/rseq.c +5
-0+static +unsigned int get_rseq_feature_size (void ) +{ +unsigned long auxv_rseq_feature_size, auxv_rseq_align; +
tools/testing/selftests/rseq/rseq.c int rseq_unregister_current_thread(void) · line 148
Quoted 10 lines
tools/testing/selftests/rseq/rseq.c +10
-0+ auxv_rseq_align =getauxval (AT_RSEQ_ALIGN ); +assert (!auxv_rseq_align || auxv_rseq_align <=RSEQ_THREAD_AREA_ALLOC_SIZE ); + + auxv_rseq_feature_size =getauxval (AT_RSEQ_FEATURE_SIZE ); +assert (!auxv_rseq_feature_size || auxv_rseq_feature_size <=RSEQ_THREAD_AREA_ALLOC_SIZE ); +if (auxv_rseq_feature_size) +return auxv_rseq_feature_size; +else +return ORIG_RSEQ_FEATURE_SIZE ; +}
Do you intend to use the auxiliary vector as the userspace handshake for glibc-managed rseq, too? I don't think it works if the kernel overtakes glibc. Or is there some other approach shown in the series that I missed?
Maybe we should just skip the existing padding and use it only for some vaguely kernel-internal purpose (say through a vDSO helper), so that it is less of an issue how to communicate the presence of these fields to userspace.
Mathieu Desnoyers
maintainerRe: [PATCH 05/30] selftests/rseq: Use ELF auxiliary vector for extensible rseq
Quoted 12 lines · Florian Weimer
* Mathieu Desnoyers:
Quoted 10 lines
tools/testing/selftests/rseq/rseq.c +10
-0+static +unsigned int get_rseq_feature_size (void ) +{ +unsigned long auxv_rseq_feature_size, auxv_rseq_align; + + auxv_rseq_align =getauxval (AT_RSEQ_ALIGN ); +assert (!auxv_rseq_align || auxv_rseq_align <=RSEQ_THREAD_AREA_ALLOC_SIZE ); + + auxv_rseq_feature_size =getauxval (AT_RSEQ_FEATURE_SIZE ); +assert (!auxv_rseq_feature_size || auxv_rseq_feature_size <=RSEQ_THREAD_AREA_ALLOC_SIZE );
Quoted 8 lines
tools/testing/selftests/rseq/rseq.c int rseq_unregister_current_thread(void) · line 148
Quoted 5 lines
tools/testing/selftests/rseq/rseq.c +5
-0+if (auxv_rseq_feature_size) +return auxv_rseq_feature_size; +else +return ORIG_RSEQ_FEATURE_SIZE ; +}Do you intend to use the auxiliary vector as the userspace handshake for glibc-managed rseq, too?
Yes.
I don't think it works if the kernel
Quoted 2 lines
overtakes glibc. Or is there some other approach shown in the series that I missed?
The handshake I am proposing is as follows:
1- libc init:
issues getauxval(AT_RSEQ_FEATURE_SIZE) to learn the rseq feature size supported by the Linux kernel. It can be either:
a) getauxval(AT_RSEQ_FEATURE_SIZE) == 0, errno=ENOENT: pre-6.3 kernel or CONFIG_RSEQ=n.
Need to issue the rseq system call to figure out if rseq is implemented/available or not. If rseq is indeed implemented, use a __rseq_size=32.
b) getauxval(AT_RSEQ_FEATURE_SIZE) > 0:
The kernel exposes its supported rseq feature size. libc either needs to register rseq with a rseq_len of 32-byte (original size), or with a rseq_len larger than 32 bytes with enough space to hold all features.
2- Now about applications (and libc) use of rseq fields:
Using both __rseq_size (from libc) and the result of getauxval(AT_RSEQ_FEATURE_SIZE), a rseq user can figure which rseq fields can indeed be used. The important part is how get_rseq_feature_size() is called in the rseq selftests:
rseq_feature_size = get_rseq_feature_size();
if (rseq_feature_size > rseq_size)
rseq_feature_size = rseq_size;which basically sets rseq_feature_size to the feature size exposed by the kernel, except if libc's __rseq_size is smaller than the feature size exposed by the kernel, in which case it will truncate the rseq_feature_size to __rseq_size.
This allows rseq users to know which feature set is supported by the kernel and for which libc has allocated enough space.
The only thing here is that rseq users cannot rely on libc's __rseq_size symbol to get the feature size. But considering that this is a contract between the kernel and the rseq user (libc is mostly just there to allocate per-thread memory), I don't think it's a concern to request users to query getauxval(AT_RSEQ_FEATURE_SIZE) in addition to load __rseq_size.
Quoted 5 lines
Maybe we should just skip the existing padding and use it only for some vaguely kernel-internal purpose (say through a vDSO helper), so that it is less of an issue how to communicate the presence of these fields to userspace.
The fact that libc's __rseq_size is included the original struct rseq padding is unfortunate, but I really see this as a purely userspace ABI concern, which should not dictate the layout of the kernel ABI exposed to user-space, especially given that all the information required to allow rseq users to know which fields can be used is readily available by combining the value loaded from __rseq_size and the result of getauxval(AT_RSEQ_FEATURE_SIZE).
Thoughts ?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Re: [PATCH 05/30] selftests/rseq: Use ELF auxiliary vector for extensible rseq
* Mathieu Desnoyers:
Quoted 8 lines
2- Now about applications (and libc) use of rseq fields:
Using both
__rseq_size(from libc) and the result ofgetauxval(AT_RSEQ_FEATURE_SIZE), a rseq user can figure which rseq fields can indeed be used. The important part is howget_rseq_feature_size()is called in the rseq selftests:
Quoted 8 lines
rseq_feature_size = get_rseq_feature_size(); if (rseq_feature_size > rseq_size) rseq_feature_size = rseq_size;which basically sets
rseq_feature_sizeto the feature size exposed by the kernel, except if libc's__rseq_sizeis smaller than the feature size exposed by the kernel, in which case it will truncate therseq_feature_sizeto__rseq_size.
Ahh, this happens to work because we pass 32 today from glibc, and there is nothing left to do in glibc to enable these new fields.
If true, that really argues in favor of this approach.
Quoted 5 lines
Quoted 4 lines
Maybe we should just skip the existing padding and use it only for some vaguely kernel-internal purpose (say through a vDSO helper), so that it is less of an issue how to communicate the presence of these fields to userspace.
Quoted 7 lines
The fact that libc's
__rseq_sizeis included the original struct rseq padding is unfortunate, but I really see this as a purely userspace ABI concern, which should not dictate the layout of the kernel ABI exposed to user-space, especially given that all the information required to allow rseq users to know which fields can be used is readily available by combining the value loaded from__rseq_sizeand the result ofgetauxval(AT_RSEQ_FEATURE_SIZE).
But we must pass size 32 to the kernel today, otherwise rseq registration fails. It's a kernel-mandated value, not something that's purely a userspace concern.
Mathieu Desnoyers
maintainerRe: [PATCH 05/30] selftests/rseq: Use ELF auxiliary vector for extensible rseq
Quoted 19 lines · Florian Weimer
* Mathieu Desnoyers:
Quoted 8 lines
2- Now about applications (and libc) use of rseq fields:
Using both
__rseq_size(from libc) and the result ofgetauxval(AT_RSEQ_FEATURE_SIZE), a rseq user can figure which rseq fields can indeed be used. The important part is howget_rseq_feature_size()is called in the rseq selftests:Quoted 8 lines
rseq_feature_size = get_rseq_feature_size(); if (rseq_feature_size > rseq_size) rseq_feature_size = rseq_size;which basically sets
rseq_feature_sizeto the feature size exposed by the kernel, except if libc's__rseq_sizeis smaller than the feature size exposed by the kernel, in which case it will truncate therseq_feature_sizeto__rseq_size.
Quoted 4 lines
Ahh, this happens to work because we pass 32 today from glibc, and there is nothing left to do in glibc to enable these new fields.
If true, that really argues in favor of this approach.
Yes, you are correct..
Quoted 14 lines
Quoted 6 lines
Quoted 5 lines
Maybe we should just skip the existing padding and use it only for some vaguely kernel-internal purpose (say through a vDSO helper), so that it is less of an issue how to communicate the presence of these fields to userspace.
Quoted 7 lines
The fact that libc's
__rseq_sizeis included the original struct rseq padding is unfortunate, but I really see this as a purely userspace ABI concern, which should not dictate the layout of the kernel ABI exposed to user-space, especially given that all the information required to allow rseq users to know which fields can be used is readily available by combining the value loaded from__rseq_sizeand the result ofgetauxval(AT_RSEQ_FEATURE_SIZE).
Quoted 3 lines
But we must pass size 32 to the kernel today, otherwise rseq registration fails. It's a kernel-mandated value, not something that's purely a userspace concern.
What I mean when stating the "userspace concern" is the semantic of the libc's __rseq_size symbol: whether it means allocated space (including padding) or actively populated feature fields.
In terms of rseq registration rseq_len argument, here is the updated check in the system call:
/*
* If there was no rseq previously registered, ensure the provided rseq
* is properly aligned, as communcated to user-space through the ELF
* auxiliary vector AT_RSEQ_ALIGN. If rseq_len is the original rseq
* size, the required alignment is the original struct rseq alignment.
*
* In order to be valid, rseq_len is either the original rseq size, or
* large enough to contain all supported fields, as communicated to
* user-space through the ELF auxiliary vector AT_RSEQ_FEATURE_SIZE.
*/
if (rseq_len < ORIG_RSEQ_SIZE ||
(rseq_len == ORIG_RSEQ_SIZE && !IS_ALIGNED((unsigned long)rseq, ORIG_RSEQ_SIZE)) || (rseq_len != ORIG_RSEQ_SIZE && (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) ||
rseq_len < offsetof(struct rseq, end))))
return -EINVAL;
Which keeps accepting rseq_len=32 (original ABI), else requires that enough space is available to hold all supported feature fields (but never less than 32 bytes).
Do my explanations take care of your concerns, or are there still aspects that you are uneasy with ?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Mathieu Desnoyers
maintainerPATCH 6/30 selftests/rseq: Implement rseq numa node id field selftest
In reply to Mathieu DesnoyersTest the NUMA node id extension rseq field. Compare it against the value returned by the getcpu(2) system call while pinned on a specific core.
--- tools/testing/selftests/rseq/basic_test.c | 4 ++++ tools/testing/selftests/rseq/rseq-abi.h | 8 +++++++ tools/testing/selftests/rseq/rseq.c | 18 +++++++++++++++ tools/testing/selftests/rseq/rseq.h | 28 +++++++++++++++++++++++ 4 files changed, 58 insertions(+)
tools/testing/selftests/rseq/basic_test.c +4 -0
@@ -22,6 +22,8 @@ void test_cpu_pointer(void)CPU_ZERO (&test_affinity);for (i =0 ; i <CPU_SETSIZE ; i++) {if (CPU_ISSET (i, &affinity)) { +int node; +CPU_SET (i, &test_affinity);sched_setaffinity (0 ,sizeof (test_affinity), &test_affinity);
@@ -29,6 +31,8 @@ void test_cpu_pointer(void)assert (rseq_current_cpu () == i);assert (rseq_current_cpu_raw () == i);assert (rseq_cpu_start () == i); + node =rseq_fallback_current_node (); +assert (rseq_current_node_id () == node);CPU_CLR (i, &test_affinity); } }
tools/testing/selftests/rseq/rseq-abi.h +8 -0
@@ -147,6 +147,14 @@ struct rseq_abi {*/ __u32 flags; +/* +* Restartable sequences node_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. Contains the current NUMA node ID. +*/ +__u32 node_id; +/* * Flexible array member at end of structure, after last feature field. */
tools/testing/selftests/rseq/rseq.c +18 -0
@@ -79,6 +79,11 @@ static int sys_rseq(struct rseq_abi *rseq_abi, uint32_t rseq_len,return syscall (__NR_rseq, rseq_abi, rseq_len, flags, sig); } +static int sys_getcpu (unsigned *cpu,unsigned *node) +{ +return syscall (__NR_getcpu, cpu, node,NULL ); +} +int rseq_available (void ) {int rc;
@@ -201,3 +206,16 @@ int32_t rseq_fallback_current_cpu(void) }return cpu; } + +int32_t rseq_fallback_current_node (void ) +{ +uint32_t cpu_id, node_id; +int ret; + + ret =sys_getcpu (&cpu_id, &node_id); +if (ret) { +perror ("sys_getcpu()" ); +return ret; + } +return (int32_t ) node_id; +}
tools/testing/selftests/rseq/rseq.h +28 -0
@@ -20,6 +20,15 @@#include "rseq-abi.h" #include "compiler.h" +#ifndef rseq_sizeof_field +#define rseq_sizeof_field (TYPE ,MEMBER ) sizeof((((TYPE *)0)->MEMBER)) +#endif + +#ifndef rseq_offsetofend +#define rseq_offsetofend (TYPE ,MEMBER ) \ + (offsetof(TYPE, MEMBER) + rseq_sizeof_field(TYPE, MEMBER)) +#endif +/* * Empty code injection macros, override when testing. * It is important to consider that the ASM injection macros need to be
@@ -128,6 +137,11 @@ int rseq_unregister_current_thread(void);*/ int32_t rseq_fallback_current_cpu (void ); +/* +* Restartable sequence fallback for reading the current node number. +*/ +int32_t rseq_fallback_current_node (void ); +/* * Values returned can be either the current CPU number, -1 (rseq is * uninitialized), or -2 (rseq initialization has failed).
@@ -163,6 +177,20 @@ static inline uint32_t rseq_current_cpu(void)return cpu; } +static inline bool rseq_node_id_available (void ) +{ + return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, node_id); +} + +/* +* Current NUMA node number. +*/ +static inline uint32_t rseq_current_node_id (void ) +{ +assert (rseq_node_id_available ()); +return RSEQ_ACCESS_ONCE (rseq_get_abi ()->node_id); +} +static inline void rseq_clear_rseq_cs (void ) {RSEQ_WRITE_ONCE (rseq_get_abi ()->rseq_cs.arch.ptr,0 );
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: Implement rseq numa node id field selftest
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 99babd04b25054717d21840298b0b46046b42cd9 Gitweb: https://git.kernel.org/tip/99babd04b25054717d21840298b0b46046b42cd9 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:08 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:11 +01:00
selftests/rseq: Implement rseq numa node id field selftest
Test the NUMA node id extension rseq field. Compare it against the value returned by the getcpu(2) system call while pinned on a specific core.
--- tools/testing/selftests/rseq/basic_test.c | 4 +++- tools/testing/selftests/rseq/rseq-abi.h | 8 ++++++- tools/testing/selftests/rseq/rseq.c | 18 ++++++++++++++- tools/testing/selftests/rseq/rseq.h | 28 ++++++++++++++++++++++- 4 files changed, 58 insertions(+)
tools/testing/selftests/rseq/basic_test.c +4 -0
@@ -22,6 +22,8 @@ void test_cpu_pointer(void)CPU_ZERO (&test_affinity);for (i =0 ; i <CPU_SETSIZE ; i++) {if (CPU_ISSET (i, &affinity)) { +int node; +CPU_SET (i, &test_affinity);sched_setaffinity (0 ,sizeof (test_affinity), &test_affinity);
@@ -29,6 +31,8 @@ void test_cpu_pointer(void)assert (rseq_current_cpu () == i);assert (rseq_current_cpu_raw () == i);assert (rseq_cpu_start () == i); + node =rseq_fallback_current_node (); +assert (rseq_current_node_id () == node);CPU_CLR (i, &test_affinity); } }
tools/testing/selftests/rseq/rseq-abi.h +8 -0
@@ -148,6 +148,14 @@ struct rseq_abi {__u32 flags;/* +* Restartable sequences node_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. Contains the current NUMA node ID. +*/ +__u32 node_id; + +/* * Flexible array member at end of structure, after last feature field. */ char end[];
tools/testing/selftests/rseq/rseq.c +18 -0
@@ -79,6 +79,11 @@ static int sys_rseq(struct rseq_abi *rseq_abi, uint32_t rseq_len,return syscall (__NR_rseq, rseq_abi, rseq_len, flags, sig); } +static int sys_getcpu (unsigned *cpu,unsigned *node) +{ +return syscall (__NR_getcpu, cpu, node,NULL ); +} +int rseq_available (void ) {int rc;
@@ -201,3 +206,16 @@ int32_t rseq_fallback_current_cpu(void) }return cpu; } + +int32_t rseq_fallback_current_node (void ) +{ +uint32_t cpu_id, node_id; +int ret; + + ret =sys_getcpu (&cpu_id, &node_id); +if (ret) { +perror ("sys_getcpu()" ); +return ret; + } +return (int32_t ) node_id; +}
tools/testing/selftests/rseq/rseq.h +28 -0
@@ -20,6 +20,15 @@#include "rseq-abi.h" #include "compiler.h" +#ifndef rseq_sizeof_field +#define rseq_sizeof_field (TYPE ,MEMBER ) sizeof((((TYPE *)0)->MEMBER)) +#endif + +#ifndef rseq_offsetofend +#define rseq_offsetofend (TYPE ,MEMBER ) \ + (offsetof(TYPE, MEMBER) + rseq_sizeof_field(TYPE, MEMBER)) +#endif +/* * Empty code injection macros, override when testing. * It is important to consider that the ASM injection macros need to be
@@ -129,6 +138,11 @@ int rseq_unregister_current_thread(void);int32_t rseq_fallback_current_cpu (void );/* +* Restartable sequence fallback for reading the current node number. +*/ +int32_t rseq_fallback_current_node (void ); + +/* * Values returned can be either the current CPU number, -1 (rseq is * uninitialized), or -2 (rseq initialization has failed). */
@@ -163,6 +177,20 @@ static inline uint32_t rseq_current_cpu(void)return cpu; } +static inline bool rseq_node_id_available (void ) +{ + return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, node_id); +} + +/* +* Current NUMA node number. +*/ +static inline uint32_t rseq_current_node_id (void ) +{ +assert (rseq_node_id_available ()); +return RSEQ_ACCESS_ONCE (rseq_get_abi ()->node_id); +} +static inline void rseq_clear_rseq_cs (void ) {RSEQ_WRITE_ONCE (rseq_get_abi ()->rseq_cs.arch.ptr,0 );
Mathieu Desnoyers
maintainerPATCH 7/30 sched: Introduce per-memory-map concurrency ID
In reply to Mathieu DesnoyersThis feature allows the scheduler to expose a per-memory map concurrency ID to user-space. This concurrency ID is within the possible cpus range, and is temporarily (and uniquely) assigned while threads are actively running within a memory map. If a memory map has fewer threads than cores, or is limited to run on few cores concurrently through sched affinity or cgroup cpusets, the concurrency IDs will be values close to 0, thus allowing efficient use of user-space memory for per-cpu data structures.
This feature is meant to be exposed by a new rseq thread area field.
The primary purpose of this feature is to do the heavy-lifting needed by memory allocators to allow them to use per-cpu data structures efficiently in the following situations:
- Single-threaded applications,
- Multi-threaded applications on large systems (many cores) with limited cpu affinity mask,
- Multi-threaded applications on large systems (many cores) with restricted cgroup cpuset per container.
One of the key concern from scheduler maintainers is the overhead associated with additional spin locks or atomic operations in the scheduler fast-path. This is why the following optimization is implemented.
On context switch between threads belonging to the same memory map, transfer the mm_cid from prev to next without any atomic ops. This takes care of use-cases involving frequent context switch between threads belonging to the same memory map.
Additional optimizations can be done if the spin locks added when context switching between threads belonging to different memory maps end up being a performance bottleneck. Those are left out of this patch though. A performance impact would have to be clearly demonstrated to justify the added complexity.
The credit goes to Paul Turner (Google) for the original virtual cpu id idea. This feature is implemented based on the discussions with Paul Turner and Peter Oskolkov (Google), but I took the liberty to implement scheduler fast-path optimizations and my own NUMA-awareness scheme. The rumor has it that Google have been running a rseq vcpu_id extension internally in production for a year. The tcmalloc source code indeed has comments hinting at a vcpu_id prototype extension to the rseq system call [1].
The following benchmarks do not show any significant overhead added to the scheduler context switch by this feature:
* perf bench sched messaging (process)
Baseline: 86.5±0.3 ms With mm_cid: 86.7±2.6 ms
* perf bench sched messaging (threaded)
Baseline: 84.3±3.0 ms With mm_cid: 84.7±2.6 ms
* hackbench (process)
Baseline: 82.9±2.7 ms With mm_cid: 82.9±2.9 ms
* hackbench (threaded)
Baseline: 85.2±2.6 ms With mm_cid: 84.4±2.9 ms
[1] https://github.com/google/tcmalloc/blob/master/tcmalloc/internal/linux_syscall_support.h#L26
---
Changes since v3:
- Remove per-runqueue vcpu id cache optimization.
- Remove single-threaded process optimization.
- Introduce spinlock to protect vcpu id bitmaps.
Changes since v4:
- Disable interrupts around mm_vcpu_get/mm_vcpu_put. The spin locks are used from within the scheduler context switch with interrupts off, so all uses of these spin locks need to have interrupts off.
- Initialize tsk->mm_vcpu to -1 in dup_task_struct to be consistent with other states where mm_vcpu_active is 0.
Changes since v5:
- Combine rseq vcpu id init into a single function.
- Use raw spinlock with irqs disabled.
- sched_vcpu_fork: warn on mm_vcpu != -1 rather than setting it again.
- Move numa-awareness to a separate patch.
- Rename Virtual CPU ID "vcpu_id" to Concurrency ID "cid".
- Rename "Memory Space" (vm) to "Memory Map" (mm).
--- fs/exec.c | 4 +++ include/linux/mm.h | 25 +++++++++++++++++ include/linux/mm_types.h | 43 ++++++++++++++++++++++++++++- include/linux/sched.h | 5 ++++ init/Kconfig | 4 +++ kernel/fork.c | 8 +++++- kernel/sched/core.c | 51 +++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 58 ++++++++++++++++++++++++++++++++++++++++ kernel/signal.c | 2 ++ 9 files changed, 198 insertions(+), 2 deletions(-)
fs/exec.c +4 -0
@@ -1013,6 +1013,7 @@ static int exec_mmap(struct mm_struct *mm) tsk->active_mm = mm; tsk->mm = mm;lru_gen_add_mm (mm); +mm_init_cid (mm);/* * This prevents preemption while active_mm is being loaded and * it and mm are being updated, which could cause problems for
@@ -1808,6 +1809,7 @@ static int bprm_execve(struct linux_binprm *bprm,check_unsafe_exec (bprm); current->in_execve =1 ; +sched_mm_cid_before_execve (current); file =do_open_execat (fd, filename, flags); retval =PTR_ERR (file);
@@ -1838,6 +1840,7 @@ static int bprm_execve(struct linux_binprm *bprm,if (retval <0 ) goto out; +sched_mm_cid_after_execve (current);/* execve succeeded */ current->fs->in_exec =0 ; current->in_execve =0 ;
@@ -1857,6 +1860,7 @@ static int bprm_execve(struct linux_binprm *bprm,force_fatal_sig (SIGSEGV ); out_unmark: +sched_mm_cid_after_execve (current); current->fs->in_exec =0 ; current->in_execve =0 ;
include/linux/mm.h +25 -0
@@ -3475,4 +3475,29 @@ madvise_set_anon_name(struct mm_struct *mm, unsigned long start,*/ #define ZAP_FLAG_DROP_MARKER ((__force zap_flags_t) BIT(0)) +#ifdef CONFIG_SCHED_MM_CID +void sched_mm_cid_before_execve (struct task_struct *t); +void sched_mm_cid_after_execve (struct task_struct *t); +void sched_mm_cid_fork (struct task_struct *t); +void sched_mm_cid_exit_signals (struct task_struct *t); +static inline int task_mm_cid (struct task_struct *t) +{ +return t->mm_cid; +} +#else +static inline void sched_mm_cid_before_execve (struct task_struct *t) { } +static inline void sched_mm_cid_after_execve (struct task_struct *t) { } +static inline void sched_mm_cid_fork (struct task_struct *t) { } +static inline void sched_mm_cid_exit_signals (struct task_struct *t) { } +static inline int task_mm_cid (struct task_struct *t) +{ +/* +* Use the processor id as a fall-back when the mm cid feature is +* disabled. This provides functional per-cpu data structure accesses +* in user-space, althrough it won't provide the memory usage benefits. +*/ +return raw_smp_processor_id (); +} +#endif +#endif /* _LINUX_MM_H */
include/linux/mm_types.h +42 -1
55 lines not on this page · raw message
include/linux/sched.h +5 -0
@@ -1314,6 +1314,11 @@ struct task_struct {unsigned long rseq_event_mask;#endif +#ifdef CONFIG_SCHED_MM_CID +int mm_cid;/* Current cid in mm */ +int mm_cid_active;/* Whether cid bitmap is active */ +#endif +struct tlbflush_unmap_batch tlb_ubc;union {
init/Kconfig +4 -0
@@ -1039,6 +1039,10 @@ config RT_GROUP_SCHED endif #CGROUP_SCHED +config SCHED_MM_CID + def_bool y + depends on SMP && RSEQ + config UCLAMP_TASK_GROUP bool "Utilization clamping per group of tasks" depends on CGROUP_SCHED
kernel/fork.c +7 -1
@@ -1047,6 +1047,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) tsk->reported_split_lock =0 ;#endif +#ifdef CONFIG_SCHED_MM_CID + tsk->mm_cid =-1 ; + tsk->mm_cid_active =0 ; +#endif return tsk; free_stack:
@@ -1150,6 +1154,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, mm->user_ns =get_user_ns (user_ns);lru_gen_init_mm (mm); +mm_init_cid (mm);return mm; fail_nocontext:
@@ -1579,6 +1584,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) tsk->mm = mm; tsk->active_mm = mm; +sched_mm_cid_fork (tsk);return 0 ; }
@@ -3041,7 +3047,7 @@ void __init proc_caches_init(void)* dynamically sized based on the maximum CPU number this system * can have, taking hotplug into account (nr_cpu_ids). */ - mm_size =sizeof (struct mm_struct ) +cpumask_size (); + mm_size =sizeof (struct mm_struct ) +cpumask_size () +mm_cid_size (); mm_cachep = kmem_cache_create_usercopy("mm_struct", mm_size, ARCH_MIN_MMSTRUCT_ALIGN,
kernel/sched/core.c +51 -0
60 lines not on this page · raw message
kernel/sched/sched.h +58 -0
62 lines not on this page · raw message
kernel/signal.c +2 -0
@@ -2950,6 +2950,7 @@ void exit_signals(struct task_struct *tsk)cgroup_threadgroup_change_begin (tsk);if (thread_group_empty (tsk) || (tsk->signal->flags &SIGNAL_GROUP_EXIT )) { +sched_mm_cid_exit_signals (tsk); tsk->flags |=PF_EXITING ;cgroup_threadgroup_change_end (tsk);return ;
@@ -2960,6 +2961,7 @@ void exit_signals(struct task_struct *tsk)* From now this task is not visible for group-wide signals, * see wants_signal(), do_signal_stop(). */ +sched_mm_cid_exit_signals (tsk); tsk->flags |=PF_EXITING ;cgroup_threadgroup_change_end (tsk);
Signature · 1 line
2.25.1
[tip: sched/core] sched: Introduce per-memory-map concurrency ID
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: af7f588d8f7355bc4298dd1962d7826358fc95f0 Gitweb: https://git.kernel.org/tip/af7f588d8f7355bc4298dd1962d7826358fc95f0 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:09 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:11 +01:00
sched: Introduce per-memory-map concurrency ID
This feature allows the scheduler to expose a per-memory map concurrency ID to user-space. This concurrency ID is within the possible cpus range, and is temporarily (and uniquely) assigned while threads are actively running within a memory map. If a memory map has fewer threads than cores, or is limited to run on few cores concurrently through sched affinity or cgroup cpusets, the concurrency IDs will be values close to 0, thus allowing efficient use of user-space memory for per-cpu data structures.
This feature is meant to be exposed by a new rseq thread area field.
The primary purpose of this feature is to do the heavy-lifting needed by memory allocators to allow them to use per-cpu data structures efficiently in the following situations:
- Single-threaded applications,
- Multi-threaded applications on large systems (many cores) with limited cpu affinity mask,
- Multi-threaded applications on large systems (many cores) with restricted cgroup cpuset per container.
One of the key concern from scheduler maintainers is the overhead associated with additional spin locks or atomic operations in the scheduler fast-path. This is why the following optimization is implemented.
On context switch between threads belonging to the same memory map, transfer the mm_cid from prev to next without any atomic ops. This takes care of use-cases involving frequent context switch between threads belonging to the same memory map.
Additional optimizations can be done if the spin locks added when context switching between threads belonging to different memory maps end up being a performance bottleneck. Those are left out of this patch though. A performance impact would have to be clearly demonstrated to justify the added complexity.
The credit goes to Paul Turner (Google) for the original virtual cpu id idea. This feature is implemented based on the discussions with Paul Turner and Peter Oskolkov (Google), but I took the liberty to implement scheduler fast-path optimizations and my own NUMA-awareness scheme. The rumor has it that Google have been running a rseq vcpu_id extension internally in production for a year. The tcmalloc source code indeed has comments hinting at a vcpu_id prototype extension to the rseq system call [1].
The following benchmarks do not show any significant overhead added to the scheduler context switch by this feature:
* perf bench sched messaging (process)
Baseline: 86.5±0.3 ms With mm_cid: 86.7±2.6 ms
* perf bench sched messaging (threaded)
Baseline: 84.3±3.0 ms With mm_cid: 84.7±2.6 ms
* hackbench (process)
Baseline: 82.9±2.7 ms With mm_cid: 82.9±2.9 ms
* hackbench (threaded)
Baseline: 85.2±2.6 ms With mm_cid: 84.4±2.9 ms
[1] https://github.com/google/tcmalloc/blob/master/tcmalloc/internal/linux_syscall_support.h#L26
--- fs/exec.c | 4 +++- include/linux/mm.h | 25 +++++++++++++++++- include/linux/mm_types.h | 43 ++++++++++++++++++++++++++++- include/linux/sched.h | 5 +++- init/Kconfig | 4 +++- kernel/fork.c | 8 ++++- kernel/sched/core.c | 51 ++++++++++++++++++++++++++++++++++- kernel/sched/sched.h | 58 +++++++++++++++++++++++++++++++++++++++- kernel/signal.c | 2 +- 9 files changed, 198 insertions(+), 2 deletions(-)
fs/exec.c +4 -0
@@ -1010,6 +1010,7 @@ static int exec_mmap(struct mm_struct *mm) active_mm = tsk->active_mm; tsk->active_mm = mm; tsk->mm = mm; +mm_init_cid (mm);/* * This prevents preemption while active_mm is being loaded and * it and mm are being updated, which could cause problems for
@@ -1822,6 +1823,7 @@ static int bprm_execve(struct linux_binprm *bprm,*/ check_unsafe_exec (bprm); current->in_execve =1 ; +sched_mm_cid_before_execve (current); file =do_open_execat (fd, filename, flags); retval =PTR_ERR (file);
@@ -1852,6 +1854,7 @@ static int bprm_execve(struct linux_binprm *bprm,if (retval <0 ) goto out; +sched_mm_cid_after_execve (current);/* execve succeeded */ current->fs->in_exec =0 ; current->in_execve =0 ;
@@ -1871,6 +1874,7 @@ out:force_fatal_sig (SIGSEGV ); out_unmark: +sched_mm_cid_after_execve (current); current->fs->in_exec =0 ; current->in_execve =0 ;
include/linux/mm.h +25 -0
@@ -1976,6 +1976,31 @@ struct zap_details {/* Set in unmap_vmas() to indicate a final unmap call. Only used by hugetlb */ #define ZAP_FLAG_UNMAP ((__force zap_flags_t) BIT(1)) +#ifdef CONFIG_SCHED_MM_CID +void sched_mm_cid_before_execve (struct task_struct *t); +void sched_mm_cid_after_execve (struct task_struct *t); +void sched_mm_cid_fork (struct task_struct *t); +void sched_mm_cid_exit_signals (struct task_struct *t); +static inline int task_mm_cid (struct task_struct *t) +{ +return t->mm_cid; +} +#else +static inline void sched_mm_cid_before_execve (struct task_struct *t) { } +static inline void sched_mm_cid_after_execve (struct task_struct *t) { } +static inline void sched_mm_cid_fork (struct task_struct *t) { } +static inline void sched_mm_cid_exit_signals (struct task_struct *t) { } +static inline int task_mm_cid (struct task_struct *t) +{ +/* +* Use the processor id as a fall-back when the mm cid feature is +* disabled. This provides functional per-cpu data structure accesses +* in user-space, althrough it won't provide the memory usage benefits. +*/ +return raw_smp_processor_id (); +} +#endif +#ifdef CONFIG_MMU extern bool can_do_mlock (void );#else
include/linux/mm_types.h +42 -1
55 lines not on this page · raw message
include/linux/sched.h +5 -0
@@ -1311,6 +1311,11 @@ struct task_struct {unsigned long rseq_event_mask;#endif +#ifdef CONFIG_SCHED_MM_CID +int mm_cid;/* Current cid in mm */ +int mm_cid_active;/* Whether cid bitmap is active */ +#endif +struct tlbflush_unmap_batch tlb_ubc;union {
init/Kconfig +4 -0
@@ -1041,6 +1041,10 @@ config RT_GROUP_SCHED endif #CGROUP_SCHED +config SCHED_MM_CID + def_bool y + depends on SMP && RSEQ + config UCLAMP_TASK_GROUP bool "Utilization clamping per group of tasks" depends on CGROUP_SCHED
kernel/fork.c +7 -1
@@ -1060,6 +1060,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) tsk->reported_split_lock =0 ;#endif +#ifdef CONFIG_SCHED_MM_CID + tsk->mm_cid =-1 ; + tsk->mm_cid_active =0 ; +#endif return tsk; free_stack:
@@ -1169,6 +1173,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, mm->user_ns =get_user_ns (user_ns);lru_gen_init_mm (mm); +mm_init_cid (mm);return mm; fail_pcpu:
@@ -1601,6 +1606,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) tsk->mm = mm; tsk->active_mm = mm; +sched_mm_cid_fork (tsk);return 0 ; }
@@ -3034,7 +3040,7 @@ void __init mm_cache_init(void)* dynamically sized based on the maximum CPU number this system * can have, taking hotplug into account (nr_cpu_ids). */ - mm_size =sizeof (struct mm_struct ) +cpumask_size (); + mm_size =sizeof (struct mm_struct ) +cpumask_size () +mm_cid_size (); mm_cachep = kmem_cache_create_usercopy("mm_struct", mm_size, ARCH_MIN_MMSTRUCT_ALIGN,
kernel/sched/core.c +51 -0
60 lines not on this page · raw message
kernel/sched/sched.h +58 -0
62 lines not on this page · raw message
kernel/signal.c +2 -0
@@ -2951,6 +2951,7 @@ void exit_signals(struct task_struct *tsk)cgroup_threadgroup_change_begin (tsk);if (thread_group_empty (tsk) || (tsk->signal->flags &SIGNAL_GROUP_EXIT )) { +sched_mm_cid_exit_signals (tsk); tsk->flags |=PF_EXITING ;cgroup_threadgroup_change_end (tsk);return ;
@@ -2961,6 +2962,7 @@ void exit_signals(struct task_struct *tsk)* From now this task is not visible for group-wide signals, * see wants_signal(), do_signal_stop(). */ +sched_mm_cid_exit_signals (tsk); tsk->flags |=PF_EXITING ;cgroup_threadgroup_change_end (tsk);
Mathieu Desnoyers
maintainerPATCH 8/30 rseq: Extend struct rseq with per-memory-map concurrency ID
In reply to Mathieu DesnoyersIf a memory map has fewer threads than there are cores on the system, or is limited to run on few cores concurrently through sched affinity or cgroup cpusets, the concurrency IDs will be values close to 0, thus allowing efficient use of user-space memory for per-cpu data structures.
--- include/uapi/linux/rseq.h | 9 +++++++++ kernel/rseq.c | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
include/uapi/linux/rseq.h +9 -0
@@ -139,6 +139,15 @@ struct rseq {*/ __u32 node_id; +/* +* Restartable sequences mm_cid 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. Contains the current thread's concurrency ID +* (allocated uniquely within a memory map). +*/ +__u32 mm_cid; +/* * Flexible array member at end of structure, after last feature field. */
kernel/rseq.c +10 -1
@@ -90,12 +90,15 @@ static int rseq_update_cpu_node_id(struct task_struct *t)struct rseq __user *rseq = t->rseq;u32 cpu_id =raw_smp_processor_id ();u32 node_id =cpu_to_node (cpu_id); +u32 mm_cid =task_mm_cid (t); +WARN_ON_ONCE ((int ) mm_cid <0 );if (!user_write_access_begin (rseq, t->rseq_len)) goto efault;unsafe_put_user (cpu_id, &rseq->cpu_id_start, efault_end);unsafe_put_user (cpu_id, &rseq->cpu_id, efault_end);unsafe_put_user (node_id, &rseq->node_id, efault_end); +unsafe_put_user (mm_cid, &rseq->mm_cid, efault_end);/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally updated only if
@@ -113,7 +116,8 @@ static int rseq_update_cpu_node_id(struct task_struct *t)static int rseq_reset_rseq_cpu_node_id (struct task_struct *t) { -u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED , node_id =0 ; +u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED , node_id =0 , + mm_cid =0 ;/* * Reset cpu_id_start to its initial state (0).
@@ -132,6 +136,11 @@ static int rseq_reset_rseq_cpu_node_id(struct task_struct *t)*/ if (put_user (node_id, &t->rseq->node_id))return -EFAULT ; +/* +* Reset mm_cid to its initial state (0). +*/ +if (put_user (mm_cid, &t->rseq->mm_cid)) +return -EFAULT ;/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally reset only if
Signature · 1 line
2.25.1
[tip: sched/core] rseq: Extend struct rseq with per-memory-map concurrency ID
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: f7b01bb0b57f994a44ea6368536b59062b796381 Gitweb: https://git.kernel.org/tip/f7b01bb0b57f994a44ea6368536b59062b796381 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:10 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:12 +01:00
rseq: Extend struct rseq with per-memory-map concurrency ID
If a memory map has fewer threads than there are cores on the system, or is limited to run on few cores concurrently through sched affinity or cgroup cpusets, the concurrency IDs will be values close to 0, thus allowing efficient use of user-space memory for per-cpu data structures.
--- include/uapi/linux/rseq.h | 9 +++++++++ kernel/rseq.c | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
include/uapi/linux/rseq.h +9 -0
@@ -140,6 +140,15 @@ struct rseq {__u32 node_id;/* +* Restartable sequences mm_cid 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. Contains the current thread's concurrency ID +* (allocated uniquely within a memory map). +*/ +__u32 mm_cid; + +/* * Flexible array member at end of structure, after last feature field. */ char end[];
kernel/rseq.c +10 -1
@@ -90,12 +90,15 @@ static int rseq_update_cpu_node_id(struct task_struct *t)struct rseq __user *rseq = t->rseq;u32 cpu_id =raw_smp_processor_id ();u32 node_id =cpu_to_node (cpu_id); +u32 mm_cid =task_mm_cid (t); +WARN_ON_ONCE ((int ) mm_cid <0 );if (!user_write_access_begin (rseq, t->rseq_len)) goto efault;unsafe_put_user (cpu_id, &rseq->cpu_id_start, efault_end);unsafe_put_user (cpu_id, &rseq->cpu_id, efault_end);unsafe_put_user (node_id, &rseq->node_id, efault_end); +unsafe_put_user (mm_cid, &rseq->mm_cid, efault_end);/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally updated only if
@@ -113,7 +116,8 @@ efault:static int rseq_reset_rseq_cpu_node_id (struct task_struct *t) { -u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED , node_id =0 ; +u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED , node_id =0 , + mm_cid =0 ;/* * Reset cpu_id_start to its initial state (0).
@@ -133,6 +137,11 @@ static int rseq_reset_rseq_cpu_node_id(struct task_struct *t)if (put_user (node_id, &t->rseq->node_id))return -EFAULT ;/* +* Reset mm_cid to its initial state (0). +*/ +if (put_user (mm_cid, &t->rseq->mm_cid)) +return -EFAULT ; +/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally reset only if * t->rseq_len != ORIG_RSEQ_SIZE.
Mathieu Desnoyers
maintainerPATCH 9/30 selftests/rseq: Remove RSEQ_SKIP_FASTPATH code
In reply to Mathieu DesnoyersThis code is not currently build by the test Makefile, adds complexity, and is not overall useful considering that the abort handling loops to retry the fast-path.
--- tools/testing/selftests/rseq/param_test.c | 4 -- tools/testing/selftests/rseq/rseq-arm.h | 6 --- tools/testing/selftests/rseq/rseq-arm64.h | 6 --- tools/testing/selftests/rseq/rseq-mips.h | 6 --- tools/testing/selftests/rseq/rseq-ppc.h | 6 --- tools/testing/selftests/rseq/rseq-riscv.h | 6 --- tools/testing/selftests/rseq/rseq-s390.h | 5 -- tools/testing/selftests/rseq/rseq-skip.h | 65 ----------------------- tools/testing/selftests/rseq/rseq-x86.h | 12 ----- 9 files changed, 116 deletions(-) delete mode 100644 tools/testing/selftests/rseq/rseq-skip.h
tools/testing/selftests/rseq/param_test.c +0 -4
@@ -38,11 +38,7 @@ static int opt_yield, opt_signal, opt_sleep, opt_disable_rseq, opt_threads =200 , opt_disable_mod =0 , opt_test ='s' , opt_mb =0 ; -#ifndef RSEQ_SKIP_FASTPATH static long long opt_reps =5000 ; -#else -static long long opt_reps =100 ; -#endif static __thread __attribute__((tls_model ("initial-exec" )))unsigned int signals_delivered;
tools/testing/selftests/rseq/rseq-arm.h +0 -6
@@ -79,10 +79,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define __RSEQ_ASM_DEFINE_TABLE (label, version, flags, start_ip, \ post_commit_offset, abort_ip) \ ".pushsection __rseq_cs, \"aw\"\n\t" \
@@ -823,5 +819,3 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-arm64.h +0 -6
@@ -85,10 +85,6 @@ do { \ } \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define RSEQ_ASM_TMP_REG32 "w15"#define RSEQ_ASM_TMP_REG "x15"#define RSEQ_ASM_TMP_REG_2 "x14"
@@ -691,5 +687,3 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-mips.h +0 -6
@@ -60,10 +60,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#if _MIPS_SZLONG ==64 # define LONG ".dword"# define LONG_LA "dla"
@@ -773,5 +769,3 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-ppc.h +0 -6
@@ -36,10 +36,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ }while (0 ) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -/* * The __rseq_cs_ptr_array and __rseq_cs sections can be used by debuggers to * better handle single-stepping through the restartable critical sections.
@@ -787,5 +783,3 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-riscv.h +0 -6
@@ -49,10 +49,6 @@ do { \RSEQ_WRITE_ONCE (*(p), v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define __RSEQ_ASM_DEFINE_TABLE (label, version, flags, start_ip, \ post_commit_offset, abort_ip) \ ".pushsection __rseq_cs, \"aw\"\n" \
@@ -673,5 +669,3 @@ int rseq_offset_deref_addv(intptr_t *ptr, off_t off, intptr_t inc, int cpu)rseq_bug ("cpu_id comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-s390.h +0 -5
@@ -28,10 +28,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#ifdef __s390x__#define LONG_L "lg"
@@ -607,4 +603,3 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,return rseq_cmpeqv_trymemcpy_storev (v, expect, dst, src, len, newv, cpu); } -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-skip.h deleted +0 -65
65 lines not on this page · raw message
tools/testing/selftests/rseq/rseq-x86.h +0 -12
@@ -50,10 +50,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define __RSEQ_ASM_DEFINE_TABLE (label, version, flags, \ start_ip, post_commit_offset, abort_ip) \ ".pushsection __rseq_cs, \"aw\"\n\t" \
@@ -629,8 +625,6 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect, newv, cpu); } -#endif /* !RSEQ_SKIP_FASTPATH */ -#elif defined(__i386__)#define RSEQ_ASM_TP_SEGMENT %%gs
@@ -657,10 +651,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ }while (0 ) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -/* * Use eax as scratch register and take memory operands as input to * lessen register pressure. Especially needed when compiling in O0.
@@ -1360,6 +1350,4 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect, #endif } -#endif /* !RSEQ_SKIP_FASTPATH */ -#endif
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: Remove RSEQ_SKIP_FASTPATH code
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 72cb1d7f2faca4fba81ab8417367d63852cd490c Gitweb: https://git.kernel.org/tip/72cb1d7f2faca4fba81ab8417367d63852cd490c Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:11 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:12 +01:00
selftests/rseq: Remove RSEQ_SKIP_FASTPATH code
This code is not currently build by the test Makefile, adds complexity, and is not overall useful considering that the abort handling loops to retry the fast-path.
--- tools/testing/selftests/rseq/param_test.c | 4 +- tools/testing/selftests/rseq/rseq-arm.h | 6 +-- tools/testing/selftests/rseq/rseq-arm64.h | 6 +-- tools/testing/selftests/rseq/rseq-mips.h | 6 +-- tools/testing/selftests/rseq/rseq-ppc.h | 6 +-- tools/testing/selftests/rseq/rseq-riscv.h | 6 +-- tools/testing/selftests/rseq/rseq-s390.h | 5 +-- tools/testing/selftests/rseq/rseq-skip.h | 65 +---------------------- tools/testing/selftests/rseq/rseq-x86.h | 12 +---- 9 files changed, 116 deletions(-) delete mode 100644 tools/testing/selftests/rseq/rseq-skip.h
tools/testing/selftests/rseq/param_test.c +0 -4
@@ -38,11 +38,7 @@ static int opt_yield, opt_signal, opt_sleep, opt_disable_rseq, opt_threads =200 , opt_disable_mod =0 , opt_test ='s' , opt_mb =0 ; -#ifndef RSEQ_SKIP_FASTPATH static long long opt_reps =5000 ; -#else -static long long opt_reps =100 ; -#endif static __thread __attribute__((tls_model ("initial-exec" )))unsigned int signals_delivered;
tools/testing/selftests/rseq/rseq-arm.h +0 -6
@@ -79,10 +79,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define __RSEQ_ASM_DEFINE_TABLE (label, version, flags, start_ip, \ post_commit_offset, abort_ip) \ ".pushsection __rseq_cs, \"aw\"\n\t" \
@@ -823,5 +819,3 @@ error2:rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-arm64.h +0 -6
@@ -85,10 +85,6 @@ do { \ } \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define RSEQ_ASM_TMP_REG32 "w15"#define RSEQ_ASM_TMP_REG "x15"#define RSEQ_ASM_TMP_REG_2 "x14"
@@ -691,5 +687,3 @@ error2:rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-mips.h +0 -6
@@ -60,10 +60,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#if _MIPS_SZLONG ==64 # define LONG ".dword"# define LONG_LA "dla"
@@ -773,5 +769,3 @@ error2:rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-ppc.h +0 -6
@@ -36,10 +36,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ }while (0 ) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -/* * The __rseq_cs_ptr_array and __rseq_cs sections can be used by debuggers to * better handle single-stepping through the restartable critical sections.
@@ -787,5 +783,3 @@ error2:rseq_bug ("expected value comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-riscv.h +0 -6
@@ -49,10 +49,6 @@ do { \RSEQ_WRITE_ONCE (*(p), v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define __RSEQ_ASM_DEFINE_TABLE (label, version, flags, start_ip, \ post_commit_offset, abort_ip) \ ".pushsection __rseq_cs, \"aw\"\n" \
@@ -673,5 +669,3 @@ error1:rseq_bug ("cpu_id comparison failed" );#endif } - -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-s390.h +0 -5
@@ -28,10 +28,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#ifdef __s390x__#define LONG_L "lg"
@@ -607,4 +603,3 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,return rseq_cmpeqv_trymemcpy_storev (v, expect, dst, src, len, newv, cpu); } -#endif /* !RSEQ_SKIP_FASTPATH */
tools/testing/selftests/rseq/rseq-skip.h deleted +0 -65
65 lines not on this page · raw message
tools/testing/selftests/rseq/rseq-x86.h +0 -12
@@ -50,10 +50,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ } while (0) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -#define __RSEQ_ASM_DEFINE_TABLE (label, version, flags, \ start_ip, post_commit_offset, abort_ip) \ ".pushsection __rseq_cs, \"aw\"\n\t" \
@@ -629,8 +625,6 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect, newv, cpu); } -#endif /* !RSEQ_SKIP_FASTPATH */ -#elif defined(__i386__)#define RSEQ_ASM_TP_SEGMENT %%gs
@@ -657,10 +651,6 @@ do { \RSEQ_WRITE_ONCE (*p, v); \ }while (0 ) -#ifdef RSEQ_SKIP_FASTPATH -#include "rseq-skip.h" -#else /* !RSEQ_SKIP_FASTPATH */ -/* * Use eax as scratch register and take memory operands as input to * lessen register pressure. Especially needed when compiling in O0.
@@ -1360,6 +1350,4 @@ error2: #endif } -#endif /* !RSEQ_SKIP_FASTPATH */ -#endif
Mathieu Desnoyers
maintainerPATCH 10/30 selftests/rseq: Implement rseq mm_cid field support
In reply to Mathieu DesnoyersAdd support for the mm_cid field (per-memory-map concurrency ID) of struct rseq to rseq selftests.
--- tools/testing/selftests/rseq/rseq-abi.h | 9 +++++++++ tools/testing/selftests/rseq/rseq.h | 10 ++++++++++ 2 files changed, 19 insertions(+)
tools/testing/selftests/rseq/rseq-abi.h +9 -0
@@ -155,6 +155,15 @@ struct rseq_abi {*/ __u32 node_id; +/* +* Restartable sequences mm_cid 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. Contains the current thread's concurrency ID +* (allocated uniquely within a memory map). +*/ +__u32 mm_cid; +/* * Flexible array member at end of structure, after last feature field. */
tools/testing/selftests/rseq/rseq.h +10 -0
@@ -191,6 +191,16 @@ static inline uint32_t rseq_current_node_id(void)return RSEQ_ACCESS_ONCE (rseq_get_abi ()->node_id); } +static inline bool rseq_mm_cid_available (void ) +{ + return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, mm_cid); +} + +static inline uint32_t rseq_current_mm_cid (void ) +{ +return RSEQ_ACCESS_ONCE (rseq_get_abi ()->mm_cid); +} +static inline void rseq_clear_rseq_cs (void ) {RSEQ_WRITE_ONCE (rseq_get_abi ()->rseq_cs.arch.ptr,0 );
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: Implement rseq mm_cid field support
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 18c2355838e76788f61849f4d83513b103d68b95 Gitweb: https://git.kernel.org/tip/18c2355838e76788f61849f4d83513b103d68b95 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:12 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:12 +01:00
selftests/rseq: Implement rseq mm_cid field support
Add support for the mm_cid field (per-memory-map concurrency ID) of struct rseq to rseq selftests.
--- tools/testing/selftests/rseq/rseq-abi.h | 9 +++++++++ tools/testing/selftests/rseq/rseq.h | 10 ++++++++++ 2 files changed, 19 insertions(+)
tools/testing/selftests/rseq/rseq-abi.h +9 -0
@@ -156,6 +156,15 @@ struct rseq_abi {__u32 node_id;/* +* Restartable sequences mm_cid 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. Contains the current thread's concurrency ID +* (allocated uniquely within a memory map). +*/ +__u32 mm_cid; + +/* * Flexible array member at end of structure, after last feature field. */ char end[];
tools/testing/selftests/rseq/rseq.h +10 -0
@@ -191,6 +191,16 @@ static inline uint32_t rseq_current_node_id(void)return RSEQ_ACCESS_ONCE (rseq_get_abi ()->node_id); } +static inline bool rseq_mm_cid_available (void ) +{ + return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, mm_cid); +} + +static inline uint32_t rseq_current_mm_cid (void ) +{ +return RSEQ_ACCESS_ONCE (rseq_get_abi ()->mm_cid); +} +static inline void rseq_clear_rseq_cs (void ) {RSEQ_WRITE_ONCE (rseq_get_abi ()->rseq_cs.arch.ptr,0 );
Mathieu Desnoyers
maintainerPATCH 11/30 selftests/rseq: x86: Template memory ordering and percpu access mode
In reply to Mathieu DesnoyersIntroduce a rseq-x86-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
This introduces changes to the rseq.h selftests API which require to update the rseq selftest programs. Similar API/templating changes need to be done for other architectures.
---
Changes since v4:
- Introduce RSEQ_TEMPLATE_CPU_ID_FIELD.
--- tools/testing/selftests/rseq/compiler.h | 6 + .../testing/selftests/rseq/rseq-bits-reset.h | 11 + .../selftests/rseq/rseq-bits-template.h | 41 + tools/testing/selftests/rseq/rseq-x86-bits.h | 993 ++++++++++++++ tools/testing/selftests/rseq/rseq-x86.h | 1181 +---------------- tools/testing/selftests/rseq/rseq.h | 159 +++ 6 files changed, 1241 insertions(+), 1150 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-bits-reset.h create mode 100644 tools/testing/selftests/rseq/rseq-bits-template.h create mode 100644 tools/testing/selftests/rseq/rseq-x86-bits.h
tools/testing/selftests/rseq/compiler.h +6 -0
@@ -27,4 +27,10 @@*/ #define rseq_after_asm_goto () asm volatile ("" : : : "memory") +/* Combine two tokens. */ +#define RSEQ__COMBINE_TOKENS (_tokena, _tokenb) \ + _tokena##_tokenb +#define RSEQ_COMBINE_TOKENS (_tokena, _tokenb) \ + RSEQ__COMBINE_TOKENS(_tokena, _tokenb) +#endif /* RSEQ_COMPILER_H_ */
tools/testing/selftests/rseq/rseq-bits-reset.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-bits-reset.h +* +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +*/ + +#undef RSEQ_TEMPLATE_IDENTIFIER +#undef RSEQ_TEMPLATE_CPU_ID_FIELD +#undef RSEQ_TEMPLATE_CPU_ID_OFFSET +#undef RSEQ_TEMPLATE_SUFFIX
tools/testing/selftests/rseq/rseq-bits-template.h new file +41 -0
41 lines not on this page · raw message
tools/testing/selftests/rseq/rseq-x86-bits.h new file +993 -0
993 lines not on this page · raw message
tools/testing/selftests/rseq/rseq-x86.h +31 -1150
1,215 lines not on this page · raw message
tools/testing/selftests/rseq/rseq.h +159 -0
169 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: x86: Template memory ordering and percpu access mode
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: ae31573843028ad17b1a807081c542d17fa9a83a Gitweb: https://git.kernel.org/tip/ae31573843028ad17b1a807081c542d17fa9a83a Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:13 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:12 +01:00
selftests/rseq: x86: Template memory ordering and percpu access mode
Introduce a rseq-x86-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
This introduces changes to the rseq.h selftests API which require to update the rseq selftest programs. Similar API/templating changes need to be done for other architectures.
--- tools/testing/selftests/rseq/compiler.h | 6 +- tools/testing/selftests/rseq/rseq-bits-reset.h | 11 +- tools/testing/selftests/rseq/rseq-bits-template.h | 41 +- tools/testing/selftests/rseq/rseq-x86-bits.h | 993 ++++++++++- tools/testing/selftests/rseq/rseq-x86.h | 1181 +------------ tools/testing/selftests/rseq/rseq.h | 159 ++- 6 files changed, 1241 insertions(+), 1150 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-bits-reset.h create mode 100644 tools/testing/selftests/rseq/rseq-bits-template.h create mode 100644 tools/testing/selftests/rseq/rseq-x86-bits.h
tools/testing/selftests/rseq/compiler.h +6 -0
@@ -27,4 +27,10 @@*/ #define rseq_after_asm_goto () asm volatile ("" : : : "memory") +/* Combine two tokens. */ +#define RSEQ__COMBINE_TOKENS (_tokena, _tokenb) \ + _tokena##_tokenb +#define RSEQ_COMBINE_TOKENS (_tokena, _tokenb) \ + RSEQ__COMBINE_TOKENS(_tokena, _tokenb) +#endif /* RSEQ_COMPILER_H_ */
tools/testing/selftests/rseq/rseq-bits-reset.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-bits-reset.h +* +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +*/ + +#undef RSEQ_TEMPLATE_IDENTIFIER +#undef RSEQ_TEMPLATE_CPU_ID_FIELD +#undef RSEQ_TEMPLATE_CPU_ID_OFFSET +#undef RSEQ_TEMPLATE_SUFFIX
tools/testing/selftests/rseq/rseq-bits-template.h new file +41 -0
41 lines not on this page · raw message
tools/testing/selftests/rseq/rseq-x86-bits.h new file +993 -0
993 lines not on this page · raw message
tools/testing/selftests/rseq/rseq-x86.h +31 -1150
1,215 lines not on this page · raw message
tools/testing/selftests/rseq/rseq.h +159 -0
169 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 12/30 selftests/rseq: arm: Template memory ordering and percpu access mode
In reply to Mathieu DesnoyersIntroduce a rseq-arm-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
---
Changes since v4:
- Use RSEQ_TEMPLATE_CPU_ID_FIELD.
--- tools/testing/selftests/rseq/rseq-arm-bits.h | 505 ++++++++++++++ tools/testing/selftests/rseq/rseq-arm.h | 695 +------------------ 2 files changed, 530 insertions(+), 670 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-arm-bits.h
tools/testing/selftests/rseq/rseq-arm-bits.h new file +505 -0
@@ -0,0 +1,505 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-arm-bits.h +* +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" +"bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" + "bne %l[error2]\n\t" +#endif +/* final store */ +"str %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +"ldr r0, %[v]\n\t" +"cmp %[expectnot], r0\n\t" +"beq %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +"ldr r0, %[v]\n\t" +"cmp %[expectnot], r0\n\t" + "beq %l[error2]\n\t" +#endif +"str r0, %[load]\n\t" +"add r0, %[voffp]\n\t" +"ldr r0, [r0]\n\t" +/* final store */ +"str r0, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "Ir" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +"ldr r0, %[v]\n\t" +"add r0, %[count]\n\t" +/* final store */ +"str r0, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(4) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [count] "Ir" (count) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" +"bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +"ldr r0, %[v2]\n\t" +"cmp %[expect2], r0\n\t" +"bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" +"bne %l[error2]\n\t" +"ldr r0, %[v2]\n\t" +"cmp %[expect2], r0\n\t" + "bne %l[error3]\n\t" +#endif +/* final store */ +"str %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && \ + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, + intptr_t *v2, intptr_t newv2, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne %l[error2]\n\t" +#endif + /* try store */ + "str %[newv2], %[v2]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "dmb\n\t" /* full mb provides store-release */ +#endif + /* final store */ + "str %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + "b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) + "5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, + void *dst, void *src, size_t len, + intptr_t newv, int cpu) +{ + uint32_t rseq_scratch[3]; + + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + "str %[src], %[rseq_scratch0]\n\t" + "str %[dst], %[rseq_scratch1]\n\t" + "str %[len], %[rseq_scratch2]\n\t" + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne 5f\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne 7f\n\t" +#endif + /* try memcpy */ + "cmp %[len], #0\n\t" \ + "beq 333f\n\t" \ + "222:\n\t" \ + "ldrb %%r0, [%[src]]\n\t" \ + "strb %%r0, [%[dst]]\n\t" \ + "adds %[src], #1\n\t" \ + "adds %[dst], #1\n\t" \ + "subs %[len], #1\n\t" \ + "bne 222b\n\t" \ + "333:\n\t" \ + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "dmb\n\t" /* full mb provides store-release */ +#endif + /* final store */ + "str %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t" + "b 8f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + abort, 1b, 2b, 4f) + RSEQ_ASM_DEFINE_CMPFAIL(5, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + cmpfail) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_CMPFAIL(6, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + error1) + RSEQ_ASM_DEFINE_CMPFAIL(7, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + error2) +#endif + "8:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), + /* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len), + [rseq_scratch0] "m" (rseq_scratch[0]), + [rseq_scratch1] "m" (rseq_scratch[1]), + [rseq_scratch2] "m" (rseq_scratch[2]) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-arm.h +25 -670
711 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: arm: Template memory ordering and percpu access mode
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 5bf4aba38a7686fd13f9800a42c39d2adef04fb0 Gitweb: https://git.kernel.org/tip/5bf4aba38a7686fd13f9800a42c39d2adef04fb0 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:14 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:13 +01:00
selftests/rseq: arm: Template memory ordering and percpu access mode
Introduce a rseq-arm-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
--- tools/testing/selftests/rseq/rseq-arm-bits.h | 505 +++++++++++++- tools/testing/selftests/rseq/rseq-arm.h | 695 +------------------ 2 files changed, 530 insertions(+), 670 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-arm-bits.h
tools/testing/selftests/rseq/rseq-arm-bits.h new file +505 -0
@@ -0,0 +1,505 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-arm-bits.h +* +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" +"bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" + "bne %l[error2]\n\t" +#endif +/* final store */ +"str %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +"ldr r0, %[v]\n\t" +"cmp %[expectnot], r0\n\t" +"beq %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +"ldr r0, %[v]\n\t" +"cmp %[expectnot], r0\n\t" + "beq %l[error2]\n\t" +#endif +"str r0, %[load]\n\t" +"add r0, %[voffp]\n\t" +"ldr r0, [r0]\n\t" +/* final store */ +"str r0, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "Ir" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +"ldr r0, %[v]\n\t" +"add r0, %[count]\n\t" +/* final store */ +"str r0, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(4) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [count] "Ir" (count) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" +"bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +"ldr r0, %[v2]\n\t" +"cmp %[expect2], r0\n\t" +"bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +"ldr r0, %[v]\n\t" +"cmp %[expect], r0\n\t" +"bne %l[error2]\n\t" +"ldr r0, %[v2]\n\t" +"cmp %[expect2], r0\n\t" + "bne %l[error3]\n\t" +#endif +/* final store */ +"str %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && \ + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, + intptr_t *v2, intptr_t newv2, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne %l[error2]\n\t" +#endif + /* try store */ + "str %[newv2], %[v2]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "dmb\n\t" /* full mb provides store-release */ +#endif + /* final store */ + "str %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + "b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) + "5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, + void *dst, void *src, size_t len, + intptr_t newv, int cpu) +{ + uint32_t rseq_scratch[3]; + + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + "str %[src], %[rseq_scratch0]\n\t" + "str %[dst], %[rseq_scratch1]\n\t" + "str %[len], %[rseq_scratch2]\n\t" + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne 5f\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) + "ldr r0, %[v]\n\t" + "cmp %[expect], r0\n\t" + "bne 7f\n\t" +#endif + /* try memcpy */ + "cmp %[len], #0\n\t" \ + "beq 333f\n\t" \ + "222:\n\t" \ + "ldrb %%r0, [%[src]]\n\t" \ + "strb %%r0, [%[dst]]\n\t" \ + "adds %[src], #1\n\t" \ + "adds %[dst], #1\n\t" \ + "subs %[len], #1\n\t" \ + "bne 222b\n\t" \ + "333:\n\t" \ + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "dmb\n\t" /* full mb provides store-release */ +#endif + /* final store */ + "str %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t" + "b 8f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + abort, 1b, 2b, 4f) + RSEQ_ASM_DEFINE_CMPFAIL(5, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + cmpfail) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_CMPFAIL(6, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + error1) + RSEQ_ASM_DEFINE_CMPFAIL(7, + /* teardown */ + "ldr %[len], %[rseq_scratch2]\n\t" + "ldr %[dst], %[rseq_scratch1]\n\t" + "ldr %[src], %[rseq_scratch0]\n\t", + error2) +#endif + "8:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), + /* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len), + [rseq_scratch0] "m" (rseq_scratch[0]), + [rseq_scratch1] "m" (rseq_scratch[1]), + [rseq_scratch2] "m" (rseq_scratch[2]) + RSEQ_INJECT_INPUT + : "r0", "memory", "cc" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-arm.h +25 -670
711 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 13/30 selftests/rseq: arm64: Template memory ordering and percpu access mode
In reply to Mathieu DesnoyersIntroduce a rseq-arm64-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
---
Changes since v4:
- Use RSEQ_TEMPLATE_CPU_ID_FIELD.
--- .../testing/selftests/rseq/rseq-arm64-bits.h | 392 +++++++++++++ tools/testing/selftests/rseq/rseq-arm64.h | 516 +----------------- 2 files changed, 422 insertions(+), 486 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-arm64-bits.h
tools/testing/selftests/rseq/rseq-arm64-bits.h new file +392 -0
@@ -0,0 +1,392 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-arm64-bits.h +* +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +* (C) Copyright 2018 - Will Deacon <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[error2]) +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_STORE (load ) +RSEQ_ASM_OP_R_LOAD_OFF (voffp) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (5 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [expectnot] "r" (expectnot), + [load] "Qo" (*load), + [voffp] "r" (voffp) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_ADD (count ) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (4 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error3]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[cmpfail]) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[error3]) +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [expect] "r" (expect), + [v2] "Qo" (*v2), + [expect2] "r" (expect2), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trystorev_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t newv2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + RSEQ_ASM_OP_STORE(newv2, v2) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "Qo" (*v), + [newv] "r" (newv), + [v2] "Qo" (*v2), + [newv2] "r" (newv2) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trymemcpy_storev )(intptr_t *v,intptr_t expect, +void *dst,void *src,size_t len, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + RSEQ_ASM_OP_R_BAD_MEMCPY(dst, src, len) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "Qo" (*v), + [newv] "r" (newv), + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG, RSEQ_ASM_TMP_REG_2 + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-arm64.h +30 -486
527 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: arm64: Template memory ordering and percpu access mode
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 8d4eeb8bb43262509c3e929e4d086ccaaec627a4 Gitweb: https://git.kernel.org/tip/8d4eeb8bb43262509c3e929e4d086ccaaec627a4 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:15 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:13 +01:00
selftests/rseq: arm64: Template memory ordering and percpu access mode
Introduce a rseq-arm64-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
--- tools/testing/selftests/rseq/rseq-arm64-bits.h | 392 ++++++++++++- tools/testing/selftests/rseq/rseq-arm64.h | 516 +---------------- 2 files changed, 422 insertions(+), 486 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-arm64-bits.h
tools/testing/selftests/rseq/rseq-arm64-bits.h new file +392 -0
@@ -0,0 +1,392 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-arm64-bits.h +* +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +* (C) Copyright 2018 - Will Deacon <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[error2]) +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_STORE (load ) +RSEQ_ASM_OP_R_LOAD_OFF (voffp) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (5 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [expectnot] "r" (expectnot), + [load] "Qo" (*load), + [voffp] "r" (voffp) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_ADD (count ) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (4 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error3]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[cmpfail]) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[error3]) +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "Qo" (*v), + [expect] "r" (expect), + [v2] "Qo" (*v2), + [expect2] "r" (expect2), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trystorev_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t newv2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + RSEQ_ASM_OP_STORE(newv2, v2) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "Qo" (*v), + [newv] "r" (newv), + [v2] "Qo" (*v2), + [newv2] "r" (newv2) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trymemcpy_storev )(intptr_t *v,intptr_t expect, +void *dst,void *src,size_t len, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, %l[error2]) +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + RSEQ_ASM_OP_R_BAD_MEMCPY(dst, src, len) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "Qo" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "Qo" (*v), + [newv] "r" (newv), + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG, RSEQ_ASM_TMP_REG_2 + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-arm64.h +30 -486
527 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 14/30 selftests/rseq: mips: Template memory ordering and percpu access mode
In reply to Mathieu DesnoyersIntroduce a rseq-mips-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
---
Changes since v4:
- Use RSEQ_TEMPLATE_CPU_ID_FIELD.
--- tools/testing/selftests/rseq/rseq-mips-bits.h | 462 +++++++++++++ tools/testing/selftests/rseq/rseq-mips.h | 640 +----------------- 2 files changed, 487 insertions(+), 615 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-mips-bits.h
tools/testing/selftests/rseq/rseq-mips-bits.h new file +462 -0
@@ -0,0 +1,462 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* Author: Paul Burton <[email protected]> +* (C) Copyright 2018 MIPS Tech LLC +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " $4, %[v]\n\t" +"bne $4, %[expect], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], %l[error2]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " $4, %[v]\n\t" +"beq $4, %[expectnot], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " $4, %[v]\n\t" + "beq $4, %[expectnot], %l[error2]\n\t" +#endif +LONG_S " $4, %[load]\n\t" +LONG_ADDI " $4, %[voffp]\n\t" +LONG_L " $4, 0($4)\n\t" +/* final store */ +LONG_S " $4, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "Ir" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +LONG_L " $4, %[v]\n\t" +LONG_ADDI " $4, %[count]\n\t" +/* final store */ +LONG_S " $4, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(4) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [count] "Ir" (count) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " $4, %[v]\n\t" +"bne $4, %[expect], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +LONG_L " $4, %[v2]\n\t" +"bne $4, %[expect2], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " $4, %[v]\n\t" +"bne $4, %[expect], %l[error2]\n\t" +LONG_L " $4, %[v2]\n\t" + "bne $4, %[expect2], %l[error3]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && \ + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, + intptr_t *v2, intptr_t newv2, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], %l[error2]\n\t" +#endif + /* try store */ + LONG_S " %[newv2], %[v2]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "sync\n\t" /* full sync provides store-release */ +#endif + /* final store */ + LONG_S " %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + "b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) + "5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + return 0; +abort: + RSEQ_INJECT_FAILED + return -1; +cmpfail: + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_bug("cpu_id comparison failed"); +error2: + rseq_bug("expected value comparison failed"); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, + void *dst, void *src, size_t len, + intptr_t newv, int cpu) +{ + uintptr_t rseq_scratch[3]; + + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + LONG_S " %[src], %[rseq_scratch0]\n\t" + LONG_S " %[dst], %[rseq_scratch1]\n\t" + LONG_S " %[len], %[rseq_scratch2]\n\t" + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], 5f\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], 7f\n\t" +#endif + /* try memcpy */ + "beqz %[len], 333f\n\t" \ + "222:\n\t" \ + "lb $4, 0(%[src])\n\t" \ + "sb $4, 0(%[dst])\n\t" \ + LONG_ADDI " %[src], 1\n\t" \ + LONG_ADDI " %[dst], 1\n\t" \ + LONG_ADDI " %[len], -1\n\t" \ + "bnez %[len], 222b\n\t" \ + "333:\n\t" \ + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "sync\n\t" /* full sync provides store-release */ +#endif + /* final store */ + LONG_S " %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t" + "b 8f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + abort, 1b, 2b, 4f) + RSEQ_ASM_DEFINE_CMPFAIL(5, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + cmpfail) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_CMPFAIL(6, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + error1) + RSEQ_ASM_DEFINE_CMPFAIL(7, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + error2) +#endif + "8:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), + /* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len), + [rseq_scratch0] "m" (rseq_scratch[0]), + [rseq_scratch1] "m" (rseq_scratch[1]), + [rseq_scratch2] "m" (rseq_scratch[2]) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + return 0; +abort: + RSEQ_INJECT_FAILED + return -1; +cmpfail: + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_bug("cpu_id comparison failed"); +error2: + rseq_bug("expected value comparison failed"); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-mips.h +25 -615
656 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: mips: Template memory ordering and percpu access mode
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 431b63285abc46d791874eadee8da12c835ce71d Gitweb: https://git.kernel.org/tip/431b63285abc46d791874eadee8da12c835ce71d Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:16 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:13 +01:00
selftests/rseq: mips: Template memory ordering and percpu access mode
Introduce a rseq-mips-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
--- tools/testing/selftests/rseq/rseq-mips-bits.h | 462 ++++++++++++- tools/testing/selftests/rseq/rseq-mips.h | 640 +----------------- 2 files changed, 487 insertions(+), 615 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-mips-bits.h
tools/testing/selftests/rseq/rseq-mips-bits.h new file +462 -0
@@ -0,0 +1,462 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* Author: Paul Burton <[email protected]> +* (C) Copyright 2018 MIPS Tech LLC +* (C) Copyright 2016-2022 - Mathieu Desnoyers <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " $4, %[v]\n\t" +"bne $4, %[expect], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], %l[error2]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " $4, %[v]\n\t" +"beq $4, %[expectnot], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " $4, %[v]\n\t" + "beq $4, %[expectnot], %l[error2]\n\t" +#endif +LONG_S " $4, %[load]\n\t" +LONG_ADDI " $4, %[voffp]\n\t" +LONG_L " $4, 0($4)\n\t" +/* final store */ +LONG_S " $4, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "Ir" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +LONG_L " $4, %[v]\n\t" +LONG_ADDI " $4, %[count]\n\t" +/* final store */ +LONG_S " $4, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(4) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [count] "Ir" (count) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " $4, %[v]\n\t" +"bne $4, %[expect], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +LONG_L " $4, %[v2]\n\t" +"bne $4, %[expect2], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " $4, %[v]\n\t" +"bne $4, %[expect], %l[error2]\n\t" +LONG_L " $4, %[v2]\n\t" + "bne $4, %[expect2], %l[error3]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +"b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) +"5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && \ + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, + intptr_t *v2, intptr_t newv2, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], %l[error2]\n\t" +#endif + /* try store */ + LONG_S " %[newv2], %[v2]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "sync\n\t" /* full sync provides store-release */ +#endif + /* final store */ + LONG_S " %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + "b 5f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort, 1b, 2b, 4f) + "5:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + return 0; +abort: + RSEQ_INJECT_FAILED + return -1; +cmpfail: + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_bug("cpu_id comparison failed"); +error2: + rseq_bug("expected value comparison failed"); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, + void *dst, void *src, size_t len, + intptr_t newv, int cpu) +{ + uintptr_t rseq_scratch[3]; + + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(9, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + LONG_S " %[src], %[rseq_scratch0]\n\t" + LONG_S " %[dst], %[rseq_scratch1]\n\t" + LONG_S " %[len], %[rseq_scratch2]\n\t" + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3f, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], 5f\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) + LONG_L " $4, %[v]\n\t" + "bne $4, %[expect], 7f\n\t" +#endif + /* try memcpy */ + "beqz %[len], 333f\n\t" \ + "222:\n\t" \ + "lb $4, 0(%[src])\n\t" \ + "sb $4, 0(%[dst])\n\t" \ + LONG_ADDI " %[src], 1\n\t" \ + LONG_ADDI " %[dst], 1\n\t" \ + LONG_ADDI " %[len], -1\n\t" \ + "bnez %[len], 222b\n\t" \ + "333:\n\t" \ + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + "sync\n\t" /* full sync provides store-release */ +#endif + /* final store */ + LONG_S " %[newv], %[v]\n\t" + "2:\n\t" + RSEQ_INJECT_ASM(6) + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t" + "b 8f\n\t" + RSEQ_ASM_DEFINE_ABORT(3, 4, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + abort, 1b, 2b, 4f) + RSEQ_ASM_DEFINE_CMPFAIL(5, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + cmpfail) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_CMPFAIL(6, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + error1) + RSEQ_ASM_DEFINE_CMPFAIL(7, + /* teardown */ + LONG_L " %[len], %[rseq_scratch2]\n\t" + LONG_L " %[dst], %[rseq_scratch1]\n\t" + LONG_L " %[src], %[rseq_scratch0]\n\t", + error2) +#endif + "8:\n\t" + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), + /* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len), + [rseq_scratch0] "m" (rseq_scratch[0]), + [rseq_scratch1] "m" (rseq_scratch[1]), + [rseq_scratch2] "m" (rseq_scratch[2]) + RSEQ_INJECT_INPUT + : "$4", "memory" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + return 0; +abort: + RSEQ_INJECT_FAILED + return -1; +cmpfail: + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_bug("cpu_id comparison failed"); +error2: + rseq_bug("expected value comparison failed"); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-mips.h +25 -615
656 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 15/30 selftests/rseq: ppc: Template memory ordering and percpu access mode
In reply to Mathieu DesnoyersIntroduce a rseq-ppc-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
---
Changes since v4:
- Use RSEQ_TEMPLATE_CPU_ID_FIELD.
--- tools/testing/selftests/rseq/rseq-ppc-bits.h | 454 ++++++++++++++ tools/testing/selftests/rseq/rseq-ppc.h | 611 +------------------ 2 files changed, 486 insertions(+), 579 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-ppc-bits.h
tools/testing/selftests/rseq/rseq-ppc-bits.h new file +454 -0
@@ -0,0 +1,454 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-ppc-bits.h +* +* (C) Copyright 2016-2018 - Mathieu Desnoyers <[email protected]> +* (C) Copyright 2016-2018 - Boqun Feng <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) +RSEQ_INJECT_ASM (3 ) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif +/* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) +RSEQ_INJECT_ASM (3 ) + /* cmp @v not equal to @expectnot */ + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v not equal to @expectnot */ + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[error2]) +#endif +/* load the value of @v */ +RSEQ_ASM_OP_R_LOAD (v) +/* store it in @load */ +RSEQ_ASM_OP_R_STORE (load ) +/* dereference voffp(v) */ +RSEQ_ASM_OP_R_LOADX (voffp) +/* final store the value at voffp(v) */ +RSEQ_ASM_OP_R_FINAL_STORE (v,2 ) +RSEQ_INJECT_ASM (5 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "b" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +/* load the value of @v */ +RSEQ_ASM_OP_R_LOAD (v) +/* add @count to it */ +RSEQ_ASM_OP_R_ADD (count ) +/* final store */ +RSEQ_ASM_OP_R_FINAL_STORE (v,2 ) +RSEQ_INJECT_ASM (4 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) +RSEQ_INJECT_ASM (3 ) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) +RSEQ_INJECT_ASM (4 ) + /* cmp @v2 equal to @expct2 */ + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[cmpfail]) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) + /* cmp @v2 equal to @expct2 */ + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[error3]) +#endif +/* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && \ + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, + intptr_t *v2, intptr_t newv2, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + /* try store */ + RSEQ_ASM_OP_STORE(newv2, v2) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + /* for 'release' */ + "lwsync\n\t" +#endif + /* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(6) + RSEQ_ASM_DEFINE_ABORT(4, abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, + void *dst, void *src, size_t len, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* setup for mempcy */ + "mr %%r19, %[len]\n\t" + "mr %%r20, %[src]\n\t" + "mr %%r21, %[dst]\n\t" + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + /* try memcpy */ + RSEQ_ASM_OP_R_MEMCPY() + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + /* for 'release' */ + "lwsync\n\t" +#endif + /* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(6) + /* teardown */ + RSEQ_ASM_DEFINE_ABORT(4, abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), + /* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17", "r18", "r19", "r20", "r21" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-ppc.h +32 -579
620 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: ppc: Template memory ordering and percpu access mode
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: e61bd94c2bbd6b258fb408092172e37d39b4bf5c Gitweb: https://git.kernel.org/tip/e61bd94c2bbd6b258fb408092172e37d39b4bf5c Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:17 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:14 +01:00
selftests/rseq: ppc: Template memory ordering and percpu access mode
Introduce a rseq-ppc-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
--- tools/testing/selftests/rseq/rseq-ppc-bits.h | 454 +++++++++++++- tools/testing/selftests/rseq/rseq-ppc.h | 611 +------------------ 2 files changed, 486 insertions(+), 579 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-ppc-bits.h
tools/testing/selftests/rseq/rseq-ppc-bits.h new file +454 -0
@@ -0,0 +1,454 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* rseq-ppc-bits.h +* +* (C) Copyright 2016-2018 - Mathieu Desnoyers <[email protected]> +* (C) Copyright 2016-2018 - Boqun Feng <[email protected]> +*/ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) +RSEQ_INJECT_ASM (3 ) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif +/* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) +RSEQ_INJECT_ASM (3 ) + /* cmp @v not equal to @expectnot */ + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v not equal to @expectnot */ + RSEQ_ASM_OP_CMPNE(v, expectnot, %l[error2]) +#endif +/* load the value of @v */ +RSEQ_ASM_OP_R_LOAD (v) +/* store it in @load */ +RSEQ_ASM_OP_R_STORE (load ) +/* dereference voffp(v) */ +RSEQ_ASM_OP_R_LOADX (voffp) +/* final store the value at voffp(v) */ +RSEQ_ASM_OP_R_FINAL_STORE (v,2 ) +RSEQ_INJECT_ASM (5 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "b" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +/* load the value of @v */ +RSEQ_ASM_OP_R_LOAD (v) +/* add @count to it */ +RSEQ_ASM_OP_R_ADD (count ) +/* final store */ +RSEQ_ASM_OP_R_FINAL_STORE (v,2 ) +RSEQ_INJECT_ASM (4 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ +RSEQ_ASM_STORE_RSEQ_CS (1 ,3b , rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) +RSEQ_INJECT_ASM (3 ) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) +RSEQ_INJECT_ASM (4 ) + /* cmp @v2 equal to @expct2 */ + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[cmpfail]) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE +/* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) + /* cmp @v2 equal to @expct2 */ + RSEQ_ASM_OP_CMPEQ(v2, expect2, %l[error3]) +#endif +/* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && \ + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, + intptr_t *v2, intptr_t newv2, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + /* try store */ + RSEQ_ASM_OP_STORE(newv2, v2) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + /* for 'release' */ + "lwsync\n\t" +#endif + /* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(6) + RSEQ_ASM_DEFINE_ABORT(4, abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, + void *dst, void *src, size_t len, + intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif + /* setup for mempcy */ + "mr %%r19, %[len]\n\t" + "mr %%r20, %[src]\n\t" + "mr %%r21, %[dst]\n\t" + /* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[cmpfail]) + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + /* cmp cpuid */ + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) + /* cmp @v equal to @expect */ + RSEQ_ASM_OP_CMPEQ(v, expect, %l[error2]) +#endif + /* try memcpy */ + RSEQ_ASM_OP_R_MEMCPY() + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + /* for 'release' */ + "lwsync\n\t" +#endif + /* final store */ + RSEQ_ASM_OP_FINAL_STORE(newv, v, 2) + RSEQ_INJECT_ASM(6) + /* teardown */ + RSEQ_ASM_DEFINE_ABORT(4, abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + /* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), + /* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len) + RSEQ_INJECT_INPUT + : "memory", "cc", "r17", "r18", "r19", "r20", "r21" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + rseq_after_asm_goto(); + return 0; +abort: + rseq_after_asm_goto(); + RSEQ_INJECT_FAILED + return -1; +cmpfail: + rseq_after_asm_goto(); + return 1; +#ifdef RSEQ_COMPARE_TWICE +error1: + rseq_after_asm_goto(); + rseq_bug("cpu_id comparison failed"); +error2: + rseq_after_asm_goto(); + rseq_bug("expected value comparison failed"); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && + (defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-ppc.h +32 -579
620 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 16/30 selftests/rseq: s390: Template memory ordering and percpu access mode
In reply to Mathieu DesnoyersIntroduce a rseq-s390-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
---
Changes since v4:
- Use RSEQ_TEMPLATE_CPU_ID_FIELD.
--- tools/testing/selftests/rseq/rseq-s390-bits.h | 474 +++++++++++++++++ tools/testing/selftests/rseq/rseq-s390.h | 490 +----------------- 2 files changed, 498 insertions(+), 466 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-s390-bits.h
tools/testing/selftests/rseq/rseq-s390-bits.h new file +474 -0
@@ -0,0 +1,474 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_CMP " %[expect], %[v]\n\t" + "jnz %l[error2]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +/* +* Compare @v against @expectnot. When it does _not_ match, load @v +* into @load, and store the content of *@v + voffp into @v. +*/ +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " %%r1, %[v]\n\t" +LONG_CMP_R " %%r1, %[expectnot]\n\t" +"je %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " %%r1, %[v]\n\t" +LONG_CMP_R " %%r1, %[expectnot]\n\t" + "je %l[error2]\n\t" +#endif +LONG_S " %%r1, %[load]\n\t" +LONG_ADD_R " %%r1, %[voffp]\n\t" +LONG_L " %%r1, 0(%%r1)\n\t" +/* final store */ +LONG_S " %%r1, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "r" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0", "r1" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +LONG_L " %%r0, %[v]\n\t" +LONG_ADD_R " %%r0, %[count]\n\t" +/* final store */ +LONG_S " %%r0, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(4) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +LONG_CMP " %[expect2], %[v2]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[error2]\n\t" +LONG_CMP " %[expect2], %[v2]\n\t" + "jnz %l[error3]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +/* s390 is TSO. */ +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trystorev_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t newv2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_CMP " %[expect], %[v]\n\t" + "jnz %l[error2]\n\t" +#endif +/* try store */ +LONG_S " %[newv2], %[v2]\n\t" +RSEQ_INJECT_ASM (5 ) + /* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +/* s390 is TSO. */ +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trymemcpy_storev )(intptr_t *v,intptr_t expect, +void *dst,void *src,size_t len, +intptr_t newv,int cpu) +{ +uint64_t rseq_scratch[3 ]; + + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +LONG_S " %[src], %[rseq_scratch0]\n\t" +LONG_S " %[dst], %[rseq_scratch1]\n\t" +LONG_S " %[len], %[rseq_scratch2]\n\t" +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz 5f\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) +LONG_CMP " %[expect], %[v]\n\t" + "jnz 7f\n\t" +#endif +/* try memcpy */ +LONG_LT_R " %[len], %[len]\n\t" +"jz 333f\n\t" +"222:\n\t" +"ic %%r0,0(%[src])\n\t" +"stc %%r0,0(%[dst])\n\t" +LONG_ADDI " %[src], 1\n\t" +LONG_ADDI " %[dst], 1\n\t" +LONG_ADDI " %[len], -1\n\t" +"jnz 222b\n\t" +"333:\n\t" +RSEQ_INJECT_ASM (5 ) + /* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" +RSEQ_INJECT_ASM (6 ) + /* teardown */ +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" +RSEQ_ASM_DEFINE_ABORT (4 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + abort) +RSEQ_ASM_DEFINE_CMPFAIL (5 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + cmpfail) +#ifdef RSEQ_COMPARE_TWICE +RSEQ_ASM_DEFINE_CMPFAIL (6 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + error1) +RSEQ_ASM_DEFINE_CMPFAIL (7 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + error2) +#endif + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), +/* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len), + [rseq_scratch0] "m" (rseq_scratch[0]), + [rseq_scratch1] "m" (rseq_scratch[1]), + [rseq_scratch2] "m" (rseq_scratch[2]) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-s390.h +24 -466
500 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: s390: Template memory ordering and percpu access mode
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: a94af3c58462d23c45879e1bbe86ed5702d5bd86 Gitweb: https://git.kernel.org/tip/a94af3c58462d23c45879e1bbe86ed5702d5bd86 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:18 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:14 +01:00
selftests/rseq: s390: Template memory ordering and percpu access mode
Introduce a rseq-s390-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
--- tools/testing/selftests/rseq/rseq-s390-bits.h | 474 ++++++++++++++++- tools/testing/selftests/rseq/rseq-s390.h | 490 +----------------- 2 files changed, 498 insertions(+), 466 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-s390-bits.h
tools/testing/selftests/rseq/rseq-s390-bits.h new file +474 -0
@@ -0,0 +1,474 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_CMP " %[expect], %[v]\n\t" + "jnz %l[error2]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +/* +* Compare @v against @expectnot. When it does _not_ match, load @v +* into @load, and store the content of *@v + voffp into @v. +*/ +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpnev_storeoffp_load )(intptr_t *v,intptr_t expectnot, +long voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_L " %%r1, %[v]\n\t" +LONG_CMP_R " %%r1, %[expectnot]\n\t" +"je %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_L " %%r1, %[v]\n\t" +LONG_CMP_R " %%r1, %[expectnot]\n\t" + "je %l[error2]\n\t" +#endif +LONG_S " %%r1, %[load]\n\t" +LONG_ADD_R " %%r1, %[voffp]\n\t" +LONG_L " %%r1, 0(%%r1)\n\t" +/* final store */ +LONG_S " %%r1, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expectnot] "r" (expectnot), + [voffp] "r" (voffp), + [load] "m" (*load) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0", "r1" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_addv )(intptr_t *v,intptr_t count,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +#endif +LONG_L " %%r0, %[v]\n\t" +LONG_ADD_R " %%r0, %[count]\n\t" +/* final store */ +LONG_S " %%r0, %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(4) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_cmpeqv_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +LONG_CMP " %[expect2], %[v2]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[error2]\n\t" +LONG_CMP " %[expect2], %[v2]\n\t" + "jnz %l[error3]\n\t" +#endif +/* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* cmp2 input */ + [v2] "m" (*v2), + [expect2] "r" (expect2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("1st expected value comparison failed" ); +error3: +rseq_after_asm_goto (); +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +/* s390 is TSO. */ +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trystorev_storev )(intptr_t *v,intptr_t expect, +intptr_t *v2,intptr_t newv2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz %l[cmpfail]\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) +LONG_CMP " %[expect], %[v]\n\t" + "jnz %l[error2]\n\t" +#endif +/* try store */ +LONG_S " %[newv2], %[v2]\n\t" +RSEQ_INJECT_ASM (5 ) + /* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* try store input */ + [v2] "m" (*v2), + [newv2] "r" (newv2), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +/* s390 is TSO. */ +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_trymemcpy_storev )(intptr_t *v,intptr_t expect, +void *dst,void *src,size_t len, +intptr_t newv,int cpu) +{ +uint64_t rseq_scratch[3 ]; + + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) +#endif +LONG_S " %[src], %[rseq_scratch0]\n\t" +LONG_S " %[dst], %[rseq_scratch1]\n\t" +LONG_S " %[len], %[rseq_scratch2]\n\t" +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +LONG_CMP " %[expect], %[v]\n\t" +"jnz 5f\n\t" + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) +LONG_CMP " %[expect], %[v]\n\t" + "jnz 7f\n\t" +#endif +/* try memcpy */ +LONG_LT_R " %[len], %[len]\n\t" +"jz 333f\n\t" +"222:\n\t" +"ic %%r0,0(%[src])\n\t" +"stc %%r0,0(%[dst])\n\t" +LONG_ADDI " %[src], 1\n\t" +LONG_ADDI " %[dst], 1\n\t" +LONG_ADDI " %[len], -1\n\t" +"jnz 222b\n\t" +"333:\n\t" +RSEQ_INJECT_ASM (5 ) + /* final store */ +LONG_S " %[newv], %[v]\n\t" +"2:\n\t" +RSEQ_INJECT_ASM (6 ) + /* teardown */ +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" +RSEQ_ASM_DEFINE_ABORT (4 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + abort) +RSEQ_ASM_DEFINE_CMPFAIL (5 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + cmpfail) +#ifdef RSEQ_COMPARE_TWICE +RSEQ_ASM_DEFINE_CMPFAIL (6 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + error1) +RSEQ_ASM_DEFINE_CMPFAIL (7 , +LONG_L " %[len], %[rseq_scratch2]\n\t" +LONG_L " %[dst], %[rseq_scratch1]\n\t" +LONG_L " %[src], %[rseq_scratch0]\n\t" , + error2) +#endif + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), +/* final store input */ + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv), +/* try memcpy input */ + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len), + [rseq_scratch0] "m" (rseq_scratch[0]), + [rseq_scratch1] "m" (rseq_scratch[1]), + [rseq_scratch2] "m" (rseq_scratch[2]) + RSEQ_INJECT_INPUT + : "memory", "cc", "r0" + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +cmpfail: +rseq_after_asm_goto (); +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_after_asm_goto (); +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_after_asm_goto (); +rseq_bug ("expected value comparison failed" ); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-s390.h +24 -466
500 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 17/30 selftests/rseq: riscv: Template memory ordering and percpu access mode
In reply to Mathieu DesnoyersIntroduce a rseq-riscv-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
---
Changes since v4:
- Use RSEQ_TEMPLATE_CPU_ID_FIELD.
--- .../testing/selftests/rseq/rseq-riscv-bits.h | 410 ++++++++++++++ tools/testing/selftests/rseq/rseq-riscv.h | 527 +----------------- 2 files changed, 437 insertions(+), 500 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-riscv-bits.h
tools/testing/selftests/rseq/rseq-riscv-bits.h new file +410 -0
@@ -0,0 +1,410 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_storev)(intptr_t *v, intptr_t expect, intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpnev_storeoffp_load)(intptr_t *v, intptr_t expectnot, +off_t voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPNE(v, expectnot, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPNE(v, expectnot, "%l[error2]") +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_STORE (load ) +RSEQ_ASM_OP_R_LOAD_OFF (voffp) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (5 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expectnot] "r" (expectnot), + [load] "m" (*load), + [voffp] "r" (voffp) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_addv)(intptr_t *v, intptr_t count, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_ADD (count ) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (4 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + :abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error3]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) + RSEQ_ASM_OP_CMPEQ(v2, expect2, "%l[cmpfail]") + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") + RSEQ_ASM_OP_CMPEQ(v2, expect2, "%l[error3]") +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [v2] "m" (*v2), + [expect2] "r" (expect2), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +error3: +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#define RSEQ_ARCH_HAS_OFFSET_DEREF_ADDV + +/* +* pval = *(ptr+off) +* *pval += inc; +*/ +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_offset_deref_addv)(intptr_t *ptr, off_t off, intptr_t inc, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") +#endif + RSEQ_ASM_OP_R_DEREF_ADDV(ptr, off, 3) + RSEQ_INJECT_ASM(4) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [ptr] "r" (ptr), + [off] "er" (off), + [inc] "er" (inc) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + :abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, +intptr_t *v2,intptr_t newv2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") +#endif + RSEQ_ASM_OP_STORE(newv2, v2) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "m" (*v), + [newv] "r" (newv), + [v2] "m" (*v2), + [newv2] "r" (newv2) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, +void *dst,void *src,size_t len, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") +#endif + RSEQ_ASM_OP_R_BAD_MEMCPY(dst, src, len) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "m" (*v), + [newv] "r" (newv), + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len) + RSEQ_INJECT_INPUT + :"memory" ,RSEQ_ASM_TMP_REG_1 ,RSEQ_ASM_TMP_REG_2 , + RSEQ_ASM_TMP_REG_3, RSEQ_ASM_TMP_REG_4 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-riscv.h +27 -500
534 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: riscv: Template memory ordering and percpu access mode
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 171586a6ab66fb6be064e399ac2024ab459dfcf9 Gitweb: https://git.kernel.org/tip/171586a6ab66fb6be064e399ac2024ab459dfcf9 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:19 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:14 +01:00
selftests/rseq: riscv: Template memory ordering and percpu access mode
Introduce a rseq-riscv-bits.h template header which is internally included to generate the static inline functions covering:
- relaxed and release memory ordering,
- per-cpu-id and per-mm-cid per-cpu data access.
--- tools/testing/selftests/rseq/rseq-riscv-bits.h | 410 ++++++++++++- tools/testing/selftests/rseq/rseq-riscv.h | 527 +---------------- 2 files changed, 437 insertions(+), 500 deletions(-) create mode 100644 tools/testing/selftests/rseq/rseq-riscv-bits.h
tools/testing/selftests/rseq/rseq-riscv-bits.h new file +410 -0
@@ -0,0 +1,410 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#include "rseq-bits-template.h" + +#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_storev)(intptr_t *v, intptr_t expect, intptr_t newv, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(5) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpnev_storeoffp_load)(intptr_t *v, intptr_t expectnot, +off_t voffp,intptr_t *load,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPNE(v, expectnot, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPNE(v, expectnot, "%l[error2]") +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_STORE (load ) +RSEQ_ASM_OP_R_LOAD_OFF (voffp) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (5 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expectnot] "r" (expectnot), + [load] "m" (*load), + [voffp] "r" (voffp) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_addv)(intptr_t *v, intptr_t count, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") +#endif +RSEQ_ASM_OP_R_LOAD (v) +RSEQ_ASM_OP_R_ADD (count ) +RSEQ_ASM_OP_R_FINAL_STORE (v,3 ) +RSEQ_INJECT_ASM (4 ) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [count] "r" (count) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + :abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t expect, +intptr_t *v2,intptr_t expect2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error3]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) + RSEQ_ASM_OP_CMPEQ(v2, expect2, "%l[cmpfail]") + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") + RSEQ_ASM_OP_CMPEQ(v2, expect2, "%l[error3]") +#endif + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [v] "m" (*v), + [expect] "r" (expect), + [v2] "m" (*v2), + [expect2] "r" (expect2), + [newv] "r" (newv) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2, error3 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +error3: +rseq_bug ("2nd expected value comparison failed" ); +#endif +} + +#define RSEQ_ARCH_HAS_OFFSET_DEREF_ADDV + +/* +* pval = *(ptr+off) +* *pval += inc; +*/ +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_offset_deref_addv)(intptr_t *ptr, off_t off, intptr_t inc, int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") +#endif + RSEQ_ASM_OP_R_DEREF_ADDV(ptr, off, 3) + RSEQ_INJECT_ASM(4) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [ptr] "r" (ptr), + [off] "er" (off), + [inc] "er" (inc) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + :abort +#ifdef RSEQ_COMPARE_TWICE + , error1 +#endif + ); +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +#endif +} + +#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect, +intptr_t *v2,intptr_t newv2, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") +#endif + RSEQ_ASM_OP_STORE(newv2, v2) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "m" (*v), + [newv] "r" (newv), + [v2] "m" (*v2), + [newv2] "r" (newv2) + RSEQ_INJECT_INPUT + : "memory", RSEQ_ASM_TMP_REG_1 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +static inline __always_inline +int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t expect, +void *dst,void *src,size_t len, +intptr_t newv,int cpu) +{ + RSEQ_INJECT_C(9) + __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f) + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]") +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]") + RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]") +#endif + RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs) + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) + RSEQ_INJECT_ASM(3) + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]") + RSEQ_INJECT_ASM(4) +#ifdef RSEQ_COMPARE_TWICE + RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]") + RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]") +#endif + RSEQ_ASM_OP_R_BAD_MEMCPY(dst, src, len) + RSEQ_INJECT_ASM(5) +#ifdef RSEQ_TEMPLATE_MO_RELEASE + RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3) +#else + RSEQ_ASM_OP_FINAL_STORE(newv, v, 3) +#endif + RSEQ_INJECT_ASM(6) +RSEQ_ASM_DEFINE_ABORT (4 , abort) + : /* gcc asm goto does not allow outputs */ + : [cpu_id] "r" (cpu), + [current_cpu_id] "m" (rseq_get_abi()->RSEQ_TEMPLATE_CPU_ID_FIELD), + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), + [expect] "r" (expect), + [v] "m" (*v), + [newv] "r" (newv), + [dst] "r" (dst), + [src] "r" (src), + [len] "r" (len) + RSEQ_INJECT_INPUT + :"memory" ,RSEQ_ASM_TMP_REG_1 ,RSEQ_ASM_TMP_REG_2 , + RSEQ_ASM_TMP_REG_3, RSEQ_ASM_TMP_REG_4 + RSEQ_INJECT_CLOBBER + : abort, cmpfail +#ifdef RSEQ_COMPARE_TWICE + , error1, error2 +#endif + ); + +return 0 ; +abort: +RSEQ_INJECT_FAILED + return -1; +cmpfail: +return 1 ; +#ifdef RSEQ_COMPARE_TWICE +error1: +rseq_bug ("cpu_id comparison failed" ); +error2: +rseq_bug ("expected value comparison failed" ); +#endif +} + +#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ + +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-riscv.h +27 -500
534 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 18/30 selftests/rseq: Implement basic percpu ops mm_cid test
In reply to Mathieu DesnoyersAdapt to the rseq.h API changes introduced by commits "selftests/rseq: <arch>: Template memory ordering and percpu access mode".
Build a new basic_percpu_ops_mm_cid_test to test the new "mm_cid" rseq field.
--- tools/testing/selftests/rseq/.gitignore | 1 + tools/testing/selftests/rseq/Makefile | 5 +- .../selftests/rseq/basic_percpu_ops_test.c | 46 ++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-)
tools/testing/selftests/rseq/.gitignore +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only basic_percpu_ops_test +basic_percpu_ops_mm_cid_test basic_test basic_rseq_op_test param_test
tools/testing/selftests/rseq/Makefile +4 -1
@@ -12,7 +12,7 @@ LDLIBS += -lpthread -ldl # still track changes to header files and depend on shared object. OVERRIDE_TARGETS = 1 -TEST_GEN_PROGS = basic_test basic_percpu_ops_test param_test \ +TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ param_test_benchmark param_test_compare_twice TEST_GEN_PROGS_EXTENDED = librseq.so
@@ -29,6 +29,9 @@ $(OUTPUT)/librseq.so: rseq.c rseq.h rseq-*.h $(OUTPUT)/%: %.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h $(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@ +$(OUTPUT)/basic_percpu_ops_mm_cid_test: basic_percpu_ops_test.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID_ID $< $(LDLIBS) -lrseq -o $@ + $(OUTPUT)/param_test_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ rseq.h rseq-*.h $(CC) $(CFLAGS) -DBENCHMARK $< $(LDLIBS) -lrseq -o $@
tools/testing/selftests/rseq/basic_percpu_ops_test.c +39 -7
85 lines not on this page · raw message
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: Implement basic percpu ops mm_cid test
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: cead72062756294dff01314b57b68e3e925ef321 Gitweb: https://git.kernel.org/tip/cead72062756294dff01314b57b68e3e925ef321 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:20 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:15 +01:00
selftests/rseq: Implement basic percpu ops mm_cid test
Adapt to the rseq.h API changes introduced by commits "selftests/rseq: <arch>: Template memory ordering and percpu access mode".
Build a new basic_percpu_ops_mm_cid_test to test the new "mm_cid" rseq field.
--- tools/testing/selftests/rseq/.gitignore | 1 +- tools/testing/selftests/rseq/Makefile | 5 +- tools/testing/selftests/rseq/basic_percpu_ops_test.c | 46 +++++++++-- 3 files changed, 44 insertions(+), 8 deletions(-)
tools/testing/selftests/rseq/.gitignore +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only basic_percpu_ops_test +basic_percpu_ops_mm_cid_test basic_test basic_rseq_op_test param_test
tools/testing/selftests/rseq/Makefile +4 -1
@@ -12,7 +12,7 @@ LDLIBS += -lpthread -ldl # still track changes to header files and depend on shared object. OVERRIDE_TARGETS = 1 -TEST_GEN_PROGS = basic_test basic_percpu_ops_test param_test \ +TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ param_test_benchmark param_test_compare_twice TEST_GEN_PROGS_EXTENDED = librseq.so
@@ -29,6 +29,9 @@ $(OUTPUT)/librseq.so: rseq.c rseq.h rseq-*.h $(OUTPUT)/%: %.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h $(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@ +$(OUTPUT)/basic_percpu_ops_mm_cid_test: basic_percpu_ops_test.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID_ID $< $(LDLIBS) -lrseq -o $@ + $(OUTPUT)/param_test_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ rseq.h rseq-*.h $(CC) $(CFLAGS) -DBENCHMARK $< $(LDLIBS) -lrseq -o $@
tools/testing/selftests/rseq/basic_percpu_ops_test.c +39 -7
85 lines not on this page · raw message
Mathieu Desnoyers
maintainerPATCH 19/30 selftests/rseq: Implement parametrized mm_cid test
In reply to Mathieu DesnoyersAdapt to the rseq.h API changes introduced by commits "selftests/rseq: <arch>: Template memory ordering and percpu access mode".
Build a new param_test_mm_cid, param_test_mm_cid_benchmark, and param_test_mm_cid_compare_twice executables to test the new "mm_cid" rseq field.
--- tools/testing/selftests/rseq/.gitignore | 3 + tools/testing/selftests/rseq/Makefile | 15 +- tools/testing/selftests/rseq/param_test.c | 148 ++++++++++++------ .../testing/selftests/rseq/run_param_test.sh | 5 + 4 files changed, 122 insertions(+), 49 deletions(-)
tools/testing/selftests/rseq/.gitignore +3 -0
@@ -6,3 +6,6 @@ basic_rseq_op_test param_test param_test_benchmark param_test_compare_twice +param_test_mm_cid +param_test_mm_cid_benchmark +param_test_mm_cid_compare_twice
tools/testing/selftests/rseq/Makefile +14 -1
@@ -13,7 +13,8 @@ LDLIBS += -lpthread -ldl OVERRIDE_TARGETS = 1 TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ - param_test_benchmark param_test_compare_twice + param_test_benchmark param_test_compare_twice param_test_mm_cid \ + param_test_mm_cid_benchmark param_test_mm_cid_compare_twice TEST_GEN_PROGS_EXTENDED = librseq.so
@@ -39,3 +40,15 @@ $(OUTPUT)/param_test_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ $(OUTPUT)/param_test_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ rseq.h rseq-*.h $(CC) $(CFLAGS) -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_cid: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_cid_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DBENCHMARK $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_cid_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
tools/testing/selftests/rseq/param_test.c +100 -48
296 lines not on this page · raw message
tools/testing/selftests/rseq/run_param_test.sh +5 -0
@@ -42,6 +42,11 @@ function do_tests() ./param_test ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 echo "Running compare-twice test ${TEST_NAME[$i]}" ./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 + + echo "Running mm_cid test ${TEST_NAME[$i]}" + ./param_test_mm_cid ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 + echo "Running mm_cid compare-twice test ${TEST_NAME[$i]}" + ./param_test_mm_cid_compare_twice ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 let "i++" done }
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: Implement parametrized mm_cid test
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: ee31fff091fa9c185d10844f9caf38784afe4745 Gitweb: https://git.kernel.org/tip/ee31fff091fa9c185d10844f9caf38784afe4745 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:21 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:15 +01:00
selftests/rseq: Implement parametrized mm_cid test
Adapt to the rseq.h API changes introduced by commits "selftests/rseq: <arch>: Template memory ordering and percpu access mode".
Build a new param_test_mm_cid, param_test_mm_cid_benchmark, and param_test_mm_cid_compare_twice executables to test the new "mm_cid" rseq field.
--- tools/testing/selftests/rseq/.gitignore | 3 +- tools/testing/selftests/rseq/Makefile | 15 +- tools/testing/selftests/rseq/param_test.c | 148 ++++++++++------ tools/testing/selftests/rseq/run_param_test.sh | 5 +- 4 files changed, 122 insertions(+), 49 deletions(-)
tools/testing/selftests/rseq/.gitignore +3 -0
@@ -6,3 +6,6 @@ basic_rseq_op_test param_test param_test_benchmark param_test_compare_twice +param_test_mm_cid +param_test_mm_cid_benchmark +param_test_mm_cid_compare_twice
tools/testing/selftests/rseq/Makefile +14 -1
@@ -13,7 +13,8 @@ LDLIBS += -lpthread -ldl OVERRIDE_TARGETS = 1 TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ - param_test_benchmark param_test_compare_twice + param_test_benchmark param_test_compare_twice param_test_mm_cid \ + param_test_mm_cid_benchmark param_test_mm_cid_compare_twice TEST_GEN_PROGS_EXTENDED = librseq.so
@@ -39,3 +40,15 @@ $(OUTPUT)/param_test_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ $(OUTPUT)/param_test_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ rseq.h rseq-*.h $(CC) $(CFLAGS) -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_cid: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_cid_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DBENCHMARK $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_cid_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
tools/testing/selftests/rseq/param_test.c +100 -48
296 lines not on this page · raw message
tools/testing/selftests/rseq/run_param_test.sh +5 -0
@@ -42,6 +42,11 @@ function do_tests() ./param_test ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 echo "Running compare-twice test ${TEST_NAME[$i]}" ./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 + + echo "Running mm_cid test ${TEST_NAME[$i]}" + ./param_test_mm_cid ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 + echo "Running mm_cid compare-twice test ${TEST_NAME[$i]}" + ./param_test_mm_cid_compare_twice ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1 let "i++" done }
Mathieu Desnoyers
maintainerPATCH 20/30 selftests/rseq: parametrized test: Report/abort on negative concurrency ID
In reply to Mathieu DesnoyersReport and abort when a negative concurrency ID value is observed by the spinlock test.
--- tools/testing/selftests/rseq/param_test.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/rseq/param_test.c +5 -0
@@ -410,6 +410,11 @@ static int rseq_this_cpu_lock(struct percpu_lock *lock)int ret; cpu =get_current_cpu_id (); +if (cpu <0 ) { +fprintf (stderr,"pid: %d: tid: %d, cpu: %d: cid: %d\n" , +getpid (), (int )rseq_gettid (),rseq_current_cpu_raw (), cpu); +abort (); + } ret =rseq_cmpeqv_storev (RSEQ_MO_RELAXED ,RSEQ_PERCPU , &lock->c[cpu].v,0 ,1 , cpu);
Signature · 1 line
2.25.1
[tip: sched/core] selftests/rseq: parametrized test: Report/abort on negative concurrency ID
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: a3798e6ffb37481c47773dd1d785c395c0785af8 Gitweb: https://git.kernel.org/tip/a3798e6ffb37481c47773dd1d785c395c0785af8 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:22 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:15 +01:00
selftests/rseq: parametrized test: Report/abort on negative concurrency ID
Report and abort when a negative concurrency ID value is observed by the spinlock test.
--- tools/testing/selftests/rseq/param_test.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/rseq/param_test.c +5 -0
@@ -410,6 +410,11 @@ static int rseq_this_cpu_lock(struct percpu_lock *lock)int ret; cpu =get_current_cpu_id (); +if (cpu <0 ) { +fprintf (stderr,"pid: %d: tid: %d, cpu: %d: cid: %d\n" , +getpid (), (int )rseq_gettid (),rseq_current_cpu_raw (), cpu); +abort (); + } ret =rseq_cmpeqv_storev (RSEQ_MO_RELAXED ,RSEQ_PERCPU , &lock->c[cpu].v,0 ,1 , cpu);
Mathieu Desnoyers
maintainerPATCH 21/30 tracing/rseq: Add mm_cid field to rseq_update
In reply to Mathieu DesnoyersAdd the mm_cid field to the rseq_update event, allowing tracers to follow which mm_cid is observed by user-space, and whether negative mm_cid values are visible in case of internal scheduler implementation issues.
---
Changes since v4:
- use task_mm_vcpu_id() to get the mm_vcpu_id from the task struct.
Changes since v5:
- rename vcpu_id to mm_cid.
--- include/trace/events/rseq.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/trace/events/rseq.h +4 -1
@@ -17,14 +17,17 @@ TRACE_EVENT(rseq_update,TP_STRUCT__entry (__field (s32 ,cpu_id )__field (s32, node_id) +__field (s32, mm_cid) ),TP_fast_assign ( __entry->cpu_id = raw_smp_processor_id(); __entry->node_id =cpu_to_node (__entry->cpu_id); + __entry->mm_cid =task_mm_cid (t); ), -TP_printk ("cpu_id=%d node_id=%d" , __entry->cpu_id, __entry->node_id) +TP_printk ("cpu_id=%d node_id=%d mm_cid=%d" , __entry->cpu_id, + __entry->node_id, __entry->mm_cid) ); TRACE_EVENT(rseq_ip_fixup,
Signature · 1 line
2.25.1
[tip: sched/core] tracing/rseq: Add mm_cid field to rseq_update
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 14a8644d4f76fb4afdfcc46e9193af867241bd42 Gitweb: https://git.kernel.org/tip/14a8644d4f76fb4afdfcc46e9193af867241bd42 Author: Mathieu Desnoyers <[email protected]> AuthorDate: Tue, 22 Nov 2022 15:39:23 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 27 Dec 2022 12:52:15 +01:00
tracing/rseq: Add mm_cid field to rseq_update
Add the mm_cid field to the rseq_update event, allowing tracers to follow which mm_cid is observed by user-space, and whether negative mm_cid values are visible in case of internal scheduler implementation issues.
--- include/trace/events/rseq.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/trace/events/rseq.h +4 -1
@@ -17,14 +17,17 @@ TRACE_EVENT(rseq_update,TP_STRUCT__entry (__field (s32 ,cpu_id )__field (s32, node_id) +__field (s32, mm_cid) ),TP_fast_assign ( __entry->cpu_id = raw_smp_processor_id(); __entry->node_id =cpu_to_node (__entry->cpu_id); + __entry->mm_cid =task_mm_cid (t); ), -TP_printk ("cpu_id=%d node_id=%d" , __entry->cpu_id, __entry->node_id) +TP_printk ("cpu_id=%d node_id=%d mm_cid=%d" , __entry->cpu_id, + __entry->node_id, __entry->mm_cid) ); TRACE_EVENT(rseq_ip_fixup,
Mathieu Desnoyers
maintainerPATCH 22/30 lib: Implement find_{first,next,nth}_notandnot_bit, find_first_andnot_bit
In reply to Mathieu DesnoyersAllow finding the first, next, or nth bit within two input bitmasks which is zero in both masks.
Allow fiding the first bit within two input bitmasks which is set in first mask and cleared in the second mask. find_next_andnot_bit and find_nth_andnot_bit already exist, so find the first bit appears to be missing.
--- include/linux/find.h | 123 +++++++++++++++++++++++++++++++++++++++++-- lib/find_bit.c | 42 +++++++++++++++ 2 files changed, 161 insertions(+), 4 deletions(-)
include/linux/find.h +119 -4
@@ -14,6 +14,8 @@ unsigned long _find_next_and_bit(const unsigned long *addr1, const unsigned long unsigned long nbits, unsigned long start);unsigned long _find_next_andnot_bit (const unsigned long *addr1,const unsigned long *addr2,unsigned long nbits,unsigned long start); +unsigned long _find_next_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long nbits,unsigned long start);unsigned long _find_next_zero_bit (const unsigned long *addr,unsigned long nbits,unsigned long start);extern unsigned long _find_first_bit (const unsigned long *addr,unsigned long size);
@@ -22,8 +24,14 @@ unsigned long __find_nth_and_bit(const unsigned long *addr1, const unsigned long unsigned long size, unsigned long n);unsigned long __find_nth_andnot_bit (const unsigned long *addr1,const unsigned long *addr2,unsigned long size,unsigned long n); +unsigned long __find_nth_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long size,unsigned long n);extern unsigned long _find_first_and_bit (const unsigned long *addr1,const unsigned long *addr2,unsigned long size); +extern unsigned long _find_first_andnot_bit (const unsigned long *addr1, +const unsigned long *addr2,unsigned long size); +extern unsigned long _find_first_notandnot_bit (const unsigned long *addr1, +const unsigned long *addr2,unsigned long size);extern unsigned long _find_first_zero_bit (const unsigned long *addr,unsigned long size);extern unsigned long _find_last_bit (const unsigned long *addr,unsigned long size);
@@ -95,15 +103,14 @@ unsigned long find_next_and_bit(const unsigned long *addr1,#ifndef find_next_andnot_bit/** -* find_next_andnot_bit - find the next set bit in *addr1 excluding all the bits -* in *addr2 +* find_next_andnot_bit - find the next bit set in *addr1, cleared in *addr2 * @addr1: The first address to base the search on * @addr2: The second address to base the search on * @size: The bitmap size in bits * @offset: The bitnumber to start searching at * -* Returns the bit number for the next set bit -* If no bits are set, returns @size. +* Returns the bit number for the next bit set in *addr1, cleared in *addr2 +* If no such bits are found, returns @size. */ static inline unsigned long find_next_andnot_bit(const unsigned long *addr1,
@@ -124,6 +131,37 @@ unsigned long find_next_andnot_bit(const unsigned long *addr1, }#endif +#ifndef find_next_notandnot_bit +/** +* find_next_notandnot_bit - find the next bit cleared in both *addr1 and *addr2 +* @addr1: The first address to base the search on +* @addr2: The second address to base the search on +* @size: The bitmap size in bits +* @offset: The bitnumber to start searching at +* +* Returns the bit number for the next bit cleared in both *addr1 and *addr2 +* If no such bits are found, returns @size. +*/ +static inline +unsigned long find_next_notandnot_bit (const unsigned long *addr1, +const unsigned long *addr2,unsigned long size, +unsigned long offset) +{ +if (small_const_nbits (size)) { +unsigned long val; + +if (unlikely (offset >= size)) +return size; + + val = ~*addr1 & ~*addr2 &GENMASK (size -1 , offset); +return val ?__ffs (val) : size; + } + +return _find_next_notandnot_bit (addr1, addr2, size, offset); +} +#endif + +#ifndef find_next_zero_bit/** * find_next_zero_bit - find the next cleared bit in a memory region
@@ -255,6 +293,32 @@ unsigned long find_nth_andnot_bit(const unsigned long *addr1, const unsigned lonreturn __find_nth_andnot_bit (addr1, addr2, size, n); } +/** +* find_nth_notandnot_bit - find N'th cleared bit in 2 memory regions. +* @addr1: The 1st address to start the search at +* @addr2: The 2nd address to start the search at +* @size: The maximum number of bits to search +* @n: The number of set bit, which position is needed, counting from 0 +* +* Returns the bit number of the N'th cleared bit. +* If no such, returns @size. +*/ +static inline +unsigned long find_nth_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long size,unsigned long n) +{ +if (n >= size) +return size; + +if (small_const_nbits (size)) { +unsigned long val = (~*addr1) & (~*addr2) &GENMASK (size -1 ,0 ); + +return val ?fns (val, n) : size; + } + +return __find_nth_notandnot_bit (addr1, addr2, size, n); +} +#ifndef find_first_and_bit/** * find_first_and_bit - find the first set bit in both memory regions
@@ -280,6 +344,57 @@ unsigned long find_first_and_bit(const unsigned long *addr1, }#endif +#ifndef find_first_andnot_bit +/** +* find_first_andnot_bit - find first set bit in 2 memory regions, +* flipping bits in 2nd region +* @addr1: The first address to base the search on +* @addr2: The second address to base the search on +* @size: The bitmap size in bits +* +* Returns the bit number for the next set bit +* If no bits are set, returns @size. +*/ +static inline +unsigned long find_first_andnot_bit (const unsigned long *addr1, +const unsigned long *addr2, +unsigned long size) +{ +if (small_const_nbits (size)) { +unsigned long val = *addr1 & (~*addr2) &GENMASK (size -1 ,0 ); + +return val ?__ffs (val) : size; + } + +return _find_first_andnot_bit (addr1, addr2, size); +} +#endif + +#ifndef find_first_notandnot_bit +/** +* find_first_notandnot_bit - find first cleared bit in 2 memory regions +* @addr1: The first address to base the search on +* @addr2: The second address to base the search on +* @size: The bitmap size in bits +* +* Returns the bit number for the next cleared bit +* If no bits are set, returns @size. +*/ +static inline +unsigned long find_first_notandnot_bit (const unsigned long *addr1, +const unsigned long *addr2, +unsigned long size) +{ +if (small_const_nbits (size)) { +unsigned long val = (~*addr1) & (~*addr2) &GENMASK (size -1 ,0 ); + +return val ?__ffs (val) : size; + } + +return _find_first_notandnot_bit (addr1, addr2, size); +} +#endif +#ifndef find_first_zero_bit/** * find_first_zero_bit - find the first cleared bit in a memory region
lib/find_bit.c +42 -0
60 lines not on this page · raw message
Signature · 1 line
2.25.1
Yury Norov
maintainerRe: [PATCH 22/30] lib: Implement find_{first,next,nth}_notandnot_bit, find_first_andnot_bit
Quoted 62 lines · Mathieu Desnoyers
Allow finding the first, next, or nth bit within two input bitmasks which is zero in both masks.
Allow fiding the first bit within two input bitmasks which is set in first mask and cleared in the second mask.
find_next_andnot_bitandfind_nth_andnot_bitalready exist, so find the first bit appears to be missing.Signed-off-by Mathieu Desnoyers <[email protected]>--- include/linux/find.h | 123 +++++++++++++++++++++++++++++++++++++++++-- lib/find_bit.c | 42 +++++++++++++++ 2 files changed, 161 insertions(+), 4 deletions(-)include/linux/find.h +11
-4@@ -14,6 +14,8 @@ unsigned long _find_next_and_bit(const unsigned long *addr1, const unsigned long unsigned long nbits, unsigned long start);unsigned long _find_next_andnot_bit (const unsigned long *addr1,const unsigned long *addr2,unsigned long nbits,unsigned long start); +unsigned long _find_next_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long nbits,unsigned long start);unsigned long _find_next_zero_bit (const unsigned long *addr,unsigned long nbits,unsigned long start);extern unsigned long _find_first_bit (const unsigned long *addr,unsigned long size);@@ -22,8 +24,14 @@ unsigned long __find_nth_and_bit(const unsigned long *addr1, const unsigned long unsigned long size, unsigned long n);unsigned long __find_nth_andnot_bit (const unsigned long *addr1,const unsigned long *addr2,unsigned long size,unsigned long n); +unsigned long __find_nth_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long size,unsigned long n);extern unsigned long _find_first_and_bit (const unsigned long *addr1,const unsigned long *addr2,unsigned long size); +extern unsigned long _find_first_andnot_bit (const unsigned long *addr1, +const unsigned long *addr2,unsigned long size); +extern unsigned long _find_first_notandnot_bit (const unsigned long *addr1, +const unsigned long *addr2,unsigned long size);extern unsigned long _find_first_zero_bit (const unsigned long *addr,unsigned long size);extern unsigned long _find_last_bit (const unsigned long *addr,unsigned long size);@@ -95,15 +103,14 @@ unsigned long find_next_and_bit(const unsigned long *addr1,#ifndef find_next_andnot_bit/** -* find_next_andnot_bit - find the next set bit in *addr1 excluding all the bits -* in *addr2 +* find_next_andnot_bit - find the next bit set in *addr1, cleared in *addr2 * @addr1: The first address to base the search on * @addr2: The second address to base the search on * @size: The bitmap size in bits * @offset: The bitnumber to start searching at * -* Returns the bit number for the next set bit -* If no bits are set, returns @size. +* Returns the bit number for the next bit set in *addr1, cleared in *addr2 +* If no such bits are found, returns @size. */ static inline unsigned long find_next_andnot_bit(const unsigned long *addr1,
include/linux/find.h unsigned long find_next_andnot_bit(const unsigned long *addr1, · line 134
Quoted 4 lines
include/linux/find.h +1
-0@@ -124,6 +131,37 @@ unsigned long find_next_andnot_bit(const unsigned long *addr1, }#endif +#ifndef find_next_notandnot_bit
You don't need ifdefs for new functions. If arch people will add their implementations, they will protect generic version themself.
Quoted 4 lines
include/linux/find.h +4
-0+/** +* find_next_notandnot_bit - find the next bit cleared in both *addr1 and *addr2 +* @addr1: The first address to base the search on +* @addr2: The second address to base the search on
include/linux/find.h unsigned long find_next_andnot_bit(const unsigned long *addr1, · line 148
Quoted 10 lines
include/linux/find.h +10
-0+* @size: The bitmap size in bits +* @offset: The bitnumber to start searching at +* +* Returns the bit number for the next bit cleared in both *addr1 and *addr2 +* If no such bits are found, returns @size. +*/ +static inline +unsigned long find_next_notandnot_bit (const unsigned long *addr1, +const unsigned long *addr2,unsigned long size, +unsigned long offset)
This should be find_next_zero_or_bit(). That way you'll avoid negation for both maps and be consistent with existing API.
Quoted 26 lines
include/linux/find.h +19
-0+{ +if (small_const_nbits (size)) { +unsigned long val; + +if (unlikely (offset >= size)) +return size; + + val = ~*addr1 & ~*addr2 &GENMASK (size -1 , offset); +return val ?__ffs (val) : size; + } + +return _find_next_notandnot_bit (addr1, addr2, size, offset); +} +#endif + +#ifndef find_next_zero_bit/** * find_next_zero_bit - find the next cleared bit in a memory region @@ -255,6 +293,32 @@ unsigned long find_nth_andnot_bit(const unsigned long *addr1, const unsigned lonreturn __find_nth_andnot_bit (addr1, addr2, size, n); } +/** +* find_nth_notandnot_bit - find N'th cleared bit in 2 memory regions. +* @addr1: The 1st address to start the search at
include/linux/find.h unsigned long find_nth_andnot_bit(const unsigned long *addr1, const unsigned lon · line 308
Quoted 10 lines
include/linux/find.h +10
-0+* @addr2: The 2nd address to start the search at +* @size: The maximum number of bits to search +* @n: The number of set bit, which position is needed, counting from 0 +* +* Returns the bit number of the N'th cleared bit. +* If no such, returns @size. +*/ +static inline +unsigned long find_nth_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long size,unsigned long n)
Same here. find_nth_zero_or_bit()
Thanks,
Yury
Quoted 144 lines
include/linux/find.h +64
-0+{ +if (n >= size) +return size; + +if (small_const_nbits (size)) { +unsigned long val = (~*addr1) & (~*addr2) &GENMASK (size -1 ,0 ); + +return val ?fns (val, n) : size; + } + +return __find_nth_notandnot_bit (addr1, addr2, size, n); +} +#ifndef find_first_and_bit/** * find_first_and_bit - find the first set bit in both memory regions @@ -280,6 +344,57 @@ unsigned long find_first_and_bit(const unsigned long *addr1, }#endif +#ifndef find_first_andnot_bit +/** +* find_first_andnot_bit - find first set bit in 2 memory regions, +* flipping bits in 2nd region +* @addr1: The first address to base the search on +* @addr2: The second address to base the search on +* @size: The bitmap size in bits +* +* Returns the bit number for the next set bit +* If no bits are set, returns @size. +*/ +static inline +unsigned long find_first_andnot_bit (const unsigned long *addr1, +const unsigned long *addr2, +unsigned long size) +{ +if (small_const_nbits (size)) { +unsigned long val = *addr1 & (~*addr2) &GENMASK (size -1 ,0 ); + +return val ?__ffs (val) : size; + } + +return _find_first_andnot_bit (addr1, addr2, size); +} +#endif + +#ifndef find_first_notandnot_bit +/** +* find_first_notandnot_bit - find first cleared bit in 2 memory regions +* @addr1: The first address to base the search on +* @addr2: The second address to base the search on +* @size: The bitmap size in bits +* +* Returns the bit number for the next cleared bit +* If no bits are set, returns @size. +*/ +static inline +unsigned long find_first_notandnot_bit (const unsigned long *addr1, +const unsigned long *addr2, +unsigned long size) +{ +if (small_const_nbits (size)) { +unsigned long val = (~*addr1) & (~*addr2) &GENMASK (size -1 ,0 ); + +return val ?__ffs (val) : size; + } + +return _find_first_notandnot_bit (addr1, addr2, size); +} +#endif +#ifndef find_first_zero_bit/** * find_first_zero_bit - find the first cleared bit in a memory region lib/find_bit.c +42
-0@@ -116,6 +116,32 @@ unsigned long _find_first_and_bit(const unsigned long *addr1,EXPORT_SYMBOL (_find_first_and_bit);#endif +#ifndef find_first_andnot_bit +/* +* Find the first set bit in two memory regions, flipping bits in 2nd region. +*/ +unsigned long _find_first_andnot_bit (const unsigned long *addr1, +const unsigned long *addr2, +unsigned long size) +{ + return FIND_FIRST_BIT(addr1[idx] & ~addr2[idx], /* nop */, size); +} +EXPORT_SYMBOL (_find_first_andnot_bit); +#endif + +#ifndef find_first_notandnot_bit +/* +* Find the first cleared bit in two memory regions. +*/ +unsigned long _find_first_notandnot_bit (const unsigned long *addr1, +const unsigned long *addr2, +unsigned long size) +{ + return FIND_FIRST_BIT(~addr1[idx] & ~addr2[idx], /* nop */, size); +} +EXPORT_SYMBOL (_find_first_notandnot_bit); +#endif +#ifndef find_first_zero_bit/* * Find the first cleared bit in a memory region. @@ -155,6 +181,13 @@ unsigned long __find_nth_andnot_bit(const unsigned long *addr1, const unsigned l }EXPORT_SYMBOL (__find_nth_andnot_bit); +unsigned long __find_nth_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long size,unsigned long n) +{ +return FIND_NTH_BIT (~addr1[idx] & ~addr2[idx], size, n); +} +EXPORT_SYMBOL (__find_nth_notandnot_bit); +#ifndef find_next_and_bitunsigned long _find_next_and_bit (const unsigned long *addr1,const unsigned long *addr2,unsigned long nbits,unsigned long start)@@ -173,6 +206,15 @@ unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsigned lEXPORT_SYMBOL (_find_next_andnot_bit);#endif +#ifndef find_next_notandnot_bit +unsigned long _find_next_notandnot_bit (const unsigned long *addr1,const unsigned long *addr2, +unsigned long nbits,unsigned long start) +{ + return FIND_NEXT_BIT(~addr1[idx] & ~addr2[idx], /* nop */, nbits, start); +} +EXPORT_SYMBOL (_find_next_notandnot_bit); +#endif +#ifndef find_next_zero_bitunsigned long _find_next_zero_bit (const unsigned long *addr,unsigned long nbits,unsigned long start)Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 23/30 cpumask: Implement cpumask_{first,next}_{not,}andnot
In reply to Mathieu DesnoyersAllow finding the first or next bit within two input cpumasks which is either:
- both zero and zero,
- respectively one and zero.
--- include/linux/cpumask.h | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
include/linux/cpumask.h +60 -0
@@ -153,6 +153,32 @@ unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumaskreturn find_first_and_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits); } +/** +* cpumask_first_andnot - return the first cpu from *srcp1 & ~*srcp2 +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_first_andnot (const struct cpumask *srcp1,const struct cpumask *srcp2) +{ +return find_first_andnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits); +} + +/** +* cpumask_first_notandnot - return the first cpu from ~*srcp1 & ~*srcp2 +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_first_notandnot (const struct cpumask *srcp1,const struct cpumask *srcp2) +{ +return find_first_notandnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits); +} +/** * cpumask_last - get the last CPU in a cpumask * @srcp: - the cpumask pointer
@@ -195,6 +221,40 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)return find_next_zero_bit (cpumask_bits (srcp), nr_cpumask_bits, n+1 ); } +/** +* cpumask_next_andnot - return the next cpu from *srcp1 & ~*srcp2 +* @n: the cpu prior to the place to search (ie. return will be > @n) +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_next_andnot (int n,const struct cpumask *srcp1,const struct cpumask *srcp2) +{ +/* -1 is a legal arg here. */ +if (n !=-1 ) +cpumask_check (n); +return find_next_andnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits, n+1 ); +} + +/** +* cpumask_next_notandnot - return the next cpu from ~*srcp1 & ~*srcp2 +* @n: the cpu prior to the place to search (ie. return will be > @n) +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_next_notandnot (int n,const struct cpumask *srcp1,const struct cpumask *srcp2) +{ +/* -1 is a legal arg here. */ +if (n !=-1 ) +cpumask_check (n); +return find_next_notandnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits, n+1 ); +} +#if NR_CPUS ==1 /* Uniprocessor: there is only one valid CPU */ static inline unsigned int cpumask_local_spread (unsigned int i,int node)
Signature · 1 line
2.25.1
Yury Norov
maintainerRe: [PATCH 23/30] cpumask: Implement cpumask_{first,next}_{not,}andnot
Quoted 31 lines · Mathieu Desnoyers
Allow finding the first or next bit within two input cpumasks which is either:
- both zero and zero,
- respectively one and zero.Signed-off-by Mathieu Desnoyers <[email protected]>--- include/linux/cpumask.h | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)include/linux/cpumask.h +12
-0@@ -153,6 +153,32 @@ unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumaskreturn find_first_and_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits); } +/** +* cpumask_first_andnot - return the first cpu from *srcp1 & ~*srcp2 +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_first_andnot (const struct cpumask *srcp1,const struct cpumask *srcp2) +{ +return find_first_andnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits); +}
include/linux/cpumask.h unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask · line 177
Quoted 10 lines
include/linux/cpumask.h +10
-0+ +/** +* cpumask_first_notandnot - return the first cpu from ~*srcp1 & ~*srcp2 +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_first_notandnot (const struct cpumask *srcp1,const struct cpumask *srcp2)
cpumask_first_zero_or
include/linux/cpumask.h unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask · line 180
Quoted 3 lines
include/linux/cpumask.h +3
-0+{ +return find_first_notandnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits); +}
Can you be consistent - either add cpumask_check for all new functions, or don't.
Quoted 25 lines
include/linux/cpumask.h +18
-0+/** * cpumask_last - get the last CPU in a cpumask * @srcp: - the cpumask pointer @@ -195,6 +221,40 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)return find_next_zero_bit (cpumask_bits (srcp), nr_cpumask_bits, n+1 ); } +/** +* cpumask_next_andnot - return the next cpu from *srcp1 & ~*srcp2 +* @n: the cpu prior to the place to search (ie. return will be > @n) +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_next_andnot (int n,const struct cpumask *srcp1,const struct cpumask *srcp2) +{ +/* -1 is a legal arg here. */ +if (n !=-1 ) +cpumask_check (n); +return find_next_andnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits, n+1 ); +} +
include/linux/cpumask.h static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp) · line 250
Quoted 10 lines
include/linux/cpumask.h +10
-0+/** +* cpumask_next_notandnot - return the next cpu from ~*srcp1 & ~*srcp2 +* @n: the cpu prior to the place to search (ie. return will be > @n) +* @src1p: the first input +* @src2p: the second input +* +* Returns >= nr_cpu_ids if no cpus match in both. +*/ +static inline +unsigned int cpumask_next_notandnot (int n,const struct cpumask *srcp1,const struct cpumask *srcp2)
same here: cpumask_next_zero_or()
Thanks,
Yury
Quoted 13 lines
include/linux/cpumask.h +7
-0+{ +/* -1 is a legal arg here. */ +if (n !=-1 ) +cpumask_check (n); +return find_next_notandnot_bit (cpumask_bits (srcp1),cpumask_bits (srcp2), nr_cpumask_bits, n+1 ); +} +#if NR_CPUS ==1 /* Uniprocessor: there is only one valid CPU */ static inline unsigned int cpumask_local_spread (unsigned int i,int node)Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 24/30 sched: NUMA-aware per-memory-map concurrency ID
In reply to Mathieu DesnoyersKeep track of a NUMA-aware concurrency ID. On NUMA systems, when a NUMA-aware concurrency ID is observed by user-space to be associated with a NUMA node, it is guaranteed to never change NUMA node unless a kernel-level NUMA configuration change happens.
Exposing a numa-aware concurrency ID is useful in situations where a process or a set of processes belonging to cpuset are pinned to a set of cores which belong to a subset of the system's NUMA nodes. In those situations, it is possible to benefit from the compactness of concurrency IDs over CPU ids, while keeping NUMA locality, for indexing a per-cpu data structure which takes into account NUMA locality.
--- include/linux/mm.h | 18 +++++ include/linux/mm_types.h | 68 +++++++++++++++- include/linux/sched.h | 3 + kernel/fork.c | 3 + kernel/sched/core.c | 8 +- kernel/sched/sched.h | 168 +++++++++++++++++++++++++++++++++++---- 6 files changed, 245 insertions(+), 23 deletions(-)
include/linux/mm.h +18 -0
@@ -3484,6 +3484,20 @@ static inline int task_mm_cid(struct task_struct *t) {return t->mm_cid; } +#ifdef CONFIG_NUMA +static inline int task_mm_numa_cid (struct task_struct *t) +{ +if (num_possible_nodes () ==1 ) +return task_mm_cid (t); +else +return t->mm_numa_cid; +} +#else +static inline int task_mm_numa_cid (struct task_struct *t) +{ +return task_mm_cid (t); +} +#endif #else static inline void sched_mm_cid_before_execve (struct task_struct *t) { }static inline void sched_mm_cid_after_execve (struct task_struct *t) { }
@@ -3498,6 +3512,10 @@ static inline int task_mm_cid(struct task_struct *t)*/ return raw_smp_processor_id (); } +static inline int task_mm_numa_cid (struct task_struct *t) +{ +return task_mm_cid (t); +}#endif #endif /* _LINUX_MM_H */
include/linux/mm_types.h +67 -1
88 lines not on this page · raw message
include/linux/sched.h +3 -0
@@ -1317,6 +1317,9 @@ struct task_struct {#ifdef CONFIG_SCHED_MM_CID int mm_cid;/* Current cid in mm */ int mm_cid_active;/* Whether cid bitmap is active */ +#ifdef CONFIG_NUMA +int mm_numa_cid;/* Current numa_cid in mm */ +#endif #endif struct tlbflush_unmap_batch tlb_ubc;
kernel/fork.c +3 -0
@@ -1050,6 +1050,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)#ifdef CONFIG_SCHED_MM_CID tsk->mm_cid =-1 ; tsk->mm_cid_active =0 ; +#ifdef CONFIG_NUMA + tsk->mm_numa_cid =-1 ; +#endif #endif return tsk;
kernel/sched/core.c +3 -5
@@ -11284,8 +11284,7 @@ void sched_mm_cid_exit_signals(struct task_struct *t)if (!mm)return ;local_irq_save (flags); -mm_cid_put (mm, t->mm_cid); - t->mm_cid =-1 ; +mm_cid_put (mm, t); t->mm_cid_active =0 ;local_irq_restore (flags); }
@@ -11298,8 +11297,7 @@ void sched_mm_cid_before_execve(struct task_struct *t)if (!mm)return ;local_irq_save (flags); -mm_cid_put (mm, t->mm_cid); - t->mm_cid =-1 ; +mm_cid_put (mm, t); t->mm_cid_active =0 ;local_irq_restore (flags); }
@@ -11312,7 +11310,7 @@ void sched_mm_cid_after_execve(struct task_struct *t)WARN_ON_ONCE ((t->flags &PF_KTHREAD ) || !t->mm);local_irq_save (flags); - t->mm_cid =mm_cid_get (mm); +mm_cid_get (mm, t); t->mm_cid_active =1 ;local_irq_restore (flags);rseq_set_notify_resume (t);
kernel/sched/sched.h +151 -17
204 lines not on this page · raw message
Signature · 1 line
2.25.1
Yury Norov
maintainerRe: [PATCH 24/30] sched: NUMA-aware per-memory-map concurrency ID
Quoted 112 lines · Mathieu Desnoyers
Keep track of a NUMA-aware concurrency ID. On NUMA systems, when a NUMA-aware concurrency ID is observed by user-space to be associated with a NUMA node, it is guaranteed to never change NUMA node unless a kernel-level NUMA configuration change happens.
Exposing a numa-aware concurrency ID is useful in situations where a process or a set of processes belonging to cpuset are pinned to a set of cores which belong to a subset of the system's NUMA nodes. In those situations, it is possible to benefit from the compactness of concurrency IDs over CPU ids, while keeping NUMA locality, for indexing a per-cpu data structure which takes into account NUMA locality.
Signed-off-by Mathieu Desnoyers <[email protected]>--- include/linux/mm.h | 18 +++++ include/linux/mm_types.h | 68 +++++++++++++++- include/linux/sched.h | 3 + kernel/fork.c | 3 + kernel/sched/core.c | 8 +- kernel/sched/sched.h | 168 +++++++++++++++++++++++++++++++++++---- 6 files changed, 245 insertions(+), 23 deletions(-)include/linux/mm.h +18
-0@@ -3484,6 +3484,20 @@ static inline int task_mm_cid(struct task_struct *t) {return t->mm_cid; } +#ifdef CONFIG_NUMA +static inline int task_mm_numa_cid (struct task_struct *t) +{ +if (num_possible_nodes () ==1 ) +return task_mm_cid (t); +else +return t->mm_numa_cid; +} +#else +static inline int task_mm_numa_cid (struct task_struct *t) +{ +return task_mm_cid (t); +} +#endif #else static inline void sched_mm_cid_before_execve (struct task_struct *t) { }static inline void sched_mm_cid_after_execve (struct task_struct *t) { }@@ -3498,6 +3512,10 @@ static inline int task_mm_cid(struct task_struct *t)*/ return raw_smp_processor_id (); } +static inline int task_mm_numa_cid (struct task_struct *t) +{ +return task_mm_cid (t); +}#endif #endif /* _LINUX_MM_H */ include/linux/mm_types.h +39
-0@@ -18,6 +18,7 @@#include <linux/page-flags-layout.h> #include <linux/workqueue.h> #include <linux/seqlock.h> +#include <linux/nodemask.h> #include <asm/mmu.h> @@ -847,15 +848,80 @@ static inline cpumask_t *mm_cidmask(struct mm_struct *mm)return (struct cpumask *)cid_bitmap; } +#ifdef CONFIG_NUMA +/* +* Layout of node cidmasks: +* - mm_numa cidmask: cpumask of the currently used mm_numa cids. +* - node_alloc cidmask: cpumask tracking which cid were +* allocated (across nodes) in this +* memory map. +* - node cidmask[nr_node_ids]: per-node cpumask tracking which cid +* were allocated in this memory map. +*/ +static inline cpumask_t *mm_numa_cidmask (struct mm_struct *mm) +{ +unsigned long cid_bitmap = (unsigned long )mm_cidmask (mm); + +/* Skip mm_cidmask */ + cid_bitmap +=cpumask_size (); +return (struct cpumask *)cid_bitmap; +} + +static inline cpumask_t *mm_node_alloc_cidmask (struct mm_struct *mm) +{ +unsigned long cid_bitmap = (unsigned long )mm_numa_cidmask (mm); + +/* Skip mm_numa_cidmask */ + cid_bitmap +=cpumask_size (); +return (struct cpumask *)cid_bitmap; +} + +static inline cpumask_t *mm_node_cidmask (struct mm_struct *mm,unsigned int node) +{ +unsigned long cid_bitmap = (unsigned long )mm_node_alloc_cidmask (mm); + +/* Skip node alloc cidmask */ + cid_bitmap +=cpumask_size (); + cid_bitmap += node *cpumask_size (); +return (struct cpumask *)cid_bitmap; +} +
include/linux/mm_types.h static inline cpumask_t *mm_cidmask(struct mm_struct *mm) · line 898
Quoted 10 lines
include/linux/mm_types.h +10
-0+static inline void mm_init_node_cidmask (struct mm_struct *mm) +{ +unsigned int node; + +if (num_possible_nodes () ==1 ) +return ; +cpumask_clear (mm_numa_cidmask (mm)); +cpumask_clear (mm_node_alloc_cidmask (mm)); +for (node =0 ; node < nr_node_ids; node++) +cpumask_clear (mm_node_cidmask (mm, node));
Can you use for_each_node() here? If so, I think it's worth to do it.
Quoted 113 lines
include/linux/mm_types.h +18
-1+} + +static inline unsigned int mm_node_cidmask_size (void ) +{ +if (num_possible_nodes () ==1 ) +return 0 ; +return (nr_node_ids +2 ) *cpumask_size (); +} +#else /* CONFIG_NUMA */ +static inline void mm_init_node_cidmask (struct mm_struct *mm) { } +static inline unsigned int mm_node_cidmask_size (void ) +{ +return 0 ; +} +#endif /* CONFIG_NUMA */ +static inline void mm_init_cid (struct mm_struct *mm) {raw_spin_lock_init (&mm->cid_lock);cpumask_clear (mm_cidmask (mm)); +mm_init_node_cidmask (mm); }static inline unsigned int mm_cid_size (void ) { -return cpumask_size (); +return cpumask_size () +mm_node_cidmask_size (); }#else /* CONFIG_SCHED_MM_CID */ static inline void mm_init_cid (struct mm_struct *mm) { }include/linux/sched.h +3
-0@@ -1317,6 +1317,9 @@ struct task_struct {#ifdef CONFIG_SCHED_MM_CID int mm_cid;/* Current cid in mm */ int mm_cid_active;/* Whether cid bitmap is active */ +#ifdef CONFIG_NUMA +int mm_numa_cid;/* Current numa_cid in mm */ +#endif #endif struct tlbflush_unmap_batch tlb_ubc;kernel/fork.c +3
-0@@ -1050,6 +1050,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)#ifdef CONFIG_SCHED_MM_CID tsk->mm_cid =-1 ; tsk->mm_cid_active =0 ; +#ifdef CONFIG_NUMA + tsk->mm_numa_cid =-1 ; +#endif #endif return tsk;kernel/sched/core.c +3
-5@@ -11284,8 +11284,7 @@ void sched_mm_cid_exit_signals(struct task_struct *t)if (!mm)return ;local_irq_save (flags); -mm_cid_put (mm, t->mm_cid); - t->mm_cid =-1 ; +mm_cid_put (mm, t); t->mm_cid_active =0 ;local_irq_restore (flags); }@@ -11298,8 +11297,7 @@ void sched_mm_cid_before_execve(struct task_struct *t)if (!mm)return ;local_irq_save (flags); -mm_cid_put (mm, t->mm_cid); - t->mm_cid =-1 ; +mm_cid_put (mm, t); t->mm_cid_active =0 ;local_irq_restore (flags); }@@ -11312,7 +11310,7 @@ void sched_mm_cid_after_execve(struct task_struct *t)WARN_ON_ONCE ((t->flags &PF_KTHREAD ) || !t->mm);local_irq_save (flags); - t->mm_cid =mm_cid_get (mm); +mm_cid_get (mm, t); t->mm_cid_active =1 ;local_irq_restore (flags);rseq_set_notify_resume (t);kernel/sched/sched.h +13
-1@@ -3262,38 +3262,174 @@ static inline void update_current_exec_runtime(struct task_struct *curr, } #ifdef CONFIG_SCHED_MM_CID -static inline int __mm_cid_get (struct mm_struct *mm) +#ifdef CONFIG_NUMA +static inline void __mm_numa_cid_get(struct mm_struct *mm, struct task_struct *t) +{ + struct cpumask *cpumask = mm_numa_cidmask(mm), + *node_cpumask = mm_node_cidmask(mm, numa_node_id()), + *node_alloc_cpumask = mm_node_alloc_cidmask(mm); + unsigned int node; + int cid; + + if (num_possible_nodes() == 1) { + cid = -1; + goto end; + }
kernel/sched/sched.h static inline void update_current_exec_runtime(struct task_struct *curr, · line 3287
Quoted 10 lines
kernel/sched/sched.h +10
-0+ +/* +* Try to reserve lowest available cid number within those already +* reserved for this NUMA node. +*/ + cid =cpumask_first_andnot (node_cpumask, cpumask); +if (cid >= nr_cpu_ids) + goto alloc_numa; +__cpumask_set_cpu (cid, cpumask); + goto end;
The 'end' is just a 't->mm_numa_cid = cid;' I think it would be less confusing if you drop it:
cid = cpumask_first_andnot();
if (cid < nr_cpu_ids) {
t->mm_numa_cid = cid;
return;
}This would also let you to remove 'alloc_numa' label.
kernel/sched/sched.h static inline void update_current_exec_runtime(struct task_struct *curr, · line 3300
Quoted 13 lines
kernel/sched/sched.h +13
-0+ +alloc_numa: +/* +* Try to reserve lowest available cid number within those not already +* allocated for numa nodes. +*/ + cid =cpumask_first_notandnot (node_alloc_cpumask, cpumask); +if (cid >= nr_cpu_ids) + goto numa_update; +__cpumask_set_cpu (cid, cpumask); +__cpumask_set_cpu (cid, node_cpumask); +__cpumask_set_cpu (cid, node_alloc_cpumask); + goto end;
Same here. Reverse conditional and return from if() branch.
kernel/sched/sched.h static inline void update_current_exec_runtime(struct task_struct *curr, · line 3314
Quoted 13 lines
kernel/sched/sched.h +13
-0+numa_update: +/* +* NUMA node id configuration changed for at least one CPU in the system. +* We need to steal a currently unused cid from an overprovisioned +* node for our current node. Userspace must handle the fact that the +* node id associated with this cid may change due to node ID +* reconfiguration. +* +* Count how many possible cpus are attached to each (other) node id, +* and compare this with the per-mm node cidmask cpu count. Find one +* which has too many cpus in its mask to steal from. +*/ +for (node =0 ; node < nr_node_ids; node++) {
Again, for_each_node()?
Quoted 5 lines
kernel/sched/sched.h +5
-0+struct cpumask *iter_cpumask; + +if (node ==numa_node_id ()) +continue ; + iter_cpumask =mm_node_cidmask (mm, node);
kernel/sched/sched.h static inline void update_current_exec_runtime(struct task_struct *curr, · line 3329
Quoted 10 lines
kernel/sched/sched.h +10
-0+if (nr_cpus_node (node) <cpumask_weight (iter_cpumask)) { +/* Try to steal from this node. */ + cid =cpumask_first_andnot (iter_cpumask, cpumask); +if (cid >= nr_cpu_ids) + goto steal_fail; +__cpumask_set_cpu (cid, cpumask); +__cpumask_clear_cpu (cid, iter_cpumask); +__cpumask_set_cpu (cid, node_cpumask); + goto end; + }
Same here, you can reverse conditional and drop goto's.
Quoted 139 lines
kernel/sched/sched.h +86
-16+ } + +steal_fail: +/* +* Our attempt at gracefully stealing a cid from another +* overprovisioned NUMA node failed. Fallback to grabbing the first +* available cid. +*/ + cid =cpumask_first_zero (cpumask); +if (cid >= nr_cpu_ids) { + cid =-1 ; + goto end; + } +__cpumask_set_cpu (cid, cpumask); +/* Steal cid from its numa node mask. */ +for (node =0 ; node < nr_node_ids; node++) { +struct cpumask *iter_cpumask; + +if (node ==numa_node_id ()) +continue ; + iter_cpumask =mm_node_cidmask (mm, node); +if (cpumask_test_cpu (cid, iter_cpumask)) { +__cpumask_clear_cpu (cid, iter_cpumask); +break ; + } + } +__cpumask_set_cpu (cid, node_cpumask); +end: + t->mm_numa_cid = cid; +} + +static inline void __mm_numa_cid_put (struct mm_struct *mm,struct task_struct *t) +{ +int cid = t->mm_numa_cid; + +if (num_possible_nodes () ==1 ) +return ; +if (cid <0 ) +return ; +__cpumask_clear_cpu (cid,mm_numa_cidmask (mm)); + t->mm_numa_cid =-1 ; +} + +static inline void mm_numa_transfer_cid_prev_next (struct task_struct *prev,struct task_struct *next) +{ + next->mm_numa_cid = prev->mm_numa_cid; + prev->mm_numa_cid =-1 ; +} +#else +static inline void __mm_numa_cid_get (struct mm_struct *mm,struct task_struct *t) { } +static inline void __mm_numa_cid_put (struct mm_struct *mm,struct task_struct *t) { } +static inline void mm_numa_transfer_cid_prev_next (struct task_struct *prev,struct task_struct *next) { } +#endif + +static inline void __mm_cid_get (struct mm_struct *mm,struct task_struct *t) {struct cpumask *cpumask;int cid; cpumask =mm_cidmask (mm); cid =cpumask_first_zero (cpumask); -if (cid >= nr_cpu_ids) -return -1 ; +if (cid >= nr_cpu_ids) { + cid =-1 ; + goto end; + }__cpumask_set_cpu (cid, cpumask); -return cid; +end: + t->mm_cid = cid; } -static inline void mm_cid_put (struct mm_struct *mm,int cid) +static inline void mm_cid_get (struct mm_struct *mm,struct task_struct *t) {lockdep_assert_irqs_disabled (); -if (cid <0 ) -return ;raw_spin_lock (&mm->cid_lock); -__cpumask_clear_cpu (cid,mm_cidmask (mm)); +__mm_cid_get (mm, t); +__mm_numa_cid_get (mm, t);raw_spin_unlock (&mm->cid_lock); } -static inline int mm_cid_get (struct mm_struct *mm) +static inline void __mm_cid_put (struct mm_struct *mm,struct task_struct *t) { -int ret; +int cid = t->mm_cid; + +if (cid <0 ) +return ; +__cpumask_clear_cpu (cid,mm_cidmask (mm)); + t->mm_cid =-1 ; +} +static inline void mm_cid_put (struct mm_struct *mm,struct task_struct *t) +{lockdep_assert_irqs_disabled ();raw_spin_lock (&mm->cid_lock); - ret =__mm_cid_get (mm); +__mm_cid_put (mm, t); +__mm_numa_cid_put (mm, t);raw_spin_unlock (&mm->cid_lock); -return ret; +} + +static inline void mm_transfer_cid_prev_next (struct task_struct *prev,struct task_struct *next) +{ + next->mm_cid = prev->mm_cid; + prev->mm_cid =-1 ; +mm_numa_transfer_cid_prev_next (prev, next); }static inline void switch_mm_cid (struct task_struct *prev,struct task_struct *next)@@ -3304,15 +3440,13 @@ static inline void switch_mm_cid(struct task_struct *prev, struct task_struct *n* Context switch between threads in same mm, hand over * the mm_cid from prev to next. */ - next->mm_cid = prev->mm_cid; - prev->mm_cid =-1 ; +mm_transfer_cid_prev_next (prev, next); return; } -mm_cid_put (prev->mm, prev->mm_cid); - prev->mm_cid =-1 ; +mm_cid_put (prev->mm, prev); }if (next->mm_cid_active) - next->mm_cid =mm_cid_get (next->mm); +mm_cid_get (next->mm, next); }#else Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 25/30 rseq: Extend struct rseq with per-memory-map NUMA-aware Concurrency ID
In reply to Mathieu DesnoyersExpose a per-memory-map NUMA-aware concurrency ID to userspace. Each concurrency ID stays associated with the same NUMA node except in case of NUMA topology reconfiguration.
--- include/uapi/linux/rseq.h | 9 +++++++++ kernel/rseq.c | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-)
include/uapi/linux/rseq.h +9 -0
@@ -148,6 +148,15 @@ struct rseq {*/ __u32 mm_cid; +/* +* Restartable sequences mm_numa_cid 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. Contains the current thread's +* NUMA-aware concurrency ID (allocated uniquely within a memory map). +*/ +__u32 mm_numa_cid; +/* * Flexible array member at end of structure, after last feature field. */
kernel/rseq.c +9 -1
@@ -91,14 +91,17 @@ static int rseq_update_cpu_node_id(struct task_struct *t)u32 cpu_id =raw_smp_processor_id ();u32 node_id =cpu_to_node (cpu_id);u32 mm_cid =task_mm_cid (t); +u32 mm_numa_cid =task_mm_numa_cid (t);WARN_ON_ONCE ((int ) mm_cid <0 ); +WARN_ON_ONCE ((int ) mm_numa_cid <0 );if (!user_write_access_begin (rseq, t->rseq_len)) goto efault;unsafe_put_user (cpu_id, &rseq->cpu_id_start, efault_end);unsafe_put_user (cpu_id, &rseq->cpu_id, efault_end);unsafe_put_user (node_id, &rseq->node_id, efault_end);unsafe_put_user (mm_cid, &rseq->mm_cid, efault_end); +unsafe_put_user (mm_numa_cid, &rseq->mm_numa_cid, efault_end);/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally updated only if
@@ -117,7 +120,7 @@ static int rseq_update_cpu_node_id(struct task_struct *t)static int rseq_reset_rseq_cpu_node_id (struct task_struct *t) {u32 cpu_id_start =0 , cpu_id =RSEQ_CPU_ID_UNINITIALIZED , node_id =0 , - mm_cid =0 ; + mm_cid =0 , mm_numa_cid =0 ;/* * Reset cpu_id_start to its initial state (0).
@@ -141,6 +144,11 @@ static int rseq_reset_rseq_cpu_node_id(struct task_struct *t)*/ if (put_user (mm_cid, &t->rseq->mm_cid))return -EFAULT ; +/* +* Reset mm_numa_cid to its initial state (0). +*/ +if (put_user (mm_numa_cid, &t->rseq->mm_numa_cid)) +return -EFAULT ;/* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally reset only if
Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 26/30 selftests/rseq: x86: Implement rseq_load_u32_u32
In reply to Mathieu DesnoyersAllow loading a pair of u32 within a rseq critical section. It can be used in situations where both rseq_abi()->mm_numa_cid and rseq_abi()->node_id need to be sampled atomically with respect to preemption, signal delivery and migration.
--- tools/testing/selftests/rseq/rseq-x86-bits.h | 43 ++++++++++++++++++++ tools/testing/selftests/rseq/rseq.h | 14 +++++++ 2 files changed, 57 insertions(+)
tools/testing/selftests/rseq/rseq-x86-bits.h +43 -0
@@ -990,4 +990,47 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t#endif +#if defined(RSEQ_TEMPLATE_CPU_ID_NONE ) && defined(RSEQ_TEMPLATE_MO_RELAXED ) + +#define RSEQ_ARCH_HAS_LOAD_U32_U32 + +static inline __attribute__((always_inline)) +int RSEQ_TEMPLATE_IDENTIFIER (rseq_load_u32_u32 )(uint32_t *dst1,uint32_t *src1, +uint32_t *dst2,uint32_t *src2) +{ + RSEQ_INJECT_C(9) + + __asm__ __volatile__ goto ( + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ +/* Start rseq by storing table entry pointer into rseq_cs. */ + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) + RSEQ_INJECT_ASM(3) +"movl %[src1], %%eax\n\t" +"movl %%eax, %[dst1]\n\t" +"movl %[src2], %%eax\n\t" +"movl %%eax, %[dst2]\n\t" +"2:\n\t" + RSEQ_INJECT_ASM(4) +RSEQ_ASM_DEFINE_ABORT (4 ,"" , abort) + : /* gcc asm goto does not allow outputs */ + : [rseq_offset] "r" (rseq_offset), +/* final store input */ + [dst1] "m" (*dst1), + [src1] "m" (*src1), + [dst2] "m" (*dst2), + [src2] "m" (*src2) + : "memory", "cc", "rax" + RSEQ_INJECT_CLOBBER + : abort + ); +rseq_after_asm_goto (); +return 0 ; +abort: +rseq_after_asm_goto (); +RSEQ_INJECT_FAILED + return -1; +} + +#endif /* defined(RSEQ_TEMPLATE_CPU_ID_NONE) && defined(RSEQ_TEMPLATE_MO_RELAXED) */ +#include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq.h +14 -0
@@ -381,4 +381,18 @@ int rseq_cmpeqv_trymemcpy_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode per } } +#ifdef RSEQ_ARCH_HAS_LOAD_U32_U32 + +static inline __attribute__((always_inline)) +int rseq_load_u32_u32 (enum rseq_mo rseq_mo, +uint32_t *dst1,uint32_t *src1, +uint32_t *dst2,uint32_t *src2) +{ +if (rseq_mo !=RSEQ_MO_RELAXED ) +return -1 ; +return rseq_load_u32_u32_relaxed (dst1, src1, dst2, src2); +} + +#endif +#endif /* RSEQ_H_ */
Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 27/30 selftests/rseq: Implement mm_numa_cid accessors in headers
In reply to Mathieu Desnoyers--- tools/testing/selftests/rseq/rseq-abi.h | 9 ++++++++ tools/testing/selftests/rseq/rseq-arm-bits.h | 8 +++---- tools/testing/selftests/rseq/rseq-arm.h | 12 +++++++++++ .../testing/selftests/rseq/rseq-arm64-bits.h | 8 +++---- tools/testing/selftests/rseq/rseq-arm64.h | 12 +++++++++++ .../selftests/rseq/rseq-bits-template.h | 10 +++++++++ tools/testing/selftests/rseq/rseq-mips-bits.h | 8 +++---- tools/testing/selftests/rseq/rseq-mips.h | 12 +++++++++++ tools/testing/selftests/rseq/rseq-ppc-bits.h | 8 +++---- tools/testing/selftests/rseq/rseq-ppc.h | 12 +++++++++++ .../testing/selftests/rseq/rseq-riscv-bits.h | 8 +++---- tools/testing/selftests/rseq/rseq-riscv.h | 12 +++++++++++ tools/testing/selftests/rseq/rseq-s390-bits.h | 8 +++---- tools/testing/selftests/rseq/rseq-s390.h | 12 +++++++++++ tools/testing/selftests/rseq/rseq-x86-bits.h | 16 +++++++------- tools/testing/selftests/rseq/rseq-x86.h | 21 +++++++++++++++---- tools/testing/selftests/rseq/rseq.h | 10 +++++++++ 17 files changed, 150 insertions(+), 36 deletions(-)
tools/testing/selftests/rseq/rseq-abi.h +9 -0
@@ -164,6 +164,15 @@ struct rseq_abi {*/ __u32 mm_cid; +/* +* Restartable sequences mm_numa_cid 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. Contains the current thread's +* NUMA-aware concurrency ID (allocated uniquely within a memory map). +*/ +__u32 mm_numa_cid; +/* * Flexible array member at end of structure, after last feature field. */
tools/testing/selftests/rseq/rseq-arm-bits.h +4 -4
@@ -8,7 +8,7 @@#include "rseq-bits-template.h" #if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __attribute__((always_inline))int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu)
@@ -288,10 +288,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t ex }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID )) static inline __attribute__((always_inline)) int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect,
@@ -500,6 +500,6 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-arm.h +12 -0
@@ -167,6 +167,18 @@ do { \#undef RSEQ_TEMPLATE_MO_RELEASE#undef RSEQ_TEMPLATE_MM_CID +/* Per-mm-numa-cid indexing. */ + +#define RSEQ_TEMPLATE_MM_NUMA_CID +#define RSEQ_TEMPLATE_MO_RELAXED +#include "rseq-arm-bits.h" +#undef RSEQ_TEMPLATE_MO_RELAXED + +#define RSEQ_TEMPLATE_MO_RELEASE +#include "rseq-arm-bits.h" +#undef RSEQ_TEMPLATE_MO_RELEASE +#undef RSEQ_TEMPLATE_MM_NUMA_CID +/* APIs which are not based on cpu ids. */ #define RSEQ_TEMPLATE_CPU_ID_NONE
tools/testing/selftests/rseq/rseq-arm64-bits.h +4 -4
@@ -9,7 +9,7 @@#include "rseq-bits-template.h" #if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __attribute__((always_inline))int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu)
@@ -246,10 +246,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t ex }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID )) static inline __attribute__((always_inline)) int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect,
@@ -387,6 +387,6 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-arm64.h +12 -0
@@ -224,6 +224,18 @@ do { \#undef RSEQ_TEMPLATE_MO_RELEASE#undef RSEQ_TEMPLATE_MM_CID +/* Per-mm-numa-cid indexing. */ + +#define RSEQ_TEMPLATE_MM_NUMA_CID +#define RSEQ_TEMPLATE_MO_RELAXED +#include "rseq-arm64-bits.h" +#undef RSEQ_TEMPLATE_MO_RELAXED + +#define RSEQ_TEMPLATE_MO_RELEASE +#include "rseq-arm64-bits.h" +#undef RSEQ_TEMPLATE_MO_RELEASE +#undef RSEQ_TEMPLATE_MM_NUMA_CID +/* APIs which are not based on cpu ids. */ #define RSEQ_TEMPLATE_CPU_ID_NONE
tools/testing/selftests/rseq/rseq-bits-template.h +10 -0
@@ -25,6 +25,16 @@# else # error "Never use <rseq-bits-template.h> directly; include <rseq.h> instead."# endif +#elif defined(RSEQ_TEMPLATE_MM_NUMA_CID) +# define RSEQ_TEMPLATE_CPU_ID_OFFSET RSEQ_MM_NUMA_CID_OFFSET +# define RSEQ_TEMPLATE_CPU_ID_FIELD mm_numa_cid +# ifdef RSEQ_TEMPLATE_MO_RELEASE +# define RSEQ_TEMPLATE_SUFFIX _release_mm_numa_cid +# elif defined (RSEQ_TEMPLATE_MO_RELAXED ) +# define RSEQ_TEMPLATE_SUFFIX _relaxed_mm_numa_cid +# else +# error "Never use <rseq-bits-template.h> directly; include <rseq.h> instead." +# endif #elif defined (RSEQ_TEMPLATE_CPU_ID_NONE)# ifdef RSEQ_TEMPLATE_MO_RELEASE # define RSEQ_TEMPLATE_SUFFIX _release
tools/testing/selftests/rseq/rseq-mips-bits.h +4 -4
@@ -8,7 +8,7 @@#include "rseq-bits-template.h" #if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __attribute__((always_inline))int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu)
@@ -261,10 +261,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t ex }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID )) static inline __attribute__((always_inline)) int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect,
@@ -457,6 +457,6 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-mips.h +12 -0
@@ -172,6 +172,18 @@ do { \#undef RSEQ_TEMPLATE_MO_RELEASE#undef RSEQ_TEMPLATE_MM_CID +/* Per-mm-numa-cid indexing. */ + +#define RSEQ_TEMPLATE_MM_NUMA_CID +#define RSEQ_TEMPLATE_MO_RELAXED +#include "rseq-mips-bits.h" +#undef RSEQ_TEMPLATE_MO_RELAXED + +#define RSEQ_TEMPLATE_MO_RELEASE +#include "rseq-mips-bits.h" +#undef RSEQ_TEMPLATE_MO_RELEASE +#undef RSEQ_TEMPLATE_MM_NUMA_CID +/* APIs which are not based on cpu ids. */ #define RSEQ_TEMPLATE_CPU_ID_NONE
tools/testing/selftests/rseq/rseq-ppc-bits.h +4 -4
@@ -9,7 +9,7 @@#include "rseq-bits-template.h" #if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __attribute__((always_inline))int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu)
@@ -283,10 +283,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t ex }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID )) static inline __attribute__((always_inline)) int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect,
@@ -449,6 +449,6 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-ppc.h +12 -0
@@ -229,6 +229,18 @@ do { \#undef RSEQ_TEMPLATE_MO_RELEASE#undef RSEQ_TEMPLATE_MM_CID +/* Per-mm-numa-cid indexing. */ + +#define RSEQ_TEMPLATE_MM_NUMA_CID +#define RSEQ_TEMPLATE_MO_RELAXED +#include "rseq-ppc-bits.h" +#undef RSEQ_TEMPLATE_MO_RELAXED + +#define RSEQ_TEMPLATE_MO_RELEASE +#include "rseq-ppc-bits.h" +#undef RSEQ_TEMPLATE_MO_RELEASE +#undef RSEQ_TEMPLATE_MM_NUMA_CID +/* APIs which are not based on cpu ids. */ #define RSEQ_TEMPLATE_CPU_ID_NONE
tools/testing/selftests/rseq/rseq-riscv-bits.h +4 -4
@@ -3,7 +3,7 @@#include "rseq-bits-template.h" #if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __always_inline int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_storev)(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
@@ -272,10 +272,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_offset_deref_addv)(intptr_t *ptr, off_t off, i }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID )) static inline __always_inline int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect,
@@ -405,6 +405,6 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-riscv.h +12 -0
@@ -189,6 +189,18 @@ do { \#undef RSEQ_TEMPLATE_MO_RELEASE#undef RSEQ_TEMPLATE_MM_CID +/* Per-mm-cid indexing. */ + +#define RSEQ_TEMPLATE_MM_NUMA_CID +#define RSEQ_TEMPLATE_MO_RELAXED +#include "rseq-riscv-bits.h" +#undef RSEQ_TEMPLATE_MO_RELAXED + +#define RSEQ_TEMPLATE_MO_RELEASE +#include "rseq-riscv-bits.h" +#undef RSEQ_TEMPLATE_MO_RELEASE +#undef RSEQ_TEMPLATE_MM_NUMA_CID +/* APIs which are not based on cpu ids. */ #define RSEQ_TEMPLATE_CPU_ID_NONE
tools/testing/selftests/rseq/rseq-s390-bits.h +4 -4
@@ -3,7 +3,7 @@#include "rseq-bits-template.h" #if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __attribute__((always_inline))int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu)
@@ -274,10 +274,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t ex }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))/* s390 is TSO. */ static inline __attribute__((always_inline))
@@ -469,6 +469,6 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #include "rseq-bits-reset.h"
tools/testing/selftests/rseq/rseq-s390.h +12 -0
@@ -154,6 +154,18 @@ do { \#undef RSEQ_TEMPLATE_MO_RELEASE#undef RSEQ_TEMPLATE_MM_CID +/* Per-mm-cid indexing. */ + +#define RSEQ_TEMPLATE_MM_NUMA_CID +#define RSEQ_TEMPLATE_MO_RELAXED +#include "rseq-s390-bits.h" +#undef RSEQ_TEMPLATE_MO_RELAXED + +#define RSEQ_TEMPLATE_MO_RELEASE +#include "rseq-s390-bits.h" +#undef RSEQ_TEMPLATE_MO_RELEASE +#undef RSEQ_TEMPLATE_MM_NUMA_CID +/* APIs which are not based on cpu ids. */ #define RSEQ_TEMPLATE_CPU_ID_NONE
tools/testing/selftests/rseq/rseq-x86-bits.h +8 -8
@@ -10,7 +10,7 @@#ifdef __x86_64__#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __attribute__((always_inline))int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu)
@@ -328,10 +328,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t ex }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID )) static inline __attribute__((always_inline)) int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect,
@@ -517,12 +517,12 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #elif defined(__i386__)#if defined(RSEQ_TEMPLATE_MO_RELAXED ) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID ))static inline __attribute__((always_inline))int RSEQ_TEMPLATE_IDENTIFIER (rseq_cmpeqv_storev )(intptr_t *v,intptr_t expect,intptr_t newv,int cpu)
@@ -784,10 +784,10 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_cmpeqv_storev)(intptr_t *v, intptr_t ex }#endif /* #if defined(RSEQ_TEMPLATE_MO_RELAXED) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #if (defined(RSEQ_TEMPLATE_MO_RELAXED ) || defined(RSEQ_TEMPLATE_MO_RELEASE )) && \ - (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID )) + (defined(RSEQ_TEMPLATE_CPU_ID ) || defined(RSEQ_TEMPLATE_MM_CID ) || defined(RSEQ_TEMPLATE_MM_NUMA_CID )) static inline __attribute__((always_inline)) int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trystorev_storev)(intptr_t *v, intptr_t expect,
@@ -986,7 +986,7 @@ int RSEQ_TEMPLATE_IDENTIFIER(rseq_cmpeqv_trymemcpy_storev)(intptr_t *v, intptr_t }#endif /* #if (defined(RSEQ_TEMPLATE_MO_RELAXED) || defined(RSEQ_TEMPLATE_MO_RELEASE)) && -(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID)) */ +(defined(RSEQ_TEMPLATE_CPU_ID) || defined(RSEQ_TEMPLATE_MM_CID) || defined(RSEQ_TEMPLATE_MM_NUMA_CID)) */ #endif
tools/testing/selftests/rseq/rseq-x86.h +17 -4
@@ -26,10 +26,11 @@* address through a "r" input operand. */ -/* Offset of cpu_id, rseq_cs, and mm_cid fields in struct rseq. */ -#define RSEQ_CPU_ID_OFFSET 4 -#define RSEQ_CS_OFFSET 8 -#define RSEQ_MM_CID_OFFSET 24 +/* Offset of cpu_id, rseq_cs, mm_cid, and mm_numa_cid fields in struct rseq. */ +#define RSEQ_CPU_ID_OFFSET 4 +#define RSEQ_CS_OFFSET 8 +#define RSEQ_MM_CID_OFFSET 24 +#define RSEQ_MM_NUMA_CID_OFFSET 28#ifdef __x86_64__
@@ -225,6 +226,18 @@ do { \#undef RSEQ_TEMPLATE_MO_RELEASE#undef RSEQ_TEMPLATE_MM_CID +/* Per-mm-numa-cid indexing. */ + +#define RSEQ_TEMPLATE_MM_NUMA_CID +#define RSEQ_TEMPLATE_MO_RELAXED +#include "rseq-x86-bits.h" +#undef RSEQ_TEMPLATE_MO_RELAXED + +#define RSEQ_TEMPLATE_MO_RELEASE +#include "rseq-x86-bits.h" +#undef RSEQ_TEMPLATE_MO_RELEASE +#undef RSEQ_TEMPLATE_MM_NUMA_CID +/* APIs which are not based on cpu ids. */ #define RSEQ_TEMPLATE_CPU_ID_NONE
tools/testing/selftests/rseq/rseq.h +10 -0
@@ -215,6 +215,16 @@ static inline uint32_t rseq_current_mm_cid(void)return RSEQ_ACCESS_ONCE (rseq_get_abi ()->mm_cid); } +static inline bool rseq_mm_numa_cid_available (void ) +{ + return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, mm_numa_cid); +} + +static inline uint32_t rseq_current_mm_numa_cid (void ) +{ +return RSEQ_ACCESS_ONCE (rseq_get_abi ()->mm_numa_cid); +} +static inline void rseq_clear_rseq_cs (void ) {RSEQ_WRITE_ONCE (rseq_get_abi ()->rseq_cs.arch.ptr,0 );
Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 28/30 selftests/rseq: Implement numa node id vs mm_numa_cid invariant test
In reply to Mathieu DesnoyersOn all architectures except Power, the NUMA topology is never reconfigured after a CPU has been associated with a NUMA node in the system lifetime.
Even on Power, we can assume that NUMA topology reconfiguration happens rarely, and therefore we do not expect it to happen while the NUMA test is running.
This test validates that the mapping between a mm_numa_cid and a numa node id remains valid for the process lifetime. In other words, it validates that if any thread within the process running on behalf of a mm_numa_cid N observes a NUMA node id M, all threads within this process will always observe the same NUMA node id value when running on behalf of that same mm_numa_cid.
This characteristic is important for NUMA locality.
This test is skipped on architectures that do not implement rseq_load_u32_u32.
--- tools/testing/selftests/rseq/.gitignore | 1 + tools/testing/selftests/rseq/Makefile | 2 +- .../testing/selftests/rseq/basic_numa_test.c | 117 ++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/rseq/basic_numa_test.c
tools/testing/selftests/rseq/.gitignore +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +basic_numa_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test basic_test
tools/testing/selftests/rseq/Makefile +1 -1
@@ -12,7 +12,7 @@ LDLIBS += -lpthread -ldl # still track changes to header files and depend on shared object. OVERRIDE_TARGETS = 1 -TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ +TEST_GEN_PROGS = basic_test basic_numa_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ param_test_benchmark param_test_compare_twice param_test_mm_cid \ param_test_mm_cid_benchmark param_test_mm_cid_compare_twice
tools/testing/selftests/rseq/basic_numa_test.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 29/30 selftests/rseq: Implement mm_numa_cid tests
In reply to Mathieu DesnoyersImplement rseq selftests for the mm_numa_cid struct rseq field.
--- tools/testing/selftests/rseq/.gitignore | 4 ++++ tools/testing/selftests/rseq/Makefile | 16 ++++++++++++- .../selftests/rseq/basic_percpu_ops_test.c | 12 ++++++++++ tools/testing/selftests/rseq/param_test.c | 24 +++++++++++++++++++ tools/testing/selftests/rseq/rseq.h | 19 +++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-)
tools/testing/selftests/rseq/.gitignore +4 -0
@@ -2,6 +2,7 @@ basic_numa_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test +basic_percpu_ops_mm_numa_cid_test basic_test basic_rseq_op_test param_test
@@ -10,3 +11,6 @@ param_test_compare_twice param_test_mm_cid param_test_mm_cid_benchmark param_test_mm_cid_compare_twice +param_test_mm_numa_cid +param_test_mm_numa_cid_benchmark +param_test_mm_numa_cid_compare_twice
tools/testing/selftests/rseq/Makefile +15 -1
@@ -14,7 +14,9 @@ OVERRIDE_TARGETS = 1 TEST_GEN_PROGS = basic_test basic_numa_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ param_test_benchmark param_test_compare_twice param_test_mm_cid \ - param_test_mm_cid_benchmark param_test_mm_cid_compare_twice + param_test_mm_cid_benchmark param_test_mm_cid_compare_twice \ + param_test_mm_numa_cid param_test_mm_numa_cid_benchmark \ + param_test_mm_numa_cid_compare_twice TEST_GEN_PROGS_EXTENDED = librseq.so
@@ -52,3 +54,15 @@ $(OUTPUT)/param_test_mm_cid_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ $(OUTPUT)/param_test_mm_cid_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ rseq.h rseq-*.h $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_numa_cid: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_NUMA_CID $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_numa_cid_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_NUMA_CID -DBENCHMARK $< $(LDLIBS) -lrseq -o $@ + +$(OUTPUT)/param_test_mm_numa_cid_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ + rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_NUMA_CID -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
tools/testing/selftests/rseq/basic_percpu_ops_test.c +12 -0
@@ -24,6 +24,18 @@ bool rseq_validate_cpu_id(void) {return rseq_mm_cid_available (); } +#elif defined(BUILDOPT_RSEQ_PERCPU_MM_NUMA_CID ) +# define RSEQ_PERCPU RSEQ_PERCPU_MM_NUMA_CID +static +int get_current_cpu_id (void ) +{ +return rseq_current_mm_numa_cid (); +} +static +bool rseq_validate_cpu_id (void ) +{ +return rseq_mm_numa_cid_available (); +}#else # define RSEQ_PERCPU RSEQ_PERCPU_CPU_ID static
tools/testing/selftests/rseq/param_test.c +24 -0
@@ -300,6 +300,30 @@ int rseq_membarrier_expedited(int cpu) 0, 0); }# endif /* TEST_MEMBARRIER */ +#elif defined(BUILDOPT_RSEQ_PERCPU_MM_NUMA_CID) +# define RSEQ_PERCPU RSEQ_PERCPU_MM_NUMA_CID +static +int get_current_cpu_id (void ) +{ +return rseq_current_mm_numa_cid (); +} +static +bool rseq_validate_cpu_id (void ) +{ +return rseq_mm_numa_cid_available (); +} +# ifdef TEST_MEMBARRIER +/* +* Membarrier does not currently support targeting a mm_numa_cid, so +* issue the barrier on all cpus. +*/ +static +int rseq_membarrier_expedited (int cpu) +{ +return sys_membarrier (MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ , +0 ,0 ); +} +# endif /* TEST_MEMBARRIER */ #else # define RSEQ_PERCPU RSEQ_PERCPU_CPU_ID static
tools/testing/selftests/rseq/rseq.h +19 -0
@@ -86,6 +86,7 @@ enum rseq_mo {enum rseq_percpu_mode {RSEQ_PERCPU_CPU_ID =0 ,RSEQ_PERCPU_MM_CID =1 , +RSEQ_PERCPU_MM_NUMA_CID =2 , };static inline struct rseq_abi *rseq_get_abi (void )
@@ -258,6 +259,8 @@ int rseq_cmpeqv_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,return rseq_cmpeqv_storev_relaxed_cpu_id (v, expect, newv, cpu);case RSEQ_PERCPU_MM_CID :return rseq_cmpeqv_storev_relaxed_mm_cid (v, expect, newv, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_cmpeqv_storev_relaxed_mm_numa_cid (v, expect, newv, cpu); }return -1 ; }
@@ -278,6 +281,8 @@ int rseq_cmpnev_storeoffp_load(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpreturn rseq_cmpnev_storeoffp_load_relaxed_cpu_id (v, expectnot, voffp, load, cpu);case RSEQ_PERCPU_MM_CID :return rseq_cmpnev_storeoffp_load_relaxed_mm_cid (v, expectnot, voffp, load, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_cmpnev_storeoffp_load_relaxed_mm_numa_cid (v, expectnot, voffp, load, cpu); }return -1 ; }
@@ -293,6 +298,8 @@ int rseq_addv(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,return rseq_addv_relaxed_cpu_id (v, count, cpu);case RSEQ_PERCPU_MM_CID :return rseq_addv_relaxed_mm_cid (v, count, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_addv_relaxed_mm_numa_cid (v, count, cpu); }return -1 ; }
@@ -313,6 +320,8 @@ int rseq_offset_deref_addv(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_moreturn rseq_offset_deref_addv_relaxed_cpu_id (ptr, off, inc, cpu);case RSEQ_PERCPU_MM_CID :return rseq_offset_deref_addv_relaxed_mm_cid (ptr, off, inc, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_offset_deref_addv_relaxed_mm_numa_cid (ptr, off, inc, cpu); }return -1 ; }
@@ -331,6 +340,8 @@ int rseq_cmpeqv_trystorev_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode perreturn rseq_cmpeqv_trystorev_storev_relaxed_cpu_id (v, expect, v2, newv2, newv, cpu);case RSEQ_PERCPU_MM_CID :return rseq_cmpeqv_trystorev_storev_relaxed_mm_cid (v, expect, v2, newv2, newv, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_cmpeqv_trystorev_storev_relaxed_mm_numa_cid (v, expect, v2, newv2, newv, cpu); }return -1 ;case RSEQ_MO_RELEASE :
@@ -339,6 +350,8 @@ int rseq_cmpeqv_trystorev_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode perreturn rseq_cmpeqv_trystorev_storev_release_cpu_id (v, expect, v2, newv2, newv, cpu);case RSEQ_PERCPU_MM_CID :return rseq_cmpeqv_trystorev_storev_release_mm_cid (v, expect, v2, newv2, newv, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_cmpeqv_trystorev_storev_release_mm_numa_cid (v, expect, v2, newv2, newv, cpu); }return -1 ;default :
@@ -359,6 +372,8 @@ int rseq_cmpeqv_cmpeqv_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpureturn rseq_cmpeqv_cmpeqv_storev_relaxed_cpu_id (v, expect, v2, expect2, newv, cpu);case RSEQ_PERCPU_MM_CID :return rseq_cmpeqv_cmpeqv_storev_relaxed_mm_cid (v, expect, v2, expect2, newv, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_cmpeqv_cmpeqv_storev_relaxed_mm_numa_cid (v, expect, v2, expect2, newv, cpu); }return -1 ; }
@@ -376,6 +391,8 @@ int rseq_cmpeqv_trymemcpy_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode perreturn rseq_cmpeqv_trymemcpy_storev_relaxed_cpu_id (v, expect, dst, src, len, newv, cpu);case RSEQ_PERCPU_MM_CID :return rseq_cmpeqv_trymemcpy_storev_relaxed_mm_cid (v, expect, dst, src, len, newv, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_cmpeqv_trymemcpy_storev_relaxed_mm_numa_cid (v, expect, dst, src, len, newv, cpu); }return -1 ;case RSEQ_MO_RELEASE :
@@ -384,6 +401,8 @@ int rseq_cmpeqv_trymemcpy_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode perreturn rseq_cmpeqv_trymemcpy_storev_release_cpu_id (v, expect, dst, src, len, newv, cpu);case RSEQ_PERCPU_MM_CID :return rseq_cmpeqv_trymemcpy_storev_release_mm_cid (v, expect, dst, src, len, newv, cpu); +case RSEQ_PERCPU_MM_NUMA_CID : +return rseq_cmpeqv_trymemcpy_storev_release_mm_numa_cid (v, expect, dst, src, len, newv, cpu); }return -1 ;default :
Signature · 1 line
2.25.1
Mathieu Desnoyers
maintainerPATCH 30/30 tracing/rseq: Add mm_numa_cid field to rseq_update
In reply to Mathieu DesnoyersAdd the mm_numa_cid field to the rseq_update event, allowing tracers to follow which mm_numa_cid is observed by user-space, and whether negative mm_numa_cid values are visible in case of internal scheduler implementation issues.
--- include/trace/events/rseq.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/trace/events/rseq.h +4 -2
@@ -18,16 +18,18 @@ TRACE_EVENT(rseq_update, __field(s32, cpu_id) __field(s32, node_id) __field(s32, mm_cid) +__field (s32, mm_numa_cid) ),TP_fast_assign ( __entry->cpu_id = raw_smp_processor_id(); __entry->node_id =cpu_to_node (__entry->cpu_id); __entry->mm_cid =task_mm_cid (t); + __entry->mm_numa_cid =task_mm_numa_cid (t); ), -TP_printk ("cpu_id=%d node_id=%d mm_cid=%d" , __entry->cpu_id, - __entry->node_id, __entry->mm_cid) +TP_printk ("cpu_id=%d node_id=%d mm_cid=%d mm_numa_cid=%d" , __entry->cpu_id, + __entry->node_id, __entry->mm_cid, __entry->mm_numa_cid) ); TRACE_EVENT(rseq_ip_fixup,
Signature · 1 line
2.25.1
Hi Mathieu, all,
Quoted 13 lines · Mathieu Desnoyers
Extend the rseq ABI to expose NUMA node ID,
mm_cid, andmm_numa_cidfields.The NUMA node ID field allows implementing a faster getcpu(2) in libc.
The per-memory-map concurrency id (
mm_cid) [1] allows ideal scaling (down or up) of user-space per-cpu data structures. The concurrency ids allocated within a memory map are tracked by the scheduler, which takes into account the number of concurrently running threads, thus implicitly considering the number of threads, the cpu affinity, the cpusets applying to those threads, and the number of logical cores on the system.
Quoted 9 lines
The NUMA-aware concurrency id (
mm_numa_cid) is similar to themm_cid, except that it keeps track of the NUMA node ids with which each cid has been associated. On NUMA systems, when a NUMA-aware concurrency ID is observed by user-space to be associated with a NUMA node, it is guaranteed to never change NUMA node unless a kernel-level NUMA configuration change happens. This is useful for NUMA-aware per-cpu data structures running in environments where a process or a set of processes belonging to cpuset are pinned to a set of cores which belong to a subset of the system's NUMA nodes.
[...]
Just out of curiosity: is anyone aware of any libraries that have started using CIDs? It looks like the cost of CID assignment is always paid (even though it should be small), I'm trying to understand if after 1.5 years there are common libraries that have started using it and what their exact usecase is.
I'm aware that TCMalloc was the inspiration for vCPUs [1], then renamed to CIDs, but am wondering if other users are out there.
Thanks,
-- Marco
Mathieu Desnoyers
maintainerQuoted 25 lines · Marco Elver
Hi Mathieu, all,
Quoted 13 lines · Mathieu Desnoyers
Extend the rseq ABI to expose NUMA node ID,
mm_cid, andmm_numa_cidfields.The NUMA node ID field allows implementing a faster getcpu(2) in libc.
The per-memory-map concurrency id (
mm_cid) [1] allows ideal scaling (down or up) of user-space per-cpu data structures. The concurrency ids allocated within a memory map are tracked by the scheduler, which takes into account the number of concurrently running threads, thus implicitly considering the number of threads, the cpu affinity, the cpusets applying to those threads, and the number of logical cores on the system.Quoted 9 lines
The NUMA-aware concurrency id (
mm_numa_cid) is similar to themm_cid, except that it keeps track of the NUMA node ids with which each cid has been associated. On NUMA systems, when a NUMA-aware concurrency ID is observed by user-space to be associated with a NUMA node, it is guaranteed to never change NUMA node unless a kernel-level NUMA configuration change happens. This is useful for NUMA-aware per-cpu data structures running in environments where a process or a set of processes belonging to cpuset are pinned to a set of cores which belong to a subset of the system's NUMA nodes.
Quoted 7 lines
[...]
Just out of curiosity: is anyone aware of any libraries that have started using CIDs? It looks like the cost of CID assignment is always paid (even though it should be small), I'm trying to understand if after 1.5 years there are common libraries that have started using it and what their exact usecase is.
Hi Marco,
AFAIK the only project using the mm_cid concept I know of today is tcmalloc. It's very useful to scale data structures such as memory allocator arenas to the number of concurrently running threads within a process without having to rely on heuristics on the user-space side.
I have plans to migrate LTTng-UST to per-ipc-namespace NUMA-aware mm_cid as well (after I get around to submit this extension into the Linux kernel) for user-space ring buffers over shared memory, but my current focus has been on pushing support for extensible RSEQ into GNU libc for the past year or so.
We are getting there though:
https://sourceware.org/pipermail/libc-alpha/2024-February/154390.html
Once we have this key piece in place within GNU libc, it will become easier to extend rseq further because the libc will adapt to the extended feature set.
Note that the overhead of the mm_cid assignment within the scheduler should be negligible after
commit 223baf9d17f2 ("sched: Fix performance regression introduced by mm_cid").
Another thing we've actively been working on is to get the "librseq" project [1] in shape so a copy the librseq headers can be integrated into the GNU libc project as internal header files. So basically librseq will become a GNU libc upstream. This will facilitate implementation of rseq critical section within GNU libc. One of the possible use-cases will be to move the GNU libc malloc implementation to per-mm_cid arenas.
Quoted 3 lines
I'm aware that TCMalloc was the inspiration for vCPUs [1], then renamed to CIDs, but am wondering if other users are out there.
I'd be curious to learn about those as well.
I suspect that the lack of official release of librseq critical section helper headers may contribute to the fact that few applications use advanced rseq features at this point.
Thanks,
Mathieu
[1] https://git.kernel.org/pub/scm/libs/librseq/librseq.git/
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
On Wed, 28 Feb 2024 at 21:01, Mathieu Desnoyers
<[email protected]> wrote:
[...]
Quoted 12 lines
AFAIK the only project using the
mm_cidconcept I know of today is tcmalloc. It's very useful to scale data structures such as memory allocator arenas to the number of concurrently running threads within a process without having to rely on heuristics on the user-space side.I have plans to migrate LTTng-UST to per-ipc-namespace NUMA-aware
mm_cidas well (after I get around to submit this extension into the Linux kernel) for user-space ring buffers over shared memory, but my current focus has been on pushing support for extensible RSEQ into GNU libc for the past year or so.
Quoted 3 lines
We are getting there though:
https://sourceware.org/pipermail/libc-alpha/2024-February/154390.html
Glad to see this!
Quoted 8 lines
Once we have this key piece in place within GNU libc, it will become easier to extend rseq further because the libc will adapt to the extended feature set.
Note that the overhead of the
mm_cidassignment within the scheduler should be negligible after
commit223baf9d17f2("sched: Fix performance regression introduced bymm_cid").
Quoted 7 lines
Another thing we've actively been working on is to get the "librseq" project [1] in shape so a copy the librseq headers can be integrated into the GNU libc project as internal header files. So basically librseq will become a GNU libc upstream. This will facilitate implementation of rseq critical section within GNU libc. One of the possible use-cases will be to move the GNU libc malloc implementation to per-mm_cid arenas.
I suppose if GNU libc malloc starts using it then usage would become ubiquitous in no time.
Quoted 8 lines
Quoted 2 lines
I'm aware that TCMalloc was the inspiration for vCPUs [1], then renamed to CIDs, but am wondering if other users are out there.
I'd be curious to learn about those as well.
I suspect that the lack of official release of librseq critical section helper headers may contribute to the fact that few applications use advanced rseq features at this point.
I guess you've answered my question, and I conclude "no known open source usage yet". A simple search on Github or the likes also didn't yield anything. I will go and check again in a year or so. ;-)
Thanks,
-- Marco