aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <joro@8bytes.org>2015-10-14 09:10:54 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2015-10-16 04:32:17 -0400
commit6092d3d3e6db983048469d424a8f2221915a8dd3 (patch)
treeba6b6b6bc3fc5359267dfe695d7fcd13420b2f22
parent951f9fd74f2d826fff1d84a8ec34b491517dc15d (diff)
kvm: svm: Only propagate next_rip when guest supports it
Currently we always write the next_rip of the shadow vmcb to the guests vmcb when we emulate a vmexit. This could confuse the guest when its cpuid indicated no support for the next_rip feature. Fix this by only propagating next_rip if the guest actually supports it. Cc: Bandan Das <bsd@redhat.com> Cc: Dirk Mueller <dmueller@suse.com> Tested-By: Dirk Mueller <dmueller@suse.com> Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/cpuid.h21
-rw-r--r--arch/x86/kvm/svm.c11
2 files changed, 31 insertions, 1 deletions
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index d434ee952b00..06332cb7e7d1 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -149,4 +149,25 @@ static inline bool guest_cpuid_has_rdtscp(struct kvm_vcpu *vcpu)
149 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0); 149 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
150 return best && (best->edx & bit(X86_FEATURE_RDTSCP)); 150 return best && (best->edx & bit(X86_FEATURE_RDTSCP));
151} 151}
152
153/*
154 * NRIPS is provided through cpuidfn 0x8000000a.edx bit 3
155 */
156#define BIT_NRIPS 3
157
158static inline bool guest_cpuid_has_nrips(struct kvm_vcpu *vcpu)
159{
160 struct kvm_cpuid_entry2 *best;
161
162 best = kvm_find_cpuid_entry(vcpu, 0x8000000a, 0);
163
164 /*
165 * NRIPS is a scattered cpuid feature, so we can't use
166 * X86_FEATURE_NRIPS here (X86_FEATURE_NRIPS would be bit
167 * position 8, not 3).
168 */
169 return best && (best->edx & bit(BIT_NRIPS));
170}
171#undef BIT_NRIPS
172
152#endif 173#endif
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 54a86183e5d3..cd8659cfc632 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -159,6 +159,9 @@ struct vcpu_svm {
159 u32 apf_reason; 159 u32 apf_reason;
160 160
161 u64 tsc_ratio; 161 u64 tsc_ratio;
162
163 /* cached guest cpuid flags for faster access */
164 bool nrips_enabled : 1;
162}; 165};
163 166
164static DEFINE_PER_CPU(u64, current_tsc_ratio); 167static DEFINE_PER_CPU(u64, current_tsc_ratio);
@@ -2365,7 +2368,9 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
2365 nested_vmcb->control.exit_info_2 = vmcb->control.exit_info_2; 2368 nested_vmcb->control.exit_info_2 = vmcb->control.exit_info_2;
2366 nested_vmcb->control.exit_int_info = vmcb->control.exit_int_info; 2369 nested_vmcb->control.exit_int_info = vmcb->control.exit_int_info;
2367 nested_vmcb->control.exit_int_info_err = vmcb->control.exit_int_info_err; 2370 nested_vmcb->control.exit_int_info_err = vmcb->control.exit_int_info_err;
2368 nested_vmcb->control.next_rip = vmcb->control.next_rip; 2371
2372 if (svm->nrips_enabled)
2373 nested_vmcb->control.next_rip = vmcb->control.next_rip;
2369 2374
2370 /* 2375 /*
2371 * If we emulate a VMRUN/#VMEXIT in the same host #vmexit cycle we have 2376 * If we emulate a VMRUN/#VMEXIT in the same host #vmexit cycle we have
@@ -4085,6 +4090,10 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
4085 4090
4086static void svm_cpuid_update(struct kvm_vcpu *vcpu) 4091static void svm_cpuid_update(struct kvm_vcpu *vcpu)
4087{ 4092{
4093 struct vcpu_svm *svm = to_svm(vcpu);
4094
4095 /* Update nrips enabled cache */
4096 svm->nrips_enabled = !!guest_cpuid_has_nrips(&svm->vcpu);
4088} 4097}
4089 4098
4090static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry) 4099static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)