blob: dd05b9cef6ae332d42ebee6c2cb41554e8eef632 [file] [log] [blame]
Avi Kivity00b27a32011-11-23 16:30:32 +02001#ifndef ARCH_X86_KVM_CPUID_H
2#define ARCH_X86_KVM_CPUID_H
3
4#include "x86.h"
5
Nadav Amitdd598092014-09-16 15:10:03 +03006int kvm_update_cpuid(struct kvm_vcpu *vcpu);
Avi Kivity00b27a32011-11-23 16:30:32 +02007struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
8 u32 function, u32 index);
Borislav Petkov9c15bb12013-09-22 16:44:50 +02009int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
10 struct kvm_cpuid_entry2 __user *entries,
11 unsigned int type);
Avi Kivity00b27a32011-11-23 16:30:32 +020012int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
13 struct kvm_cpuid *cpuid,
14 struct kvm_cpuid_entry __user *entries);
15int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
16 struct kvm_cpuid2 *cpuid,
17 struct kvm_cpuid_entry2 __user *entries);
18int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
19 struct kvm_cpuid2 *cpuid,
20 struct kvm_cpuid_entry2 __user *entries);
Avi Kivity62046e52012-06-07 14:07:48 +030021void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
Avi Kivity00b27a32011-11-23 16:30:32 +020022
Eugene Korenevsky5a4f55c2015-03-29 23:56:12 +030023int cpuid_query_maxphyaddr(struct kvm_vcpu *vcpu);
24
25static inline int cpuid_maxphyaddr(struct kvm_vcpu *vcpu)
26{
27 return vcpu->arch.maxphyaddr;
28}
Avi Kivity00b27a32011-11-23 16:30:32 +020029
30static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
31{
32 struct kvm_cpuid_entry2 *best;
33
Petr Matousek6d1068b2012-11-06 19:24:07 +010034 if (!static_cpu_has(X86_FEATURE_XSAVE))
Joe Perches1d804d02015-03-30 16:46:09 -070035 return false;
Petr Matousek6d1068b2012-11-06 19:24:07 +010036
Avi Kivity00b27a32011-11-23 16:30:32 +020037 best = kvm_find_cpuid_entry(vcpu, 1, 0);
38 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
39}
40
Will Auldba904632012-11-29 12:42:50 -080041static inline bool guest_cpuid_has_tsc_adjust(struct kvm_vcpu *vcpu)
42{
43 struct kvm_cpuid_entry2 *best;
44
45 best = kvm_find_cpuid_entry(vcpu, 7, 0);
46 return best && (best->ebx & bit(X86_FEATURE_TSC_ADJUST));
47}
48
Avi Kivity00b27a32011-11-23 16:30:32 +020049static inline bool guest_cpuid_has_smep(struct kvm_vcpu *vcpu)
50{
51 struct kvm_cpuid_entry2 *best;
52
53 best = kvm_find_cpuid_entry(vcpu, 7, 0);
54 return best && (best->ebx & bit(X86_FEATURE_SMEP));
55}
56
Feng Wu97ec8c02014-04-01 17:46:34 +080057static inline bool guest_cpuid_has_smap(struct kvm_vcpu *vcpu)
58{
59 struct kvm_cpuid_entry2 *best;
60
61 best = kvm_find_cpuid_entry(vcpu, 7, 0);
62 return best && (best->ebx & bit(X86_FEATURE_SMAP));
63}
64
Avi Kivity00b27a32011-11-23 16:30:32 +020065static inline bool guest_cpuid_has_fsgsbase(struct kvm_vcpu *vcpu)
66{
67 struct kvm_cpuid_entry2 *best;
68
69 best = kvm_find_cpuid_entry(vcpu, 7, 0);
70 return best && (best->ebx & bit(X86_FEATURE_FSGSBASE));
71}
72
Paolo Bonzini660a5d52015-05-05 11:50:23 +020073static inline bool guest_cpuid_has_longmode(struct kvm_vcpu *vcpu)
74{
75 struct kvm_cpuid_entry2 *best;
76
77 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
78 return best && (best->edx & bit(X86_FEATURE_LM));
79}
80
Boris Ostrovsky2b036c62012-01-09 14:00:35 -050081static inline bool guest_cpuid_has_osvw(struct kvm_vcpu *vcpu)
82{
83 struct kvm_cpuid_entry2 *best;
84
85 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
86 return best && (best->ecx & bit(X86_FEATURE_OSVW));
87}
88
Mao, Junjiead756a12012-07-02 01:18:48 +000089static inline bool guest_cpuid_has_pcid(struct kvm_vcpu *vcpu)
90{
91 struct kvm_cpuid_entry2 *best;
92
93 best = kvm_find_cpuid_entry(vcpu, 1, 0);
94 return best && (best->ecx & bit(X86_FEATURE_PCID));
95}
96
Jan Kiszka58cb6282014-01-24 16:48:44 +010097static inline bool guest_cpuid_has_x2apic(struct kvm_vcpu *vcpu)
98{
99 struct kvm_cpuid_entry2 *best;
100
101 best = kvm_find_cpuid_entry(vcpu, 1, 0);
102 return best && (best->ecx & bit(X86_FEATURE_X2APIC));
103}
104
Paolo Bonzinia0c0feb2014-09-02 13:24:12 +0200105static inline bool guest_cpuid_is_amd(struct kvm_vcpu *vcpu)
106{
107 struct kvm_cpuid_entry2 *best;
108
109 best = kvm_find_cpuid_entry(vcpu, 0, 0);
110 return best && best->ebx == X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx;
111}
112
Nadav Amit5f7dde72014-05-07 15:32:50 +0300113static inline bool guest_cpuid_has_gbpages(struct kvm_vcpu *vcpu)
114{
115 struct kvm_cpuid_entry2 *best;
116
117 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
118 return best && (best->edx & bit(X86_FEATURE_GBPAGES));
119}
Nadav Amit6f43ed02014-07-15 17:37:46 +0300120
121static inline bool guest_cpuid_has_rtm(struct kvm_vcpu *vcpu)
122{
123 struct kvm_cpuid_entry2 *best;
124
125 best = kvm_find_cpuid_entry(vcpu, 7, 0);
126 return best && (best->ebx & bit(X86_FEATURE_RTM));
127}
Liang Lic447e762015-05-21 04:41:25 +0800128
129static inline bool guest_cpuid_has_mpx(struct kvm_vcpu *vcpu)
130{
131 struct kvm_cpuid_entry2 *best;
132
133 best = kvm_find_cpuid_entry(vcpu, 7, 0);
134 return best && (best->ebx & bit(X86_FEATURE_MPX));
135}
Avi Kivity00b27a32011-11-23 16:30:32 +0200136#endif