From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yang Zhang Subject: Re: [PATCH] KVM: x86: no need to check CPL for XSETBV on VMX Date: Fri, 15 Apr 2016 18:37:23 +0800 Message-ID: <5710C463.4080308@gmail.com> References: <57104A23.4070405@gmail.com> <5710BE49.4000702@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit To: Paolo Bonzini , "kvm@vger.kernel.org" , "rkrcmar@redhat.com" Return-path: Received: from mail-pf0-f195.google.com ([209.85.192.195]:36405 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751010AbcDOKhd (ORCPT ); Fri, 15 Apr 2016 06:37:33 -0400 Received: by mail-pf0-f195.google.com with SMTP id p185so5528311pfb.3 for ; Fri, 15 Apr 2016 03:37:32 -0700 (PDT) In-Reply-To: <5710BE49.4000702@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 2016/4/15 18:11, Paolo Bonzini wrote: > > > On 15/04/2016 03:55, Yang Zhang wrote: >> The CPL check for XSETBV instruction is done by hardware on VMX. >> It only needs by SVM. > > I don't think this is performance-sensitive, hence it's simpler to keep > the code as simple as possible. For example, if one added XSETBV > support to the emulator, your patch would introduce a bug. In what case we need to decode XSETBV? > > Paolo > >> Signed-off-by: Yang Zhang >> --- >> arch/x86/kvm/svm.c | 4 +++- >> arch/x86/kvm/x86.c | 3 +-- >> 2 files changed, 4 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c >> index 31346a3..14680f5 100644 >> --- a/arch/x86/kvm/svm.c >> +++ b/arch/x86/kvm/svm.c >> @@ -2715,7 +2715,9 @@ static int xsetbv_interception(struct vcpu_svm *svm) >> u64 new_bv = kvm_read_edx_eax(&svm->vcpu); >> u32 index = kvm_register_read(&svm->vcpu, VCPU_REGS_RCX); >> >> - if (kvm_set_xcr(&svm->vcpu, index, new_bv) == 0) { >> + if (svm_get_cpl(&svm->vcpu) != 0) >> + kvm_inject_gp(&svm->vcpu, 0); >> + else if (kvm_set_xcr(&svm->vcpu, index, new_bv) == 0) { >> svm->next_rip = kvm_rip_read(&svm->vcpu) + 3; >> skip_emulated_instruction(&svm->vcpu); >> } >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index 8f57335..3cfc59f 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -709,8 +709,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 >> index, u64 xcr) >> >> int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) >> { >> - if (kvm_x86_ops->get_cpl(vcpu) != 0 || >> - __kvm_set_xcr(vcpu, index, xcr)) { >> + if (__kvm_set_xcr(vcpu, index, xcr)) { >> kvm_inject_gp(vcpu, 0); >> return 1; >> } -- best regards yang