1 // SPDX-License-Identifier: GPL-2.0-only
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
8 * Force VMX unavailable during a transaction and see if it corrupts
9 * the checkpointed VMX register state after the abort.
13 #include <htmintrin.h>
27 void *worker(void *unused
)
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 */
44 /* Kernel will hopefully turn VMX off now */
49 /* Cause VMX unavail. Any VMX instruction */
55 /* Check VMX0 sanity after abort */
57 "lvx 1, 0, %[vmx0_ptr];"
59 "bc 4, 24, %l[value_mismatch];"
62 : [vmx0_ptr
] "r"(&vmx0
)
64 : success
, value_match
, value_mismatch
67 /* HTM aborted and VMX0 is corrupted */
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
));
79 /* HTM aborted but VMX0 is correct */
89 int tm_vmx_unavail_test()
98 threads
= sysconf(_SC_NPROCESSORS_ONLN
) * 4;
99 thread
= malloc(sizeof(pthread_t
)*threads
);
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
);
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");