selftests/powerpc: Add missing clobbered register to to ptrace TM tests
PATCH v2 1/2 selftests/powerpc: Add missing clobbered register to to ptrace TM tests
ISA v3.1 removes TM but includes a synthetic implementation for backwards compatibility. With this implementation, the tests ptrace-tm-spd-gpr and ptrace-tm-gpr should never be able to make any forward progress and eventually should be killed by the timeout. Instead on a P10 running in P9 mode, ptrace_tm_gpr fails like so:
test: ptrace_tm_gpr
tags: git_version:unknown
Starting the child
...
...
GPR[27]: 1 Expected: 2
GPR[28]: 1 Expected: 2
GPR[29]: 1 Expected: 2
GPR[30]: 1 Expected: 2
GPR[31]: 1 Expected: 2
[FAIL] Test FAILED on line 98
failure: ptrace_tm_gpr
selftests: ptrace-tm-gpr [FAIL]
The problem is in the inline assembly of the child. r0 is loaded with a value in the child's transaction abort handler but this register is not included in the clobbers list. This means it is possible that this statement:
cptr[1] = 0;
which is meant to signal the parent to wait may actually use the value placed into r0 by the inline assembly incorrectly signal the parent to continue.
By inspection the same problem is present in ptrace-tm-spd-gpr.
Adding r0 to the clobbbers list makes the test fail correctly via a timeout on a P10 running in P8/P9 compatibility mode.
--- tools/testing/selftests/powerpc/ptrace/ptrace-tm-gpr.c | 2 +- tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-gpr.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/powerpc/ptrace/ptrace-tm-gpr.c +1 -1
@@ -57,7 +57,7 @@ void tm_gpr(void) : [gpr_1]"i"(GPR_1), [gpr_2]"i"(GPR_2), [sprn_texasr] "i" (SPRN_TEXASR), [flt_1] "b" (&a), [flt_2] "b" (&b), [cptr1] "b" (&cptr[1]) - : "memory", "r7", "r8", "r9", "r10", + : "memory", "r0", "r7", "r8", "r9", "r10"," r11", " r12", " r13", " r14", " r15", " r16", " r17", " r18", " r19", " r20", " r21", " r22", "r23", "r24", "r25", "r26", "r27", "r28",
tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-gpr.c +1 -1
@@ -65,7 +65,7 @@ void tm_spd_gpr(void) : [gpr_1]"i"(GPR_1), [gpr_2]"i"(GPR_2), [gpr_4]"i"(GPR_4), [sprn_texasr] "i" (SPRN_TEXASR), [flt_1] "b" (&a), [flt_4] "b" (&d) - : "memory", "r5", "r6", "r7", + : "memory", "r0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
Signature · 1 line
2.25.1
PATCH v2 2/2 selftests: Skip TM tests on synthetic TM implementations
Transactional Memory was removed from the architecture in ISA v3.1. For threads running in P8/P9 compatibility mode on P10 a synthetic TM implementation is provided. In this implementation, tbegin. always sets cr0 eq meaning the abort handler is always called. This is not an issue as users of TM are expected to have a fallback non transactional way to make forward progress in the abort handler. The TEXASR indicates if a transaction failure is due to a synthetic implementation.
Some of the TM self tests need a non-degenerate TM implementation for their testing to be meaningful so check for a synthetic implementation and skip the test if so.
---
v2: Added checking for synthetic implementation to more tests
--- .../selftests/powerpc/ptrace/ptrace-tm-gpr.c | 1 + .../powerpc/ptrace/ptrace-tm-spd-gpr.c | 1 + .../powerpc/ptrace/ptrace-tm-spd-tar.c | 1 + .../powerpc/ptrace/ptrace-tm-spd-vsx.c | 1 + .../selftests/powerpc/ptrace/ptrace-tm-spr.c | 1 + .../selftests/powerpc/ptrace/ptrace-tm-tar.c | 1 + .../selftests/powerpc/ptrace/ptrace-tm-vsx.c | 1 + .../selftests/powerpc/signal/signal_tm.c | 1 + tools/testing/selftests/powerpc/tm/tm-exec.c | 1 + tools/testing/selftests/powerpc/tm/tm-fork.c | 1 + .../testing/selftests/powerpc/tm/tm-poison.c | 1 + .../selftests/powerpc/tm/tm-resched-dscr.c | 1 + .../powerpc/tm/tm-signal-context-chk-fpu.c | 1 + .../powerpc/tm/tm-signal-context-chk-gpr.c | 1 + .../powerpc/tm/tm-signal-context-chk-vmx.c | 1 + .../powerpc/tm/tm-signal-context-chk-vsx.c | 1 + .../powerpc/tm/tm-signal-pagefault.c | 1 + .../powerpc/tm/tm-signal-sigreturn-nt.c | 1 + .../selftests/powerpc/tm/tm-signal-stack.c | 1 + .../selftests/powerpc/tm/tm-sigreturn.c | 1 + .../testing/selftests/powerpc/tm/tm-syscall.c | 2 +- tools/testing/selftests/powerpc/tm/tm-tar.c | 1 + tools/testing/selftests/powerpc/tm/tm-tmspr.c | 1 + tools/testing/selftests/powerpc/tm/tm-trap.c | 1 + .../selftests/powerpc/tm/tm-unavailable.c | 1 + .../selftests/powerpc/tm/tm-vmx-unavail.c | 1 + .../testing/selftests/powerpc/tm/tm-vmxcopy.c | 1 + tools/testing/selftests/powerpc/tm/tm.h | 36 +++++++++++++++++++ 28 files changed, 63 insertions(+), 1 deletion(-)
tools/testing/selftests/powerpc/ptrace/ptrace-tm-gpr.c +1 -0
@@ -113,6 +113,7 @@ int ptrace_tm_gpr(void)int ret, status;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); shm_id =shmget (IPC_PRIVATE ,sizeof (int ) *2 ,0777 |IPC_CREAT ); pid =fork ();if (pid <0 ) {
tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-gpr.c +1 -0
@@ -119,6 +119,7 @@ int ptrace_tm_spd_gpr(void)int ret, status;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); shm_id =shmget (IPC_PRIVATE ,sizeof (int ) *3 ,0777 |IPC_CREAT ); pid =fork ();if (pid <0 ) {
tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-tar.c +1 -0
@@ -129,6 +129,7 @@ int ptrace_tm_spd_tar(void)int ret, status;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); shm_id =shmget (IPC_PRIVATE ,sizeof (int ) *3 ,0777 |IPC_CREAT ); pid =fork ();if (pid ==0 )
tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-vsx.c +1 -0
@@ -129,6 +129,7 @@ int ptrace_tm_spd_vsx(void)int ret, status, i;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); shm_id =shmget (IPC_PRIVATE ,sizeof (int ) *3 ,0777 |IPC_CREAT );for (i =0 ; i <128 ; i++) {
tools/testing/selftests/powerpc/ptrace/ptrace-tm-spr.c +1 -0
@@ -114,6 +114,7 @@ int ptrace_tm_spr(void)int ret, status;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); shm_id =shmget (IPC_PRIVATE ,sizeof (struct shared ),0777 |IPC_CREAT ); shm_id1 =shmget (IPC_PRIVATE ,sizeof (int ),0777 |IPC_CREAT ); pid =fork ();
tools/testing/selftests/powerpc/ptrace/ptrace-tm-tar.c +1 -0
@@ -117,6 +117,7 @@ int ptrace_tm_tar(void)int ret, status;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); shm_id =shmget (IPC_PRIVATE ,sizeof (int ) *2 ,0777 |IPC_CREAT ); pid =fork ();if (pid ==0 )
tools/testing/selftests/powerpc/ptrace/ptrace-tm-vsx.c +1 -0
@@ -113,6 +113,7 @@ int ptrace_tm_vsx(void)int ret, status, i;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); shm_id =shmget (IPC_PRIVATE ,sizeof (int ) *2 ,0777 |IPC_CREAT );for (i =0 ; i <128 ; i++) {
tools/testing/selftests/powerpc/signal/signal_tm.c +1 -0
@@ -56,6 +56,7 @@ static int test_signal_tm() }SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ());for (i =0 ; i <MAX_ATTEMPT ; i++) {/*
tools/testing/selftests/powerpc/tm/tm-exec.c +1 -0
@@ -27,6 +27,7 @@ static char *path;static int test_exec (void ) {SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); asm __volatile__( "tbegin.;"
tools/testing/selftests/powerpc/tm/tm-fork.c +1 -0
@@ -21,6 +21,7 @@int test_fork (void ) {SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); asm __volatile__( "tbegin.;"
tools/testing/selftests/powerpc/tm/tm-poison.c +1 -0
@@ -34,6 +34,7 @@ int tm_poison_test(void)bool fail_vr = false;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); cpu =pick_online_cpu ();FAIL_IF (cpu <0 );
tools/testing/selftests/powerpc/tm/tm-resched-dscr.c +1 -0
@@ -40,6 +40,7 @@ int test_body(void)uint64_t rv, dscr1 =1 , dscr2, texasr;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ());printf ("Check DSCR TM context switch: " );fflush (stdout);
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-fpu.c +1 -0
@@ -79,6 +79,7 @@ static int tm_signal_context_chk_fpu()pid_t pid =getpid ();SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); act.sa_sigaction = signal_usr1;sigemptyset (&act.sa_mask);
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c +1 -0
@@ -81,6 +81,7 @@ static int tm_signal_context_chk_gpr()pid_t pid =getpid ();SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); act.sa_sigaction = signal_usr1;sigemptyset (&act.sa_mask);
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vmx.c +1 -0
@@ -104,6 +104,7 @@ static int tm_signal_context_chk()pid_t pid =getpid ();SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); act.sa_sigaction = signal_usr1;sigemptyset (&act.sa_mask);
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vsx.c +1 -0
@@ -153,6 +153,7 @@ static int tm_signal_context_chk()pid_t pid =getpid ();SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); act.sa_sigaction = signal_usr1;sigemptyset (&act.sa_mask);
tools/testing/selftests/powerpc/tm/tm-signal-pagefault.c +1 -0
@@ -226,6 +226,7 @@ int tm_signal_pagefault(void)stack_t ss;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ());SKIP_IF (!have_userfaultfd ());setup_uf_mem ();
tools/testing/selftests/powerpc/tm/tm-signal-sigreturn-nt.c +1 -0
@@ -32,6 +32,7 @@ int tm_signal_sigreturn_nt(void)struct sigaction trap_sa;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); trap_sa.sa_flags =SA_SIGINFO ; trap_sa.sa_sigaction = trap_signal_handler;
tools/testing/selftests/powerpc/tm/tm-signal-stack.c +1 -0
@@ -35,6 +35,7 @@ int tm_signal_stack()int pid;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); pid =fork ();if (pid <0 )
tools/testing/selftests/powerpc/tm/tm-sigreturn.c +1 -0
@@ -55,6 +55,7 @@ int tm_sigreturn(void)uint64_t ret =0 ;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ());SKIP_IF (!is_ppc64le ());memset (&sa,0 ,sizeof (sa));
tools/testing/selftests/powerpc/tm/tm-syscall.c +1 -1
@@ -25,7 +25,6 @@ extern int getppid_tm_suspended(void);unsigned retries =0 ;#define TEST_DURATION 10/* seconds */ -#define TM_RETRIES 100pid_t getppid_tm (bool suspend) {
@@ -67,6 +66,7 @@ int tm_syscall(void)struct timeval end, now;SKIP_IF (!have_htm_nosc ()); +SKIP_IF (htm_is_synthetic ());setbuf (stdout,NULL );
tools/testing/selftests/powerpc/tm/tm-tar.c +1 -0
@@ -26,6 +26,7 @@ int test_tar(void)int i;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ());SKIP_IF (!is_ppc64le ());for (i =0 ; i < num_loops; i++)
tools/testing/selftests/powerpc/tm/tm-tmspr.c +1 -0
@@ -96,6 +96,7 @@ int test_tmspr()unsigned long i;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ());/* To cause some context switching */ thread_num =10 *sysconf (_SC_NPROCESSORS_ONLN);
tools/testing/selftests/powerpc/tm/tm-trap.c +1 -0
@@ -255,6 +255,7 @@ int tm_trap_test(void)struct sigaction trap_sa;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); trap_sa.sa_flags =SA_SIGINFO ; trap_sa.sa_sigaction = trap_signal_handler;
tools/testing/selftests/powerpc/tm/tm-unavailable.c +1 -0
@@ -344,6 +344,7 @@ int tm_unavailable_test(void)cpu_set_t cpuset;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); cpu =pick_online_cpu ();FAIL_IF (cpu <0 );
tools/testing/selftests/powerpc/tm/tm-vmx-unavail.c +1 -0
@@ -91,6 +91,7 @@ int tm_vmx_unavail_test()pthread_t *thread;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ()); passed =1 ;
tools/testing/selftests/powerpc/tm/tm-vmxcopy.c +1 -0
@@ -46,6 +46,7 @@ int test_vmxcopy()uint64_t aborted =0 ;SKIP_IF (!have_htm ()); +SKIP_IF (htm_is_synthetic ());SKIP_IF (!is_ppc64le ()); fd =mkstemp (tmpfile);
tools/testing/selftests/powerpc/tm/tm.h +36 -0
@@ -10,6 +10,9 @@#include <asm/tm.h> #include "utils.h" +#include "reg.h" + +#define TM_RETRIES 100static inline bool have_htm (void ) {
@@ -31,6 +34,39 @@ static inline bool have_htm_nosc(void)#endif } +/* +* Transactional Memory was removed in ISA 3.1. A synthetic TM implementation +* is provided on P10 for threads running in P8/P9 compatibility mode. The +* synthetic implementation immediately fails after tbegin. This failure sets +* Bit 7 (Failure Persistent) and Bit 15 (Implementation-specific). +*/ +static inline bool htm_is_synthetic (void ) +{ +int i; + +/* +* Per the ISA, the Failure Persistent bit may be incorrect. Try a few +* times in case we got an Implementation-specific failure on a non ISA +* v3.1 system. On these systems the Implementation-specific failure +* should not be persistent. +*/ +for (i =0 ; i <TM_RETRIES ; i++) { + asmvolatile ( +"tbegin.;" +"beq 1f;" +"tend.;" +"1:" + : + : + :"memory" ); + +if ((__builtin_get_texasr () & (TEXASR_FP |TEXASR_IC )) != + (TEXASR_FP |TEXASR_IC )) +break ; + } +return i ==TM_RETRIES ; +} +static inline long failure_code (void ) {return __builtin_get_texasru () >>24 ;
Signature · 1 line
2.25.1
Michael Ellerman
AppliedQuoted 20 lines · Jordan Niethe
ISA v3.1 removes TM but includes a synthetic implementation for backwards compatibility. With this implementation, the tests ptrace-tm-spd-gpr and ptrace-tm-gpr should never be able to make any forward progress and eventually should be killed by the timeout. Instead on a P10 running in P9 mode,
ptrace_tm_gprfails like so:test:
ptrace_tm_gpr
tags: git_version:unknown
Starting the child
...
...
GPR[27]: 1 Expected: 2
GPR[28]: 1 Expected: 2
GPR[29]: 1 Expected: 2
GPR[30]: 1 Expected: 2
GPR[31]: 1 Expected: 2
[FAIL] Test FAILED on line 98
failure:ptrace_tm_gpr
selftests: ptrace-tm-gpr [FAIL]
Quoted 1 line
[...]
Applied to powerpc/next.
[1/2] selftests/powerpc: Add missing clobbered register to to ptrace TM tests
https://git.kernel.org/powerpc/c/c95278a0534449efc64ac8169382bce217963be2 [2/2] selftests: Skip TM tests on synthetic TM implementations https://git.kernel.org/powerpc/c/e42edf9b9d126bb1c743f2e7984877ba27f09fe7
cheers