1 #ifndef ARCH_X86_KVM_CPUID_H
2 #define ARCH_X86_KVM_CPUID_H
6 int kvm_update_cpuid(struct kvm_vcpu *vcpu);
7 struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
8 u32 function, u32 index);
9 int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
10 struct kvm_cpuid_entry2 __user *entries,
12 int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
13 struct kvm_cpuid *cpuid,
14 struct kvm_cpuid_entry __user *entries);
15 int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
16 struct kvm_cpuid2 *cpuid,
17 struct kvm_cpuid_entry2 __user *entries);
18 int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
19 struct kvm_cpuid2 *cpuid,
20 struct kvm_cpuid_entry2 __user *entries);
21 void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
23 int cpuid_query_maxphyaddr(struct kvm_vcpu *vcpu);
25 static inline int cpuid_maxphyaddr(struct kvm_vcpu *vcpu)
27 return vcpu->arch.maxphyaddr;
30 static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
32 struct kvm_cpuid_entry2 *best;
34 if (!static_cpu_has(X86_FEATURE_XSAVE))
37 best = kvm_find_cpuid_entry(vcpu, 1, 0);
38 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
41 static inline bool guest_cpuid_has_mtrr(struct kvm_vcpu *vcpu)
43 struct kvm_cpuid_entry2 *best;
45 best = kvm_find_cpuid_entry(vcpu, 1, 0);
46 return best && (best->edx & bit(X86_FEATURE_MTRR));
49 static inline bool guest_cpuid_has_tsc_adjust(struct kvm_vcpu *vcpu)
51 struct kvm_cpuid_entry2 *best;
53 best = kvm_find_cpuid_entry(vcpu, 7, 0);
54 return best && (best->ebx & bit(X86_FEATURE_TSC_ADJUST));
57 static inline bool guest_cpuid_has_smep(struct kvm_vcpu *vcpu)
59 struct kvm_cpuid_entry2 *best;
61 best = kvm_find_cpuid_entry(vcpu, 7, 0);
62 return best && (best->ebx & bit(X86_FEATURE_SMEP));
65 static inline bool guest_cpuid_has_smap(struct kvm_vcpu *vcpu)
67 struct kvm_cpuid_entry2 *best;
69 best = kvm_find_cpuid_entry(vcpu, 7, 0);
70 return best && (best->ebx & bit(X86_FEATURE_SMAP));
73 static inline bool guest_cpuid_has_fsgsbase(struct kvm_vcpu *vcpu)
75 struct kvm_cpuid_entry2 *best;
77 best = kvm_find_cpuid_entry(vcpu, 7, 0);
78 return best && (best->ebx & bit(X86_FEATURE_FSGSBASE));
81 static inline bool guest_cpuid_has_longmode(struct kvm_vcpu *vcpu)
83 struct kvm_cpuid_entry2 *best;
85 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
86 return best && (best->edx & bit(X86_FEATURE_LM));
89 static inline bool guest_cpuid_has_osvw(struct kvm_vcpu *vcpu)
91 struct kvm_cpuid_entry2 *best;
93 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
94 return best && (best->ecx & bit(X86_FEATURE_OSVW));
97 static inline bool guest_cpuid_has_pcid(struct kvm_vcpu *vcpu)
99 struct kvm_cpuid_entry2 *best;
101 best = kvm_find_cpuid_entry(vcpu, 1, 0);
102 return best && (best->ecx & bit(X86_FEATURE_PCID));
105 static inline bool guest_cpuid_has_x2apic(struct kvm_vcpu *vcpu)
107 struct kvm_cpuid_entry2 *best;
109 best = kvm_find_cpuid_entry(vcpu, 1, 0);
110 return best && (best->ecx & bit(X86_FEATURE_X2APIC));
113 static inline bool guest_cpuid_is_amd(struct kvm_vcpu *vcpu)
115 struct kvm_cpuid_entry2 *best;
117 best = kvm_find_cpuid_entry(vcpu, 0, 0);
118 return best && best->ebx == X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx;
121 static inline bool guest_cpuid_has_gbpages(struct kvm_vcpu *vcpu)
123 struct kvm_cpuid_entry2 *best;
125 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
126 return best && (best->edx & bit(X86_FEATURE_GBPAGES));
129 static inline bool guest_cpuid_has_rtm(struct kvm_vcpu *vcpu)
131 struct kvm_cpuid_entry2 *best;
133 best = kvm_find_cpuid_entry(vcpu, 7, 0);
134 return best && (best->ebx & bit(X86_FEATURE_RTM));
137 static inline bool guest_cpuid_has_mpx(struct kvm_vcpu *vcpu)
139 struct kvm_cpuid_entry2 *best;
141 best = kvm_find_cpuid_entry(vcpu, 7, 0);
142 return best && (best->ebx & bit(X86_FEATURE_MPX));
145 static inline bool guest_cpuid_has_pcommit(struct kvm_vcpu *vcpu)
147 struct kvm_cpuid_entry2 *best;
149 best = kvm_find_cpuid_entry(vcpu, 7, 0);
150 return best && (best->ebx & bit(X86_FEATURE_PCOMMIT));
153 static inline bool guest_cpuid_has_rdtscp(struct kvm_vcpu *vcpu)
155 struct kvm_cpuid_entry2 *best;
157 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
158 return best && (best->edx & bit(X86_FEATURE_RDTSCP));
162 * NRIPS is provided through cpuidfn 0x8000000a.edx bit 3
166 static inline bool guest_cpuid_has_nrips(struct kvm_vcpu *vcpu)
168 struct kvm_cpuid_entry2 *best;
170 best = kvm_find_cpuid_entry(vcpu, 0x8000000a, 0);
173 * NRIPS is a scattered cpuid feature, so we can't use
174 * X86_FEATURE_NRIPS here (X86_FEATURE_NRIPS would be bit
175 * position 8, not 3).
177 return best && (best->edx & bit(BIT_NRIPS));