[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1519714664-2649-1-git-send-email-Tianyu.Lan@microsoft.com>
Date: Tue, 27 Feb 2018 06:57:59 +0000
From: Tianyu Lan <Tianyu.Lan@...rosoft.com>
To: unlisted-recipients:; (no To-header on input)
CC: Tianyu Lan <Tianyu.Lan@...rosoft.com>,
"pbonzini@...hat.com" <pbonzini@...hat.com>,
"rkrcmar@...hat.com" <rkrcmar@...hat.com>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"mingo@...hat.com" <mingo@...hat.com>,
"hpa@...or.com" <hpa@...or.com>, "x86@...nel.org" <x86@...nel.org>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] KVM/X86: Check input sreg values before loading vcpu
From: Lan Tianyu <Tianyu.Lan@...rosoft.com>
This patch is to check sreg value first and then load vcpu in order
to avoid redundant loading/putting vcpu.
Signed-off-by: Lan Tianyu <Tianyu.Lan@...rosoft.com>
---
arch/x86/kvm/x86.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c8a0b54..46da9ec 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7671,6 +7671,10 @@ EXPORT_SYMBOL_GPL(kvm_task_switch);
int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
{
+ if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
+ (sregs->cr4 & X86_CR4_OSXSAVE))
+ return -EINVAL;
+
if ((sregs->efer & EFER_LME) && (sregs->cr0 & X86_CR0_PG)) {
/*
* When EFER.LME and CR0.PG are set, the processor is in
@@ -7701,14 +7705,10 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
struct desc_ptr dt;
int ret = -EINVAL;
- vcpu_load(vcpu);
-
- if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
- (sregs->cr4 & X86_CR4_OSXSAVE))
- goto out;
-
if (kvm_valid_sregs(vcpu, sregs))
- goto out;
+ return ret;
+
+ vcpu_load(vcpu);
apic_base_msr.data = sregs->apic_base;
apic_base_msr.host_initiated = true;
--
2.7.4
Powered by blists - more mailing lists