From patchwork Tue Sep 15 10:30:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 7183651 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7265DBEEC1 for ; Tue, 15 Sep 2015 10:31:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A2D31206DD for ; Tue, 15 Sep 2015 10:31:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B87F6206CC for ; Tue, 15 Sep 2015 10:31:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753126AbbIOKbE (ORCPT ); Tue, 15 Sep 2015 06:31:04 -0400 Received: from blu004-omc1s11.hotmail.com ([65.55.116.22]:55544 "EHLO BLU004-OMC1S11.hotmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753115AbbIOKbA (ORCPT ); Tue, 15 Sep 2015 06:31:00 -0400 Received: from BLU436-SMTP253 ([65.55.116.7]) by BLU004-OMC1S11.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 15 Sep 2015 03:30:59 -0700 X-TMN: [+BxBMKLfeMui2u8i53Eya3qunIAtIsEv] X-Originating-Email: [wanpeng.li@hotmail.com] Message-ID: From: Wanpeng Li To: Paolo Bonzini CC: Jan Kiszka , Bandan Das , Wincy Van , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v2 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid Date: Tue, 15 Sep 2015 18:30:33 +0800 X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442313034-14243-1-git-send-email-wanpeng.li@hotmail.com> References: <1442313034-14243-1-git-send-email-wanpeng.li@hotmail.com> X-OriginalArrivalTime: 15 Sep 2015 10:30:58.0324 (UTC) FILETIME=[9C350D40:01D0EFA1] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enhance allocate/free_vid to handle shadow vpid. Suggested-by: Wincy Van Signed-off-by: Wanpeng Li --- arch/x86/kvm/vmx.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index da1590e..bd07d88 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -424,6 +424,8 @@ struct nested_vmx { /* to migrate it to L2 if VM_ENTRY_LOAD_DEBUG_CONTROLS is off */ u64 vmcs01_debugctl; + u16 vpid02; + u32 nested_vmx_procbased_ctls_low; u32 nested_vmx_procbased_ctls_high; u32 nested_vmx_true_procbased_ctls_low; @@ -4155,18 +4157,29 @@ static int alloc_identity_pagetable(struct kvm *kvm) return r; } -static void allocate_vpid(struct vcpu_vmx *vmx) +static void allocate_vpid(struct vcpu_vmx *vmx, bool nested) { int vpid; - vmx->vpid = 0; if (!enable_vpid) return; + if (!nested) + vmx->vpid = 0; + else + vmx->nested.vpid02 = 0; spin_lock(&vmx_vpid_lock); - vpid = find_first_zero_bit(vmx_vpid_bitmap, VMX_NR_VPIDS); - if (vpid < VMX_NR_VPIDS) { + if (!nested) { + vpid = find_first_zero_bit(vmx_vpid_bitmap, VMX_NR_VPIDS); + if (vpid < VMX_NR_VPIDS) { vmx->vpid = vpid; __set_bit(vpid, vmx_vpid_bitmap); + } + } else { + vpid = find_first_zero_bit(vmx_vpid_bitmap, VMX_NR_VPIDS); + if (vpid < VMX_NR_VPIDS) { + vmx->nested.vpid02 = vpid; + __set_bit(vpid, vmx_vpid_bitmap); + } } spin_unlock(&vmx_vpid_lock); } @@ -4178,6 +4191,12 @@ static void free_vpid(struct vcpu_vmx *vmx) spin_lock(&vmx_vpid_lock); if (vmx->vpid != 0) __clear_bit(vmx->vpid, vmx_vpid_bitmap); + if (!nested) { + spin_unlock(&vmx_vpid_lock); + return; + } + if (vmx->nested.vpid02) + __clear_bit(vmx->nested.vpid02, vmx_vpid_bitmap); spin_unlock(&vmx_vpid_lock); } @@ -8509,7 +8528,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) if (!vmx) return ERR_PTR(-ENOMEM); - allocate_vpid(vmx); + allocate_vpid(vmx, false); err = kvm_vcpu_init(&vmx->vcpu, kvm, id); if (err) @@ -8557,8 +8576,10 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) goto free_vmcs; } - if (nested) + if (nested) { nested_vmx_setup_ctls_msrs(vmx); + allocate_vpid(vmx, true); + } vmx->nested.posted_intr_nv = -1; vmx->nested.current_vmptr = -1ull;