Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp65301ima; Thu, 31 Jan 2019 12:29:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN75HsCqdPvZh4nohPoTSRKh1xROfDmhEa84r9F/hwzVwnR4Fk2pB7iHG/g2d+goCTop6N9T X-Received: by 2002:a63:e74b:: with SMTP id j11mr33053658pgk.397.1548966544296; Thu, 31 Jan 2019 12:29:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548966544; cv=none; d=google.com; s=arc-20160816; b=jMJ43oCM7XaoCgLtOsxCTtgeM/NJs+kD579xSofUw8Fq2nclRFu08UieGnS+/1C8rY B3h/9G8wnR7rZ6M8YfxfabiDJSJeUV3Sy2f4Jw0ULlcbmyIaqnlSUf4mHt7Pcnjeg1qN O6nVl7vl3+tbJTnu13pZKipQLVMRFSGoR+YtYrkSHoVBGgqhCjohIR3r1hQqDIGWYq4B OElKeuyGLezIe1WlloQpzNz/2wk9TTL3pfGfYQQQm/NTxBQcOOx55Lc+VUkksIwXfIP8 GWummpxQ2p8nbA4eAvre4wKvKwA9VpJhMfW6JdYK8pti8OACpGO8Mn6vo3UC9dl7K3LS 7NBg== 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=mllvbMuI+hb6yPgBVYrhWq18u7HhXUYfrIcLxoipIIY=; b=qkdubhaPjKg0blTLBzIfU1mLtvEQDCqdIIRoYc5uFJnm4b07wWEComtOuhWDshrg0I lP+5kn7pFYd/Rlkofx5gE7oL118pW+mo6r2OOvTWNz+WpEIFtL03GULuM9soaMGsvk/S wcM9gvHn8rQ6z+W4+AdJjL/vwRL0HlP6i2l9DbYIwS3Y82Gkvgj5ozJ1LWmtvwplO4Yp afpjvG5NF3gFPoylW2d5lVty75AzKNZ5AV93XhxBzjCn9UCk2jucF3uAjKQGMQ52CQWc E6SP2wNl3aNBVIl9bNOkWhxvOfKYfW7uTN4Gw9IKBrQi/6bjsYGCoYysLMTkomV/BR1t xZrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=g2EfUyJs; 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 l186si4899181pge.205.2019.01.31.12.28.49; Thu, 31 Jan 2019 12:29: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=g2EfUyJs; 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 S1728930AbfAaU2J (ORCPT + 99 others); Thu, 31 Jan 2019 15:28:09 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:45295 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728177AbfAaU1F (ORCPT ); Thu, 31 Jan 2019 15:27:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1548966424; x=1580502424; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=mllvbMuI+hb6yPgBVYrhWq18u7HhXUYfrIcLxoipIIY=; b=g2EfUyJsLL4a/CQds3QPnRNUDG1cifjcTrobHlUd8fqg352zxLIFi2fN NEB3eiSPdOYwV8pWVNdpIujIecAzD0P+oexU4ARJZEOtloi1EjZdzXq+j DBnSvVQsjDti6XeggkhYKv13jlKa9xnqYJNniAK04BbQm/Ly6lDsMbC80 s=; X-IronPort-AV: E=Sophos;i="5.56,545,1539648000"; d="scan'208";a="780024417" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2c-c6afef2e.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 31 Jan 2019 20:27:04 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2c-c6afef2e.us-west-2.amazon.com (Postfix) with ESMTPS id 92CF4A2246; Thu, 31 Jan 2019 20:27:03 +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 x0VKR16Z028991; Thu, 31 Jan 2019 21:27:01 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id x0VKR0Ae028990; Thu, 31 Jan 2019 21:27:00 +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 08/14] KVM/nVMX: Use kvm_vcpu_map when mapping the posted interrupt descriptor table Date: Thu, 31 Jan 2019 21:24:38 +0100 Message-Id: <1548966284-28642-9-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 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 Reviewed-by: Konrad Rzeszutek Wilk --- 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 31b352c..53b1063 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(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); - vmx->nested.pi_desc_page = NULL; - vmx->nested.pi_desc = NULL; - } + kvm_vcpu_unmap(vcpu, &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(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); - vmx->nested.pi_desc_page = NULL; - vmx->nested.pi_desc = NULL; - } + kvm_vcpu_unmap(vcpu, &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