Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp63807ima; Thu, 31 Jan 2019 12:27:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN6twOdiy2dP+7DHdUp8IK99RzOsd3lnHU6lLlKlxQkcU+cdvSYFmvjJJTjjrlIzmDeQNGUA X-Received: by 2002:a63:7e1a:: with SMTP id z26mr32006266pgc.216.1548966457586; Thu, 31 Jan 2019 12:27:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548966457; cv=none; d=google.com; s=arc-20160816; b=vuVOS6c4J3OSo6MZLp1XfJB7gcV9SnW1ClXRLqk9ZsvIKDX6ikfw81IGz3BjAIrUrp wU8ufWtt9tp4BPI+CK/Zhhsnn0kYVbDb0O53ZK6NFoWoTXBct/YSdI0+G9oNgSssrWcG ANAlWCsLnvnAsJ/QgL0j7PgpIZ2oU1fpbaKMEzKQv5kExdLjgEvz14iyfX/4sQrL7y0v dHFRjgK8wSb1mCZYk3iMLv5qdTjrolbs41L8W0+Ww2pKsy3iLI/lSwPP1Fz/uK+/2OCk b7y5m3rGGKC8UVa0HPFyAVQEaHqtb+E7YORV1QB+XADfnKl9d7PMb/i85TkKGMM+CgyP 3VlA== 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=QZVMhKVWbWjBs9t9fXnfD9E4/yA59hBZ75kOCaTDCc0=; b=iqp+OThEo/Eg5hIug+UmwKbLPpfBmJg3E1nbLE4Kc3ejy3o/h+EOERi9M4TxJbE1uk 9ChjCVQ6badihiMcrB2H1E9vzasamYCKQZCW5ipDCwyN1+Msb4L+sHnAl+eyLwUg9Oub i7kHD5tRxR+LAPn/5c7Opv6lrK9SD4LuC/5vPFXsaf28mpPAmmyXfUWzbJDQGC4yKolO X8rQ4fi2Bh9XXZPf0AzHzZh9+FBGmrQVXg6++rSr5QY6ObVnei7YCRjvg95W9JdyWYSY LmFSRDqdiGhsrv5QAZKEOjJK4bs3NYXzJjlJq0esir25iX5t9F9AdLS519SenR+aMr4i TGSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=db9VY9v1; 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 m11si5621148pla.436.2019.01.31.12.27.22; Thu, 31 Jan 2019 12:27:37 -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=db9VY9v1; 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 S1728352AbfAaU1I (ORCPT + 99 others); Thu, 31 Jan 2019 15:27:08 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:62606 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728191AbfAaU1G (ORCPT ); Thu, 31 Jan 2019 15:27:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1548966425; x=1580502425; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=QZVMhKVWbWjBs9t9fXnfD9E4/yA59hBZ75kOCaTDCc0=; b=db9VY9v1/Ope5aL8oXwm3QLyED+GGeAYcolPAtiaP4SlbrjxFcQaWhn+ HqQm3kdz7UmJnnXKmrqN9HDzXx5qxXu8IHPg4fOXaDpDVrPpJbhDiDBXR E9tvbgoU+PtUhmU5rcnYF6BuYTT2r4wJNQs+BTXAGJlz74w3uGv1k+uXx U=; X-IronPort-AV: E=Sophos;i="5.56,545,1539648000"; d="scan'208";a="656822804" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 31 Jan 2019 20:27:02 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com (Postfix) with ESMTPS id 34F5FA226F; Thu, 31 Jan 2019 20:27:02 +0000 (UTC) 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 x0VKQxfW028987; Thu, 31 Jan 2019 21:26:59 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id x0VKQxCk028976; Thu, 31 Jan 2019 21:26:59 +0100 From: KarimAllah Ahmed To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Paolo Bonzini Cc: KarimAllah Ahmed Subject: [PATCH v6 07/14] KVM/nVMX: Use kvm_vcpu_map when mapping the virtual APIC page Date: Thu, 31 Jan 2019 21:24:37 +0100 Message-Id: <1548966284-28642-8-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548966284-28642-1-git-send-email-karahmed@amazon.de> References: <1548966284-28642-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 virtual APIC page 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 virtual APIC page on the host side. Signed-off-by: KarimAllah Ahmed Reviewed-by: Konrad Rzeszutek Wilk --- v4 -> v5: - unmap with dirty flag v1 -> v2: - Do not change the lifecycle of the mapping (pbonzini) - Use pfn_to_hpa instead of gfn_to_gpa --- arch/x86/kvm/vmx/nested.c | 32 +++++++++++--------------------- arch/x86/kvm/vmx/vmx.c | 5 ++--- arch/x86/kvm/vmx/vmx.h | 2 +- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 1813211..31b352c 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -229,10 +229,7 @@ static void free_nested(struct kvm_vcpu *vcpu) 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(vcpu, &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); @@ -2817,6 +2814,7 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu) { struct vmcs12 *vmcs12 = get_vmcs12(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu); + struct kvm_host_map *map; struct page *page; u64 hpa; @@ -2849,11 +2847,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 @@ -2868,11 +2862,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, pfn_to_hpa(map->pfn)); + } if (nested_cpu_has_posted_intr(vmcs12)) { @@ -3279,11 +3271,12 @@ 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.hva; + if (!vapic_page) + return; + __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)) { status &= ~0xff; @@ -3917,10 +3910,7 @@ 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; - } + kvm_vcpu_unmap(vcpu, &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); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index a3da75a..ea9cffc 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3627,14 +3627,13 @@ static bool vmx_guest_apic_has_interrupt(struct kvm_vcpu *vcpu) if (WARN_ON_ONCE(!is_guest_mode(vcpu)) || !nested_cpu_has_vid(get_vmcs12(vcpu)) || - WARN_ON_ONCE(!vmx->nested.virtual_apic_page)) + WARN_ON_ONCE(!vmx->nested.virtual_apic_map.gfn)) return false; rvi = vmx_get_rvi(); - vapic_page = kmap(vmx->nested.virtual_apic_page); + vapic_page = vmx->nested.virtual_apic_map.hva; vppr = *((u32 *)(vapic_page + APIC_PROCPRI)); - kunmap(vmx->nested.virtual_apic_page); return ((rvi & 0xf0) > (vppr & 0xf0)); } diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 6fb69d8..f618f52 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -142,7 +142,7 @@ 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; -- 2.7.4