~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/tm/tm-syscall.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright 2015, Sam Bobroff, IBM Corp.
  4  *
  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.
 10  */
 11 
 12 #include <stdio.h>
 13 #include <unistd.h>
 14 #include <sys/syscall.h>
 15 #include <asm/tm.h>
 16 #include <sys/time.h>
 17 #include <stdlib.h>
 18 
 19 #include "utils.h"
 20 #include "tm.h"
 21 
 22 #ifndef PPC_FEATURE2_SCV
 23 #define PPC_FEATURE2_SCV               0x00100000 /* scv syscall */
 24 #endif
 25 
 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);
 30 
 31 unsigned retries = 0;
 32 
 33 #define TEST_DURATION 10 /* seconds */
 34 
 35 pid_t getppid_tm(bool scv, bool suspend)
 36 {
 37         int i;
 38         pid_t pid;
 39 
 40         for (i = 0; i < TM_RETRIES; i++) {
 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                 }
 52 
 53                 if (pid >= 0)
 54                         return pid;
 55 
 56                 if (failure_is_persistent()) {
 57                         if (failure_is_syscall())
 58                                 return -1;
 59 
 60                         printf("Unexpected persistent transaction failure.\n");
 61                         printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
 62                                __builtin_get_texasr(), __builtin_get_tfiar());
 63                         exit(-1);
 64                 }
 65 
 66                 retries++;
 67         }
 68 
 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());
 72 
 73         exit(-1);
 74 }
 75 
 76 int tm_syscall(void)
 77 {
 78         unsigned count = 0;
 79         struct timeval end, now;
 80 
 81         SKIP_IF(!have_htm_nosc());
 82         SKIP_IF(htm_is_synthetic());
 83 
 84         setbuf(stdout, NULL);
 85 
 86         printf("Testing transactional syscalls for %d seconds...\n", TEST_DURATION);
 87 
 88         gettimeofday(&end, NULL);
 89         now.tv_sec = TEST_DURATION;
 90         now.tv_usec = 0;
 91         timeradd(&end, &now, &end);
 92 
 93         for (count = 0; timercmp(&now, &end, <); count++) {
 94                 /*
 95                  * Test a syscall within a suspended transaction and verify
 96                  * that it succeeds.
 97                  */
 98                 FAIL_IF(getppid_tm(false, true) == -1); /* Should succeed. */
 99 
100                 /*
101                  * Test a syscall within an active transaction and verify that
102                  * it fails with the correct failure code.
103                  */
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. */
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 
116                 gettimeofday(&now, 0);
117         }
118 
119         printf("%d active and suspended transactions behaved correctly.\n", count);
120         printf("(There were %d transaction retries.)\n", retries);
121 
122         return 0;
123 }
124 
125 int main(void)
126 {
127         return test_harness(tm_syscall, "tm_syscall");
128 }
129 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php