Avi Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 1 | #ifndef ARCH_X86_KVM_CPUID_H |
| 2 | #define ARCH_X86_KVM_CPUID_H |
| 3 | |
| 4 | #include "x86.h" |
| 5 | |
Nadav Amit | dd59809 | 2014-09-16 15:10:03 +0300 | [diff] [blame] | 6 | int kvm_update_cpuid(struct kvm_vcpu *vcpu); |
Avi Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 7 | struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu, |
| 8 | u32 function, u32 index); |
Borislav Petkov | 9c15bb1 | 2013-09-22 16:44:50 +0200 | [diff] [blame] | 9 | int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, |
| 10 | struct kvm_cpuid_entry2 __user *entries, |
| 11 | unsigned int type); |
Avi Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 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); |
Avi Kivity | 62046e5 | 2012-06-07 14:07:48 +0300 | [diff] [blame] | 21 | void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); |
Avi Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 22 | |
Eugene Korenevsky | 5a4f55c | 2015-03-29 23:56:12 +0300 | [diff] [blame] | 23 | int cpuid_query_maxphyaddr(struct kvm_vcpu *vcpu); |
| 24 | |
| 25 | static inline int cpuid_maxphyaddr(struct kvm_vcpu *vcpu) |
| 26 | { |
| 27 | return vcpu->arch.maxphyaddr; |
| 28 | } |
Avi Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 29 | |
| 30 | static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu) |
| 31 | { |
| 32 | struct kvm_cpuid_entry2 *best; |
| 33 | |
Petr Matousek | 6d1068b | 2012-11-06 19:24:07 +0100 | [diff] [blame] | 34 | if (!static_cpu_has(X86_FEATURE_XSAVE)) |
Joe Perches | 1d804d0 | 2015-03-30 16:46:09 -0700 | [diff] [blame] | 35 | return false; |
Petr Matousek | 6d1068b | 2012-11-06 19:24:07 +0100 | [diff] [blame] | 36 | |
Avi Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 37 | best = kvm_find_cpuid_entry(vcpu, 1, 0); |
| 38 | return best && (best->ecx & bit(X86_FEATURE_XSAVE)); |
| 39 | } |
| 40 | |
Will Auld | ba90463 | 2012-11-29 12:42:50 -0800 | [diff] [blame] | 41 | static 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 Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 49 | static 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 Wu | 97ec8c0 | 2014-04-01 17:46:34 +0800 | [diff] [blame] | 57 | static 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 Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 65 | static 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 Bonzini | 660a5d5 | 2015-05-05 11:50:23 +0200 | [diff] [blame] | 73 | static 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 Ostrovsky | 2b036c6 | 2012-01-09 14:00:35 -0500 | [diff] [blame] | 81 | static 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, Junjie | ad756a1 | 2012-07-02 01:18:48 +0000 | [diff] [blame] | 89 | static 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 Kiszka | 58cb628 | 2014-01-24 16:48:44 +0100 | [diff] [blame] | 97 | static 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 Bonzini | a0c0feb5 | 2014-09-02 13:24:12 +0200 | [diff] [blame] | 105 | static 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 Amit | 5f7dde7 | 2014-05-07 15:32:50 +0300 | [diff] [blame] | 113 | static 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 Amit | 6f43ed0 | 2014-07-15 17:37:46 +0300 | [diff] [blame] | 120 | |
| 121 | static 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 Li | c447e76 | 2015-05-21 04:41:25 +0800 | [diff] [blame] | 128 | |
| 129 | static 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 | } |
Xiao Guangrong | 8b3e34e | 2015-09-09 14:05:51 +0800 | [diff] [blame] | 136 | |
| 137 | static inline bool guest_cpuid_has_pcommit(struct kvm_vcpu *vcpu) |
| 138 | { |
| 139 | struct kvm_cpuid_entry2 *best; |
| 140 | |
| 141 | best = kvm_find_cpuid_entry(vcpu, 7, 0); |
| 142 | return best && (best->ebx & bit(X86_FEATURE_PCOMMIT)); |
| 143 | } |
Xiao Guangrong | 1cea0ce | 2015-09-09 14:05:57 +0800 | [diff] [blame^] | 144 | |
| 145 | static inline bool guest_cpuid_has_rdtscp(struct kvm_vcpu *vcpu) |
| 146 | { |
| 147 | struct kvm_cpuid_entry2 *best; |
| 148 | |
| 149 | best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0); |
| 150 | return best && (best->edx & bit(X86_FEATURE_RDTSCP)); |
| 151 | } |
Avi Kivity | 00b27a3 | 2011-11-23 16:30:32 +0200 | [diff] [blame] | 152 | #endif |