x86/mm: Remove preempt_disable/enable() from __native_flush_tlb()
[linux/fpc-iii.git] / tools / testing / selftests / powerpc / tm / tm-vmx-unavail.c
blob137185ba4937b8f73b0d0ada357f7776c2295618
1 /*
2 * Copyright 2017, Michael Neuling, IBM Corp.
3 * Licensed under GPLv2.
4 * Original: Breno Leitao <brenohl@br.ibm.com> &
5 * Gustavo Bueno Romero <gromero@br.ibm.com>
6 * Edited: Michael Neuling
8 * Force VMX unavailable during a transaction and see if it corrupts
9 * the checkpointed VMX register state after the abort.
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 #include <pthread.h>
22 #include "tm.h"
23 #include "utils.h"
25 int passed;
27 void *worker(void *unused)
29 __int128 vmx0;
30 uint64_t texasr;
32 asm goto (
33 "li 3, 1;" /* Stick non-zero value in VMX0 */
34 "std 3, 0(%[vmx0_ptr]);"
35 "lvx 0, 0, %[vmx0_ptr];"
37 /* Wait here a bit so we get scheduled out 255 times */
38 "lis 3, 0x3fff;"
39 "1: ;"
40 "addi 3, 3, -1;"
41 "cmpdi 3, 0;"
42 "bne 1b;"
44 /* Kernel will hopefully turn VMX off now */
46 "tbegin. ;"
47 "beq failure;"
49 /* Cause VMX unavail. Any VMX instruction */
50 "vaddcuw 0,0,0;"
52 "tend. ;"
53 "b %l[success];"
55 /* Check VMX0 sanity after abort */
56 "failure: ;"
57 "lvx 1, 0, %[vmx0_ptr];"
58 "vcmpequb. 2, 0, 1;"
59 "bc 4, 24, %l[value_mismatch];"
60 "b %l[value_match];"
62 : [vmx0_ptr] "r"(&vmx0)
63 : "r3"
64 : success, value_match, value_mismatch
67 /* HTM aborted and VMX0 is corrupted */
68 value_mismatch:
69 texasr = __builtin_get_texasr();
71 printf("\n\n==============\n\n");
72 printf("Failure with error: %lx\n", _TEXASR_FAILURE_CODE(texasr));
73 printf("Summary error : %lx\n", _TEXASR_FAILURE_SUMMARY(texasr));
74 printf("TFIAR exact : %lx\n\n", _TEXASR_TFIAR_EXACT(texasr));
76 passed = 0;
77 return NULL;
79 /* HTM aborted but VMX0 is correct */
80 value_match:
81 // printf("!");
82 return NULL;
84 success:
85 // printf(".");
86 return NULL;
89 int tm_vmx_unavail_test()
91 int threads;
92 pthread_t *thread;
94 SKIP_IF(!have_htm());
96 passed = 1;
98 threads = sysconf(_SC_NPROCESSORS_ONLN) * 4;
99 thread = malloc(sizeof(pthread_t)*threads);
100 if (!thread)
101 return EXIT_FAILURE;
103 for (uint64_t i = 0; i < threads; i++)
104 pthread_create(&thread[i], NULL, &worker, NULL);
106 for (uint64_t i = 0; i < threads; i++)
107 pthread_join(thread[i], NULL);
109 free(thread);
111 return passed ? EXIT_SUCCESS : EXIT_FAILURE;
115 int main(int argc, char **argv)
117 return test_harness(tm_vmx_unavail_test, "tm_vmx_unavail_test");