Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp524351imu; Wed, 9 Jan 2019 01:45:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN7J+GB70AAWe1h/Kv5ZZcdve5DcbpfPbmDaawZYN7wd023OCwFUd6s5mrMe8pG40JsSQWBI X-Received: by 2002:a62:b24a:: with SMTP id x71mr5406911pfe.148.1547027135919; Wed, 09 Jan 2019 01:45:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547027135; cv=none; d=google.com; s=arc-20160816; b=guq/p6TyBsLmY1gnqmqFOKtSyBNl3cAh7CYF/KeJQJ6K4uzBBScKmRljmPxBo2g/t9 UN8222ZzWx/de37xJyVtnaVJhl6RWu4mTP/CxTXieNrfCmF7AmED3BprCwaqYO60l1aN /j3HeauJiHQS19pwY4ey8nBITeWgXr8pUrnBm/lXvt15JUyOdMsF+upYpBYS4smwpoCn //SU3+rnO6xVzLAmqaz0+qZ2rjkeaM2n6UwwRltWQr92UpLK+Ct3hAl/BbX4gOadurAH R8CRGZba4O1A29+Yr6uW67JfQBcr/PH/ahr1zvQu4wIQzx9ezVYF9xI/46JtBGiRvPSK 3/Vw== 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; bh=+OgXWLij7az0MI49TyIaysFnRbjS1cbJdhcZ2MrJgNU=; b=cSNw9XZWbRYAPFFodTBTXKogCRMMSEcptldD3Y5JWbs6ftk/olMFp00Ch7bfQnNNzs zZEtozBMvnNq2UJCObdpXoS+mBPgmleTM/mpNOziHoCTJ0O1SUaXJRlj/NIYxsEpih4M HU5TN6lpzGNTzQXI7i5Wy1oljFaPdsKoiiUYVqpn1uMyR2RbEUWv/TYKselhIkmYHuBO vRvcRD1CNR2fhy9UjBgrF1PqYKc8+j1r462U80S58Gn7Cync3a0kEVCM1rOPQ2jtgvGJ zMWG+CovS7oZbJS/9PGLyL32+Iq0Q2+beqzOeeVq5Dtvl1pOonUG4gz5FuwW/Dbr9U39 jLyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b="H/OnXORX"; 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 s2si11652195pgr.285.2019.01.09.01.45.20; Wed, 09 Jan 2019 01:45:35 -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="H/OnXORX"; 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 S1730588AbfAIJmw (ORCPT + 99 others); Wed, 9 Jan 2019 04:42:52 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:53731 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730113AbfAIJma (ORCPT ); Wed, 9 Jan 2019 04:42:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1547026949; x=1578562949; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=+OgXWLij7az0MI49TyIaysFnRbjS1cbJdhcZ2MrJgNU=; b=H/OnXORXG6HPuoaFq8UxrhjRMAcuQaSEutKi9ysm6MDusHdZegUJkURh ohS7jnrYlMzrCnWsTfn2v3BmaHdFAeLy1Fx4HGXTLbtT92Lsb32PBtfd8 3CCojkHVse8IwO0CrkbtlTlMK52CTOjtBugVNnvXkWdE5taJR7VQPtPtb Y=; X-IronPort-AV: E=Sophos;i="5.56,253,1539648000"; d="scan'208";a="380876339" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 09 Jan 2019 09:42:28 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id x099gKoT101493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 9 Jan 2019 09:42:22 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 x099gKS4031323; Wed, 9 Jan 2019 10:42:20 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id x099gKT9031322; Wed, 9 Jan 2019 10:42:20 +0100 From: KarimAllah Ahmed To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com Cc: KarimAllah Ahmed Subject: [PATCH v5 08/13] KVM/nVMX: Use kvm_vcpu_map when mapping the posted interrupt descriptor table Date: Wed, 9 Jan 2019 10:42:08 +0100 Message-Id: <1547026933-31226-9-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547026933-31226-1-git-send-email-karahmed@amazon.de> References: <1547026933-31226-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 Use kvm_vcpu_map when mapping the posted interrupt descriptor table since using kvm_vcpu_gpa_to_page() and kmap() will only work for guest memory that has a "struct page". One additional semantic change is that the virtual host mapping lifecycle has changed a bit. It now has the same lifetime of the pinning of the interrupt descriptor table page on the host side. Signed-off-by: KarimAllah Ahmed --- v4 -> v5: - unmap with dirty flag v1 -> v2: - Do not change the lifecycle of the mapping (pbonzini) --- arch/x86/kvm/vmx/nested.c | 43 ++++++++++++------------------------------- arch/x86/kvm/vmx/vmx.h | 2 +- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index dcff99d..b4230ce 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -230,12 +230,8 @@ static void free_nested(struct kvm_vcpu *vcpu) vmx->nested.apic_access_page = NULL; } kvm_vcpu_unmap(&vmx->nested.virtual_apic_map, true); - if (vmx->nested.pi_desc_page) { - kunmap(vmx->nested.pi_desc_page); - kvm_release_page_dirty(vmx->nested.pi_desc_page); - vmx->nested.pi_desc_page = NULL; - vmx->nested.pi_desc = NULL; - } + kvm_vcpu_unmap(&vmx->nested.pi_desc_map, true); + vmx->nested.pi_desc = NULL; kvm_mmu_free_roots(vcpu, &vcpu->arch.guest_mmu, KVM_MMU_ROOTS_ALL); @@ -2868,26 +2864,15 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu) } if (nested_cpu_has_posted_intr(vmcs12)) { - if (vmx->nested.pi_desc_page) { /* shouldn't happen */ - kunmap(vmx->nested.pi_desc_page); - kvm_release_page_dirty(vmx->nested.pi_desc_page); - vmx->nested.pi_desc_page = NULL; - vmx->nested.pi_desc = NULL; - vmcs_write64(POSTED_INTR_DESC_ADDR, -1ull); + map = &vmx->nested.pi_desc_map; + + if (!kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->posted_intr_desc_addr), map)) { + vmx->nested.pi_desc = + (struct pi_desc *)(((void *)map->hva) + + offset_in_page(vmcs12->posted_intr_desc_addr)); + vmcs_write64(POSTED_INTR_DESC_ADDR, + pfn_to_hpa(map->pfn) + offset_in_page(vmcs12->posted_intr_desc_addr)); } - page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->posted_intr_desc_addr); - if (is_error_page(page)) - return; - vmx->nested.pi_desc_page = page; - vmx->nested.pi_desc = kmap(vmx->nested.pi_desc_page); - vmx->nested.pi_desc = - (struct pi_desc *)((void *)vmx->nested.pi_desc + - (unsigned long)(vmcs12->posted_intr_desc_addr & - (PAGE_SIZE - 1))); - vmcs_write64(POSTED_INTR_DESC_ADDR, - page_to_phys(vmx->nested.pi_desc_page) + - (unsigned long)(vmcs12->posted_intr_desc_addr & - (PAGE_SIZE - 1))); } if (nested_vmx_prepare_msr_bitmap(vcpu, vmcs12)) vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL, @@ -3911,12 +3896,8 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, vmx->nested.apic_access_page = NULL; } kvm_vcpu_unmap(&vmx->nested.virtual_apic_map, true); - if (vmx->nested.pi_desc_page) { - kunmap(vmx->nested.pi_desc_page); - kvm_release_page_dirty(vmx->nested.pi_desc_page); - vmx->nested.pi_desc_page = NULL; - vmx->nested.pi_desc = NULL; - } + kvm_vcpu_unmap(&vmx->nested.pi_desc_map, true); + vmx->nested.pi_desc = NULL; /* * We are now running in L2, mmu_notifier will force to reload the diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index f618f52..bd04725 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -143,7 +143,7 @@ struct nested_vmx { */ struct page *apic_access_page; struct kvm_host_map virtual_apic_map; - struct page *pi_desc_page; + struct kvm_host_map pi_desc_map; struct kvm_host_map msr_bitmap_map; -- 2.7.4