* [PATCH] KVM/X86: Check input sreg values before loading vcpu
@ 2018-02-27 6:57 Tianyu Lan
2018-03-08 16:15 ` rkrcmar
0 siblings, 1 reply; 3+ messages in thread
From: Tianyu Lan @ 2018-02-27 6:57 UTC (permalink / raw)
Cc: Tianyu Lan, pbonzini, rkrcmar, tglx, mingo, hpa, x86, kvm, linux-kernel
From: Lan Tianyu <Tianyu.Lan@microsoft.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@microsoft.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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM/X86: Check input sreg values before loading vcpu
2018-02-27 6:57 [PATCH] KVM/X86: Check input sreg values before loading vcpu Tianyu Lan
@ 2018-03-08 16:15 ` rkrcmar
2018-03-09 7:24 ` Tianyu Lan
0 siblings, 1 reply; 3+ messages in thread
From: rkrcmar @ 2018-03-08 16:15 UTC (permalink / raw)
To: Tianyu Lan; +Cc: pbonzini, tglx, mingo, hpa, x86, kvm, linux-kernel
2018-02-27 06:57+0000, Tianyu Lan:
> From: Lan Tianyu <Tianyu.Lan@microsoft.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@microsoft.com>
> ---
Patch "KVM: x86: KVM_CAP_SYNC_REGS" made significant changes to the
sregs setter, so the patch cannot be applied in current form.
I think that moving the X86_CR4_OSXSAVE check to guest_cpuid_has still
makes sense, but avoiding the vcpu_load/put would produce worse code
elsewhere and avoiding the load/put is not critical as any error is
probably going to be the end for this VM.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM/X86: Check input sreg values before loading vcpu
2018-03-08 16:15 ` rkrcmar
@ 2018-03-09 7:24 ` Tianyu Lan
0 siblings, 0 replies; 3+ messages in thread
From: Tianyu Lan @ 2018-03-09 7:24 UTC (permalink / raw)
To: rkrcmar, Tianyu Lan; +Cc: pbonzini, tglx, mingo, hpa, x86, kvm, linux-kernel
Hi Radim:
Thanks for your review.
On 3/9/2018 12:15 AM, rkrcmar@redhat.com wrote:
> 2018-02-27 06:57+0000, Tianyu Lan:
>> From: Lan Tianyu <Tianyu.Lan@microsoft.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@microsoft.com>
>> ---
>
> Patch "KVM: x86: KVM_CAP_SYNC_REGS" made significant changes to the
> sregs setter, so the patch cannot be applied in current form.
>
> I think that moving the X86_CR4_OSXSAVE check to guest_cpuid_has still
> makes sense, but avoiding the vcpu_load/put would produce worse code
> elsewhere and avoiding the load/put is not critical as any error is
> probably going to be the end for this VM.
>
OK. I will update patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-09 7:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-27 6:57 [PATCH] KVM/X86: Check input sreg values before loading vcpu Tianyu Lan
2018-03-08 16:15 ` rkrcmar
2018-03-09 7:24 ` Tianyu Lan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.