This source file includes following definitions.
- cpu_has_vmx
- cpu_vmxoff
- cpu_vmx_enabled
- __cpu_emergency_vmxoff
- cpu_emergency_vmxoff
- cpu_has_svm
- cpu_svm_disable
- cpu_emergency_svm_disable
1
2
3
4
5
6
7
8
9
10
11
12
13 #ifndef _ASM_X86_VIRTEX_H
14 #define _ASM_X86_VIRTEX_H
15
16 #include <asm/processor.h>
17
18 #include <asm/vmx.h>
19 #include <asm/svm.h>
20 #include <asm/tlbflush.h>
21
22
23
24
25
26 static inline int cpu_has_vmx(void)
27 {
28 unsigned long ecx = cpuid_ecx(1);
29 return test_bit(5, &ecx);
30 }
31
32
33
34
35
36
37
38
39 static inline void cpu_vmxoff(void)
40 {
41 asm volatile ("vmxoff");
42 cr4_clear_bits(X86_CR4_VMXE);
43 }
44
45 static inline int cpu_vmx_enabled(void)
46 {
47 return __read_cr4() & X86_CR4_VMXE;
48 }
49
50
51
52
53
54 static inline void __cpu_emergency_vmxoff(void)
55 {
56 if (cpu_vmx_enabled())
57 cpu_vmxoff();
58 }
59
60
61
62 static inline void cpu_emergency_vmxoff(void)
63 {
64 if (cpu_has_vmx())
65 __cpu_emergency_vmxoff();
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 static inline int cpu_has_svm(const char **msg)
83 {
84 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
85 boot_cpu_data.x86_vendor != X86_VENDOR_HYGON) {
86 if (msg)
87 *msg = "not amd or hygon";
88 return 0;
89 }
90
91 if (boot_cpu_data.extended_cpuid_level < SVM_CPUID_FUNC) {
92 if (msg)
93 *msg = "can't execute cpuid_8000000a";
94 return 0;
95 }
96
97 if (!boot_cpu_has(X86_FEATURE_SVM)) {
98 if (msg)
99 *msg = "svm not available";
100 return 0;
101 }
102 return 1;
103 }
104
105
106
107
108
109
110 static inline void cpu_svm_disable(void)
111 {
112 uint64_t efer;
113
114 wrmsrl(MSR_VM_HSAVE_PA, 0);
115 rdmsrl(MSR_EFER, efer);
116 wrmsrl(MSR_EFER, efer & ~EFER_SVME);
117 }
118
119
120
121 static inline void cpu_emergency_svm_disable(void)
122 {
123 if (cpu_has_svm(NULL))
124 cpu_svm_disable();
125 }
126
127 #endif