From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753317AbbIWIji (ORCPT ); Wed, 23 Sep 2015 04:39:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44944 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751723AbbIWIjh (ORCPT ); Wed, 23 Sep 2015 04:39:37 -0400 Subject: Re: [PATCH] KVM: nVMX: emulate the INVVPID instruction To: Wanpeng Li References: Cc: Jan Kiszka , Bandan Das , Wincy Van , kvm@vger.kernel.org, linux-kernel@vger.kernel.org From: Paolo Bonzini X-Enigmail-Draft-Status: N1110 Message-ID: <56026541.7030000@redhat.com> Date: Wed, 23 Sep 2015 10:39:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/09/2015 09:59, Wanpeng Li wrote: > Add the INVVPID instruction emulation. > > Reviewed-by: Wincy Van > Signed-off-by: Wanpeng Li > --- > arch/x86/include/asm/vmx.h | 1 + > arch/x86/kvm/vmx.c | 23 ++++++++++++++++++++++- > 2 files changed, 23 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h > index d25f32a..69f3d71 100644 > --- a/arch/x86/include/asm/vmx.h > +++ b/arch/x86/include/asm/vmx.h > @@ -397,6 +397,7 @@ enum vmcs_field { > #define IDENTITY_PAGETABLE_PRIVATE_MEMSLOT (KVM_USER_MEM_SLOTS + 2) > > #define VMX_NR_VPIDS (1 << 16) > +#define VMX_VPID_EXTENT_INDIVIDUAL_ADDR 0 > #define VMX_VPID_EXTENT_SINGLE_CONTEXT 1 > #define VMX_VPID_EXTENT_ALL_CONTEXT 2 > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 6ad991a..794c529 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -7189,7 +7189,28 @@ static int handle_invept(struct kvm_vcpu *vcpu) > > static int handle_invvpid(struct kvm_vcpu *vcpu) > { > - kvm_queue_exception(vcpu, UD_VECTOR); > + u32 vmx_instruction_info; > + unsigned long type; > + > + if (!nested_vmx_check_permission(vcpu)) > + return 1; > + > + vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); > + type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf); > + > + switch (type) { > + case VMX_VPID_EXTENT_INDIVIDUAL_ADDR: > + case VMX_VPID_EXTENT_SINGLE_CONTEXT: > + case VMX_VPID_EXTENT_ALL_CONTEXT: > + vmx_flush_tlb(vcpu); > + nested_vmx_succeed(vcpu); > + break; > + default: > + nested_vmx_failInvalid(vcpu); > + break; > + } > + > + skip_emulated_instruction(vcpu); > return 1; > } > > This is not enough. You need to add a VPID argument to vpid_sync_vcpu_single, and inline vmx_flush_tlb in handle_invvpid so that it can use the new VPID argument of vpid_sync_vcpu_single. Note that the "all context" variant can be mapped to vpid_sync_vcpu_single with vpid02 as the argument (a nice side effect of your vpid02 design). However, I have applied the patch to kvm/queue. Please send the changes separately, and I will squash them in the existing VPID patch. Paolo