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>
26 void *worker(void *unused
)
32 "li 3, 1;" /* Stick non-zero value in VMX0 */
33 "std 3, 0(%[vmx0_ptr]);"
34 "lvx 0, 0, %[vmx0_ptr];"
36 /* Wait here a bit so we get scheduled out 255 times */
43 /* Kernel will hopefully turn VMX off now */
48 /* Cause VMX unavail. Any VMX instruction */
54 /* Check VMX0 sanity after abort */
56 "lvx 1, 0, %[vmx0_ptr];"
58 "bc 4, 24, %l[value_mismatch];"
61 : [vmx0_ptr
] "r"(&vmx0
)
63 : success
, value_match
, value_mismatch
66 /* HTM aborted and VMX0 is corrupted */
68 texasr
= __builtin_get_texasr();
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
));
78 /* HTM aborted but VMX0 is correct */
88 int tm_vmx_unavail_test()
94 SKIP_IF(htm_is_synthetic());
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");