Received: by 10.223.185.116 with SMTP id b49csp1049098wrg; Wed, 21 Feb 2018 11:11:04 -0800 (PST) X-Google-Smtp-Source: AH8x226Kb56qVIVpiUOTF5I/SzyyBx0nAYV4Mn8sLqInT8pfIY7KnfeNLbVNuyP8qA/drdxC04T2 X-Received: by 2002:a17:902:6b89:: with SMTP id p9-v6mr4085165plk.377.1519240264412; Wed, 21 Feb 2018 11:11:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519240264; cv=none; d=google.com; s=arc-20160816; b=xi1lHTAy0NhAM6VUUJkD+u9kUegLaajigrdGuzbmEp2YlW98Iy3g+pYX+uQIKV/yHr GXqY2XcgUvpeFocCDDk34k19MMiTLe0b2nqHpMKdkMySZgJ5oMj7afAgx+XBjb9KQGcQ 0+nCHyeQfdXu/Qu9sq64XHMTbjd5rspDwsDC41GNqkckStkPZG56ShLeHj16wiQalWnn lHaXWiM1yd23NbxfH2inD2SUVDHtYnjrWjtdb+r7r1EdSNLGqPjr8B0olF1xxSHbDdzz sSfLRXS9cJpkN9JN6247DoY7esvIH13JcruYI6Of78VIaeKM0YPoQitSKzUBQ4M0FGq/ OVew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=wZRg1KKIy3ShNibO0Ff1Pi/yG77fFkX1bpRYyR3iT04=; b=KAL5AZG70BZFkd+6O2s9zaP8fuFsWY7cGnWOvKSPaRv+zRw4HXzuBAD5NXjrI3EE7d nXc3YRZUVgMnDcTxp0szGws4E+VQGPfY8OQqbrxr2KyZNxTPGwc9HL/XC6vIiKESXi2h qtMQSqmGqsRlcxzuQXRHeFkMWUjVt6ru/kF0tS6h/3uA5t+sIwiSKVg/xbSefVRWx8iY MIwC1W/uSLoOgbThu9hnfpYjiiwsgHwXgBLWySu7szY5JtXyaGgfPyxqBOKyoliWtQYs X2gZHtox6PAUvjr8GjXOMFifMzdGIBJgIN//qmHlJxSHcCPTuZdDGGkeVDmqiaT8pZm1 luXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=XsF6meCT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s12si244348pgr.762.2018.02.21.11.10.50; Wed, 21 Feb 2018 11:11:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=XsF6meCT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936526AbeBURr4 (ORCPT + 99 others); Wed, 21 Feb 2018 12:47:56 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:11223 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935683AbeBURrx (ORCPT ); Wed, 21 Feb 2018 12:47:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1519235273; x=1550771273; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=wZRg1KKIy3ShNibO0Ff1Pi/yG77fFkX1bpRYyR3iT04=; b=XsF6meCTvbYi4MtW/aoiyViKr5AhQdOGbZI8ji50eEiqTYrVNCfPvNIh tWthL+H4XSgCd7cNA/0Nr6ralCm6tjKSKtxT1YeS8JuCxiIHm02pCcIkW jQHkQ8To+99HN9cOiK+w13PcqTb72EFsQpokQPBhV9svoc63eMIMciilK M=; X-IronPort-AV: E=Sophos;i="5.47,375,1515456000"; d="scan'208";a="723871775" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1d-5dd976cd.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 21 Feb 2018 17:47:49 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (iad1-ws-svc-lb91-vlan3.amazon.com [10.0.103.150]) by email-inbound-relay-1d-5dd976cd.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w1LHlcFH035876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 21 Feb 2018 17:47:40 GMT Received: from u54e1ad5160425a4b64ea.ant.amazon.com (localhost [127.0.0.1]) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w1LHlbw5006674; Wed, 21 Feb 2018 18:47:37 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w1LHlbo7006673; Wed, 21 Feb 2018 18:47:37 +0100 From: KarimAllah Ahmed To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: hpa@zytor.com, jmattson@google.com, mingo@redhat.com, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, KarimAllah Ahmed Subject: [PATCH 06/10] KVM/nVMX: Use kvm_vcpu_map when mapping the virtual APIC page Date: Wed, 21 Feb 2018 18:47:17 +0100 Message-Id: <1519235241-6500-7-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519235241-6500-1-git-send-email-karahmed@amazon.de> References: <1519235241-6500-1-git-send-email-karahmed@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ... since using kvm_vcpu_gpa_to_page() and kmap() will only work for guest memory that has a "struct page". The life-cycle of the mapping also changes to avoid doing map and unmap on every single exit (which becomes very expesive once we use memremap). Now the memory is mapped and only unmapped when a new VMCS12 is loaded into the vCPU (or when the vCPU is freed!). Signed-off-by: KarimAllah Ahmed --- arch/x86/kvm/vmx.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 4bfef58..a700338 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -460,9 +460,8 @@ struct nested_vmx { * pointers, so we must keep them pinned while L2 runs. */ struct page *apic_access_page; - struct page *virtual_apic_page; + struct kvm_host_map virtual_apic_map; struct page *pi_desc_page; - struct kvm_host_map msr_bitmap_map; struct pi_desc *pi_desc; @@ -5444,10 +5443,9 @@ static void vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu) max_irr = find_last_bit((unsigned long *)vmx->nested.pi_desc->pir, 256); if (max_irr != 256) { - vapic_page = kmap(vmx->nested.virtual_apic_page); + vapic_page = vmx->nested.virtual_apic_map.kaddr; __kvm_apic_update_irr(vmx->nested.pi_desc->pir, vapic_page, &max_irr); - kunmap(vmx->nested.virtual_apic_page); status = vmcs_read16(GUEST_INTR_STATUS); if ((u8)max_irr > ((u8)status & 0xff)) { @@ -7667,6 +7665,7 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) vmx->nested.current_vmptr >> PAGE_SHIFT, vmx->nested.cached_vmcs12, 0, VMCS12_SIZE); + kvm_vcpu_unmap(&vmx->nested.virtual_apic_map); kvm_vcpu_unmap(&vmx->nested.msr_bitmap_map); vmx->nested.current_vmptr = -1ull; @@ -7698,10 +7697,7 @@ static void free_nested(struct vcpu_vmx *vmx) kvm_release_page_dirty(vmx->nested.apic_access_page); vmx->nested.apic_access_page = NULL; } - if (vmx->nested.virtual_apic_page) { - kvm_release_page_dirty(vmx->nested.virtual_apic_page); - vmx->nested.virtual_apic_page = NULL; - } + kvm_vcpu_unmap(&vmx->nested.virtual_apic_map); if (vmx->nested.pi_desc_page) { kunmap(vmx->nested.pi_desc_page); kvm_release_page_dirty(vmx->nested.pi_desc_page); @@ -10222,6 +10218,7 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu, static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { + struct kvm_host_map *map; struct vcpu_vmx *vmx = to_vmx(vcpu); struct page *page; u64 hpa; @@ -10260,11 +10257,7 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu, } if (nested_cpu_has(vmcs12, CPU_BASED_TPR_SHADOW)) { - if (vmx->nested.virtual_apic_page) { /* shouldn't happen */ - kvm_release_page_dirty(vmx->nested.virtual_apic_page); - vmx->nested.virtual_apic_page = NULL; - } - page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->virtual_apic_page_addr); + map = &vmx->nested.virtual_apic_map; /* * If translation failed, VM entry will fail because @@ -10279,11 +10272,9 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu, * control. But such a configuration is useless, so * let's keep the code simple. */ - if (!is_error_page(page)) { - vmx->nested.virtual_apic_page = page; - hpa = page_to_phys(vmx->nested.virtual_apic_page); - vmcs_write64(VIRTUAL_APIC_PAGE_ADDR, hpa); - } + + if (kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->virtual_apic_page_addr), map)) + vmcs_write64(VIRTUAL_APIC_PAGE_ADDR, gfn_to_gpa(map->pfn)); } if (nested_cpu_has_posted_intr(vmcs12)) { @@ -11902,10 +11893,6 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, kvm_release_page_dirty(vmx->nested.apic_access_page); vmx->nested.apic_access_page = NULL; } - if (vmx->nested.virtual_apic_page) { - kvm_release_page_dirty(vmx->nested.virtual_apic_page); - vmx->nested.virtual_apic_page = NULL; - } if (vmx->nested.pi_desc_page) { kunmap(vmx->nested.pi_desc_page); kvm_release_page_dirty(vmx->nested.pi_desc_page); -- 2.7.4