Skip to content

Commit 5379ef2

Browse files
npigginmpe
authored andcommitted
selftests/powerpc: Add scv versions of the basic TM syscall tests
The basic TM vs syscall test code hard codes an sc instruction for the system call, which fails to cover scv even when the userspace libc has support for it. Duplicate the tests with hard coded scv variants so both are tested when possible. Signed-off-by: Nicholas Piggin <[email protected]> [mpe: Fix build on old toolchains by using .long for scv] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b871895 commit 5379ef2

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

tools/testing/selftests/powerpc/tm/tm-syscall-asm.S

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#include <ppc-asm.h>
2+
#include <basic_asm.h>
33
#include <asm/unistd.h>
44

55
.text
@@ -26,3 +26,38 @@ FUNC_START(getppid_tm_suspended)
2626
1:
2727
li r3, -1
2828
blr
29+
30+
31+
.macro scv level
32+
.long (0x44000001 | (\level) << 5)
33+
.endm
34+
35+
FUNC_START(getppid_scv_tm_active)
36+
PUSH_BASIC_STACK(0)
37+
tbegin.
38+
beq 1f
39+
li r0, __NR_getppid
40+
scv 0
41+
tend.
42+
POP_BASIC_STACK(0)
43+
blr
44+
1:
45+
li r3, -1
46+
POP_BASIC_STACK(0)
47+
blr
48+
49+
FUNC_START(getppid_scv_tm_suspended)
50+
PUSH_BASIC_STACK(0)
51+
tbegin.
52+
beq 1f
53+
li r0, __NR_getppid
54+
tsuspend.
55+
scv 0
56+
tresume.
57+
tend.
58+
POP_BASIC_STACK(0)
59+
blr
60+
1:
61+
li r3, -1
62+
POP_BASIC_STACK(0)
63+
blr

tools/testing/selftests/powerpc/tm/tm-syscall.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,36 @@
1919
#include "utils.h"
2020
#include "tm.h"
2121

22+
#ifndef PPC_FEATURE2_SCV
23+
#define PPC_FEATURE2_SCV 0x00100000 /* scv syscall */
24+
#endif
25+
2226
extern int getppid_tm_active(void);
2327
extern int getppid_tm_suspended(void);
28+
extern int getppid_scv_tm_active(void);
29+
extern int getppid_scv_tm_suspended(void);
2430

2531
unsigned retries = 0;
2632

2733
#define TEST_DURATION 10 /* seconds */
2834

29-
pid_t getppid_tm(bool suspend)
35+
pid_t getppid_tm(bool scv, bool suspend)
3036
{
3137
int i;
3238
pid_t pid;
3339

3440
for (i = 0; i < TM_RETRIES; i++) {
35-
if (suspend)
36-
pid = getppid_tm_suspended();
37-
else
38-
pid = getppid_tm_active();
41+
if (suspend) {
42+
if (scv)
43+
pid = getppid_scv_tm_suspended();
44+
else
45+
pid = getppid_tm_suspended();
46+
} else {
47+
if (scv)
48+
pid = getppid_scv_tm_active();
49+
else
50+
pid = getppid_tm_active();
51+
}
3952

4053
if (pid >= 0)
4154
return pid;
@@ -82,15 +95,24 @@ int tm_syscall(void)
8295
* Test a syscall within a suspended transaction and verify
8396
* that it succeeds.
8497
*/
85-
FAIL_IF(getppid_tm(true) == -1); /* Should succeed. */
98+
FAIL_IF(getppid_tm(false, true) == -1); /* Should succeed. */
8699

87100
/*
88101
* Test a syscall within an active transaction and verify that
89102
* it fails with the correct failure code.
90103
*/
91-
FAIL_IF(getppid_tm(false) != -1); /* Should fail... */
104+
FAIL_IF(getppid_tm(false, false) != -1); /* Should fail... */
92105
FAIL_IF(!failure_is_persistent()); /* ...persistently... */
93106
FAIL_IF(!failure_is_syscall()); /* ...with code syscall. */
107+
108+
/* Now do it all again with scv if it is available. */
109+
if (have_hwcap2(PPC_FEATURE2_SCV)) {
110+
FAIL_IF(getppid_tm(true, true) == -1); /* Should succeed. */
111+
FAIL_IF(getppid_tm(true, false) != -1); /* Should fail... */
112+
FAIL_IF(!failure_is_persistent()); /* ...persistently... */
113+
FAIL_IF(!failure_is_syscall()); /* ...with code syscall. */
114+
}
115+
94116
gettimeofday(&now, 0);
95117
}
96118

0 commit comments

Comments
 (0)