diff options
| author | Cyril Bur <cyrilbur@gmail.com> | 2016-09-23 02:18:20 -0400 |
|---|---|---|
| committer | Michael Ellerman <mpe@ellerman.id.au> | 2016-10-04 05:33:12 -0400 |
| commit | f10d4424b20c101f3b4dd599819083e1e4b5a3fa (patch) | |
| tree | 1ba4364831f7a9e797d34c797d1cde69ef976e7d /tools/testing | |
| parent | ef186331b427fdf2bf791d184921df6c6c6e9a63 (diff) | |
selftests/powerpc: Add checks for transactional GPRs in signal contexts
If a thread receives a signal while transactional the kernel creates a
second context to show the transactional state of the process. This
test loads some known values and waits for a signal and confirms that
the expected values are in the signal context.
Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/powerpc/tm/Makefile | 7 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c | 90 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/tm/tm-signal.S | 114 |
3 files changed, 210 insertions, 1 deletions
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile index 9d301d785d9e..e1204f6f9175 100644 --- a/tools/testing/selftests/powerpc/tm/Makefile +++ b/tools/testing/selftests/powerpc/tm/Makefile | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr | ||
| 2 | |||
| 1 | TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \ | 3 | TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \ |
| 2 | tm-vmxcopy tm-fork tm-tar tm-tmspr tm-exec tm-execed | 4 | tm-vmxcopy tm-fork tm-tar tm-tmspr $(SIGNAL_CONTEXT_CHK_TESTS) |
| 3 | 5 | ||
| 4 | all: $(TEST_PROGS) | 6 | all: $(TEST_PROGS) |
| 5 | 7 | ||
| @@ -11,6 +13,9 @@ tm-syscall: tm-syscall-asm.S | |||
| 11 | tm-syscall: CFLAGS += -I../../../../../usr/include | 13 | tm-syscall: CFLAGS += -I../../../../../usr/include |
| 12 | tm-tmspr: CFLAGS += -pthread | 14 | tm-tmspr: CFLAGS += -pthread |
| 13 | 15 | ||
| 16 | $(SIGNAL_CONTEXT_CHK_TESTS): tm-signal.S | ||
| 17 | $(SIGNAL_CONTEXT_CHK_TESTS): CFLAGS += -mhtm -m64 -mvsx | ||
| 18 | |||
| 14 | include ../../lib.mk | 19 | include ../../lib.mk |
| 15 | 20 | ||
| 16 | clean: | 21 | clean: |
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c b/tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c new file mode 100644 index 000000000000..df91330a08ef --- /dev/null +++ b/tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2016, Cyril Bur, IBM Corp. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU General Public License | ||
| 6 | * as published by the Free Software Foundation; either version | ||
| 7 | * 2 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * | ||
| 10 | * Test the kernel's signal frame code. | ||
| 11 | * | ||
| 12 | * The kernel sets up two sets of ucontexts if the signal was to be | ||
| 13 | * delivered while the thread was in a transaction. | ||
| 14 | * Expected behaviour is that the checkpointed state is in the user | ||
| 15 | * context passed to the signal handler. The speculated state can be | ||
| 16 | * accessed with the uc_link pointer. | ||
| 17 | * | ||
| 18 | * The rationale for this is that if TM unaware code (which linked | ||
| 19 | * against TM libs) installs a signal handler it will not know of the | ||
| 20 | * speculative nature of the 'live' registers and may infer the wrong | ||
| 21 | * thing. | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <stdlib.h> | ||
| 25 | #include <stdio.h> | ||
| 26 | #include <signal.h> | ||
| 27 | #include <unistd.h> | ||
| 28 | |||
| 29 | #include <altivec.h> | ||
| 30 | |||
| 31 | #include "utils.h" | ||
| 32 | #include "tm.h" | ||
| 33 | |||
| 34 | #define MAX_ATTEMPT 500000 | ||
| 35 | |||
| 36 | #define NV_GPR_REGS 18 | ||
| 37 | |||
| 38 | long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss); | ||
| 39 | |||
| 40 | static sig_atomic_t fail; | ||
| 41 | |||
| 42 | static long gps[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, | ||
| 43 | -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18}; | ||
| 44 | |||
| 45 | static void signal_usr1(int signum, siginfo_t *info, void *uc) | ||
| 46 | { | ||
| 47 | int i; | ||
| 48 | ucontext_t *ucp = uc; | ||
| 49 | ucontext_t *tm_ucp = ucp->uc_link; | ||
| 50 | |||
| 51 | for (i = 0; i < NV_GPR_REGS && !fail; i++) { | ||
| 52 | fail = (ucp->uc_mcontext.gp_regs[i + 14] != gps[i]); | ||
| 53 | fail |= (tm_ucp->uc_mcontext.gp_regs[i + 14] != gps[i + NV_GPR_REGS]); | ||
| 54 | if (fail) | ||
| 55 | printf("Failed on %d GPR %lu or %lu\n", i, | ||
| 56 | ucp->uc_mcontext.gp_regs[i + 14], tm_ucp->uc_mcontext.gp_regs[i + 14]); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | static int tm_signal_context_chk_gpr() | ||
| 61 | { | ||
| 62 | struct sigaction act; | ||
| 63 | int i; | ||
| 64 | long rc; | ||
| 65 | pid_t pid = getpid(); | ||
| 66 | |||
| 67 | SKIP_IF(!have_htm()); | ||
| 68 | |||
| 69 | act.sa_sigaction = signal_usr1; | ||
| 70 | sigemptyset(&act.sa_mask); | ||
| 71 | act.sa_flags = SA_SIGINFO; | ||
| 72 | if (sigaction(SIGUSR1, &act, NULL) < 0) { | ||
| 73 | perror("sigaction sigusr1"); | ||
| 74 | exit(1); | ||
| 75 | } | ||
| 76 | |||
| 77 | i = 0; | ||
| 78 | while (i < MAX_ATTEMPT && !fail) { | ||
| 79 | rc = tm_signal_self_context_load(pid, gps, NULL, NULL, NULL); | ||
| 80 | FAIL_IF(rc != pid); | ||
| 81 | i++; | ||
| 82 | } | ||
| 83 | |||
| 84 | return fail; | ||
| 85 | } | ||
| 86 | |||
| 87 | int main(void) | ||
| 88 | { | ||
| 89 | return test_harness(tm_signal_context_chk_gpr, "tm_signal_context_chk_gpr"); | ||
| 90 | } | ||
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal.S b/tools/testing/selftests/powerpc/tm/tm-signal.S new file mode 100644 index 000000000000..4e13e8b3a96f --- /dev/null +++ b/tools/testing/selftests/powerpc/tm/tm-signal.S | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2015, Cyril Bur, IBM Corp. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU General Public License | ||
| 6 | * as published by the Free Software Foundation; either version | ||
| 7 | * 2 of the License, or (at your option) any later version. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include "../basic_asm.h" | ||
| 11 | #include "../gpr_asm.h" | ||
| 12 | #include "../fpu_asm.h" | ||
| 13 | #include "../vmx_asm.h" | ||
| 14 | #include "../vsx_asm.h" | ||
| 15 | |||
| 16 | /* | ||
| 17 | * Large caveat here being that the caller cannot expect the | ||
| 18 | * signal to always be sent! The hardware can (AND WILL!) abort | ||
| 19 | * the transaction between the tbegin and the tsuspend (however | ||
| 20 | * unlikely it seems or infrequently it actually happens). | ||
| 21 | * You have been warned. | ||
| 22 | */ | ||
| 23 | /* long tm_signal_self(pid_t pid, long *gprs, double *fps, vector *vms, vector *vss); */ | ||
| 24 | FUNC_START(tm_signal_self_context_load) | ||
| 25 | PUSH_BASIC_STACK(512) | ||
| 26 | /* | ||
| 27 | * Don't strictly need to save and restore as it depends on if | ||
| 28 | * we're going to use them, however this reduces messy logic | ||
| 29 | */ | ||
| 30 | PUSH_VMX(STACK_FRAME_LOCAL(5,0),r8) | ||
| 31 | PUSH_FPU(512) | ||
| 32 | PUSH_NVREGS_BELOW_FPU(512) | ||
| 33 | std r3, STACK_FRAME_PARAM(0)(sp) /* pid */ | ||
| 34 | std r4, STACK_FRAME_PARAM(1)(sp) /* gps */ | ||
| 35 | std r5, STACK_FRAME_PARAM(2)(sp) /* fps */ | ||
| 36 | std r6, STACK_FRAME_PARAM(3)(sp) /* vms */ | ||
| 37 | std r7, STACK_FRAME_PARAM(4)(sp) /* vss */ | ||
| 38 | |||
| 39 | ld r3, STACK_FRAME_PARAM(1)(sp) | ||
| 40 | cmpdi r3, 0 | ||
| 41 | beq skip_gpr_lc | ||
| 42 | bl load_gpr | ||
| 43 | skip_gpr_lc: | ||
| 44 | ld r3, STACK_FRAME_PARAM(2)(sp) | ||
| 45 | cmpdi r3, 0 | ||
| 46 | beq skip_fpu_lc | ||
| 47 | bl load_fpu | ||
| 48 | skip_fpu_lc: | ||
| 49 | ld r3, STACK_FRAME_PARAM(3)(sp) | ||
| 50 | cmpdi r3, 0 | ||
| 51 | beq skip_vmx_lc | ||
| 52 | bl load_vmx | ||
| 53 | skip_vmx_lc: | ||
| 54 | ld r3, STACK_FRAME_PARAM(4)(sp) | ||
| 55 | cmpdi r3, 0 | ||
| 56 | beq skip_vsx_lc | ||
| 57 | bl load_vsx | ||
| 58 | skip_vsx_lc: | ||
| 59 | /* | ||
| 60 | * Set r3 (return value) before tbegin. Use the pid as a known | ||
| 61 | * 'all good' return value, zero is used to indicate a non-doomed | ||
| 62 | * transaction. | ||
| 63 | */ | ||
| 64 | ld r3, STACK_FRAME_PARAM(0)(sp) | ||
| 65 | tbegin. | ||
| 66 | beq 1f | ||
| 67 | tsuspend. /* Can't enter a syscall transactionally */ | ||
| 68 | ld r3, STACK_FRAME_PARAM(1)(sp) | ||
| 69 | cmpdi r3, 0 | ||
| 70 | beq skip_gpr_lt | ||
| 71 | /* Get the second half of the array */ | ||
