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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 2017, Michael Neuling, IBM Corp.
  4  * Original: Breno Leitao <brenohl@br.ibm.com> &
  5  *           Gustavo Bueno Romero <gromero@br.ibm.com>
  6  * Edited: Michael Neuling
  7  *
  8  * Force VMX unavailable during a transaction and see if it corrupts
  9  * the checkpointed VMX register state after the abort.
 10  */
 11 
 12 #include <inttypes.h>
 13 #include <htmintrin.h>
 14 #include <string.h>
 15 #include <stdlib.h>
 16 #include <stdio.h>
 17 #include <pthread.h>
 18 #include <sys/mman.h>
 19 #include <unistd.h>
 20 
 21 #include "tm.h"
 22 #include "utils.h"
 23 
 24 int passed;
 25 
 26 void *worker(void *unused)
 27 {
 28         __int128 vmx0;
 29         uint64_t texasr;
 30 
 31         asm goto (
 32                 "li       3, 1;"  /* Stick non-zero value in VMX0 */
 33                 "std      3, 0(%[vmx0_ptr]);"
 34                 "lvx      0, 0, %[vmx0_ptr];"
 35 
 36                 /* Wait here a bit so we get scheduled out 255 times */
 37                 "lis      3, 0x3fff;"
 38                 "1: ;"
 39                 "addi     3, 3, -1;"
 40                 "cmpdi    3, 0;"
 41                 "bne      1b;"
 42 
 43                 /* Kernel will hopefully turn VMX off now */
 44 
 45                 "tbegin. ;"
 46                 "beq      failure;"
 47 
 48                 /* Cause VMX unavail. Any VMX instruction */
 49                 "vaddcuw  0,0,0;"
 50 
 51                 "tend. ;"
 52                 "b        %l[success];"
 53 
 54                 /* Check VMX0 sanity after abort */
 55                 "failure: ;"
 56                 "lvx       1,  0, %[vmx0_ptr];"
 57                 "vcmpequb. 2,  0, 1;"
 58                 "bc        4, 24, %l[value_mismatch];"
 59                 "b        %l[value_match];"
 60                 :
 61                 : [vmx0_ptr] "r"(&vmx0)
 62                 : "r3"
 63                 : success, value_match, value_mismatch
 64                 );
 65 
 66         /* HTM aborted and VMX0 is corrupted */
 67 value_mismatch:
 68         texasr = __builtin_get_texasr();
 69 
 70         printf("\n\n==============\n\n");
 71         printf("Failure with error: %lx\n",   _TEXASR_FAILURE_CODE(texasr));
 72         printf("Summary error     : %lx\n",   _TEXASR_FAILURE_SUMMARY(texasr));
 73         printf("TFIAR exact       : %lx\n\n", _TEXASR_TFIAR_EXACT(texasr));
 74 
 75         passed = 0;
 76         return NULL;
 77 
 78         /* HTM aborted but VMX0 is correct */
 79 value_match:
 80 //      printf("!");
 81         return NULL;
 82 
 83 success:
 84 //      printf(".");
 85         return NULL;
 86 }
 87 
 88 int tm_vmx_unavail_test()
 89 {
 90         int threads;
 91         pthread_t *thread;
 92 
 93         SKIP_IF(!have_htm());
 94         SKIP_IF(htm_is_synthetic());
 95 
 96         passed = 1;
 97 
 98         threads = sysconf(_SC_NPROCESSORS_ONLN) * 4;
 99         thread = malloc(sizeof(pthread_t)*threads);
100         if (!thread)
101                 return EXIT_FAILURE;
102 
103         for (uint64_t i = 0; i < threads; i++)
104                 pthread_create(&thread[i], NULL, &worker, NULL);
105 
106         for (uint64_t i = 0; i < threads; i++)
107                 pthread_join(thread[i], NULL);
108 
109         free(thread);
110 
111         return passed ? EXIT_SUCCESS : EXIT_FAILURE;
112 }
113 
114 
115 int main(int argc, char **argv)
116 {
117         return test_harness(tm_vmx_unavail_test, "tm_vmx_unavail_test");
118 }
119 

~ [ 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