xref: /kvm-unit-tests/x86/memory.c (revision cd5f2fb4ad641c51fe0f1a85264dc3f6ede6e131)
1 /*
2  * Test for x86 cache and memory instructions
3  *
4  * Copyright (c) 2015 Red Hat Inc
5  *
6  * Authors:
7  *  Eduardo Habkost <ehabkost@redhat.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.
10  */
11 
12 #include "libcflat.h"
13 #include "desc.h"
14 #include "processor.h"
15 
16 static long target;
17 
main(int ac,char ** av)18 int main(int ac, char **av)
19 {
20 	if (this_cpu_has(X86_FEATURE_CLFLUSH))
21 		asm_safe_report("clflush (%0)", "b" (&target));
22 	else
23 		report_skip("clflush");
24 
25 	if (this_cpu_has(X86_FEATURE_XMM))
26 		asm_safe_report("sfence");
27 	else
28 		report_skip("sfence");
29 
30 	if (this_cpu_has(X86_FEATURE_XMM2)) {
31 		asm_safe_report("lfence");
32 		asm_safe_report("mfence");
33 	} else {
34 		report_skip("lfence");
35 		report_skip("mfence");
36 	}
37 
38 	if (this_cpu_has(X86_FEATURE_CLFLUSHOPT)) {
39 		/* clflushopt (%rbx): */
40 		asm_safe_report(".byte 0x66, 0x0f, 0xae, 0x3b", "b" (&target));
41 	} else {
42 		report_skip("clflushopt");
43 	}
44 
45 	if (this_cpu_has(X86_FEATURE_CLWB)) {
46 		/* clwb (%rbx): */
47 		asm_safe_report(".byte 0x66, 0x0f, 0xae, 0x33", "b" (&target));
48 	} else {
49 		report_skip("clwb");
50 	}
51 
52 	if (this_cpu_has(X86_FEATURE_PCOMMIT)) { /* PCOMMIT */
53 		/* pcommit: */
54 		asm_safe_report(".byte 0x66, 0x0f, 0xae, 0xf8");
55 	} else {
56 		report_skip("pcommit");
57 	}
58 
59 	return report_summary();
60 }
61