1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2015, Sam Bobroff, IBM Corp.
5 * Test the kernel's system call code to ensure that a system call
6 * made from within an active HTM transaction is aborted with the
7 * correct failure code.
8 * Conversely, ensure that a system call made from within a
9 * suspended transaction can succeed.
14 #include <sys/syscall.h>
22 #ifndef PPC_FEATURE2_SCV
23 #define PPC_FEATURE2_SCV 0x00100000 /* scv syscall */
26 extern int getppid_tm_active(void);
27 extern int getppid_tm_suspended(void);
28 extern int getppid_scv_tm_active(void);
29 extern int getppid_scv_tm_suspended(void);
33 #define TEST_DURATION 10 /* seconds */
35 pid_t
getppid_tm(bool scv
, bool suspend
)
40 for (i
= 0; i
< TM_RETRIES
; i
++) {
43 pid
= getppid_scv_tm_suspended();
45 pid
= getppid_tm_suspended();
48 pid
= getppid_scv_tm_active();
50 pid
= getppid_tm_active();
56 if (failure_is_persistent()) {
57 if (failure_is_syscall())
60 printf("Unexpected persistent transaction failure.\n");
61 printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
62 __builtin_get_texasr(), __builtin_get_tfiar());
69 printf("Exceeded limit of %d temporary transaction failures.\n", TM_RETRIES
);
70 printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
71 __builtin_get_texasr(), __builtin_get_tfiar());
79 struct timeval end
, now
;
81 SKIP_IF(!have_htm_nosc());
82 SKIP_IF(htm_is_synthetic());
86 printf("Testing transactional syscalls for %d seconds...\n", TEST_DURATION
);
88 gettimeofday(&end
, NULL
);
89 now
.tv_sec
= TEST_DURATION
;
91 timeradd(&end
, &now
, &end
);
93 for (count
= 0; timercmp(&now
, &end
, <); count
++) {
95 * Test a syscall within a suspended transaction and verify
98 FAIL_IF(getppid_tm(false, true) == -1); /* Should succeed. */
101 * Test a syscall within an active transaction and verify that
102 * it fails with the correct failure code.
104 FAIL_IF(getppid_tm(false, false) != -1); /* Should fail... */
105 FAIL_IF(!failure_is_persistent()); /* ...persistently... */
106 FAIL_IF(!failure_is_syscall()); /* ...with code syscall. */
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. */
116 gettimeofday(&now
, 0);
119 printf("%d active and suspended transactions behaved correctly.\n", count
);
120 printf("(There were %d transaction retries.)\n", retries
);
127 return test_harness(tm_syscall
, "tm_syscall");