[PATCH v2 2/7] kvm: x86: Extract kvm_xcr0_update_cpuid() from kvm_update_cpuid_runtime()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



And let __kvm_set_xcr() call kvm_xcr0_update_cpuid() instead of whole
kvm_update_cpuid_runtime()

Signed-off-by: Robert Hoo <robert.hu@xxxxxxxxxxxxxxx>
---
 arch/x86/kvm/cpuid.c | 22 ++++++++++++++++++++++
 arch/x86/kvm/cpuid.h |  2 ++
 arch/x86/kvm/x86.c   |  2 +-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index b6dd4ee..6d5cd03 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -87,6 +87,28 @@ void kvm_apic_base_update_cpuid(struct kvm_vcpu *vcpu, bool set)
 	guest_cpuid_change(vcpu, 1, 0, X86_FEATURE_APIC, set);
 }
 
+
+void kvm_xcr0_update_cpuid(struct kvm_vcpu *vcpu)
+{
+	struct kvm_cpuid_entry2 *e;
+
+	e = kvm_find_cpuid_entry(vcpu, 0xD, 0);
+	if (!e) {
+		vcpu->arch.guest_supported_xcr0 = 0;
+	} else {
+		vcpu->arch.guest_supported_xcr0 =
+			(e->eax | ((u64)e->edx << 32)) & supported_xcr0;
+		e->ebx = xstate_required_size(vcpu->arch.xcr0, false);
+	}
+
+	e = kvm_find_cpuid_entry(vcpu, 0xD, 1);
+	if (!e)
+		return;
+	if (cpuid_entry_has(e, X86_FEATURE_XSAVES) ||
+	    cpuid_entry_has(e, X86_FEATURE_XSAVEC))
+		e->ebx = xstate_required_size(vcpu->arch.xcr0, true);
+}
+
 void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
 {
 	struct kvm_cpuid_entry2 *best;
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index ef4cb9c..845544e 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -10,6 +10,8 @@
 void kvm_set_cpu_caps(void);
 
 void kvm_apic_base_update_cpuid(struct kvm_vcpu *vcpu, bool set);
+void kvm_xcr0_update_cpuid(struct kvm_vcpu *vcpu);
+
 void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu);
 struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
 					      u32 function, u32 index);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 58fa354..cd41bec 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -944,7 +944,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
 	vcpu->arch.xcr0 = xcr0;
 
 	if ((xcr0 ^ old_xcr0) & XFEATURE_MASK_EXTEND)
-		kvm_update_cpuid_runtime(vcpu);
+		kvm_xcr0_update_cpuid(vcpu);
 	return 0;
 }
 
-- 
1.8.3.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux