Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp64243ima; Thu, 31 Jan 2019 12:28:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN6DefK3lOZmes5UhWoL/d6RhzWyRA1NZwWGVOQovAAeYXFlOu0KThrAEY8XYud07c+oB49Q X-Received: by 2002:a17:902:7296:: with SMTP id d22mr37028599pll.265.1548966483014; Thu, 31 Jan 2019 12:28:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548966482; cv=none; d=google.com; s=arc-20160816; b=s8wMZfe73y3Wbac6DE4rn3C/S8mdDqKJJ7B7MtIHTFjywmS3DHFRe+IwZOvcYyR6bO 7GFdoUdFncfOBnvoH784Mue5MaDyrhtrM7mtVz4skFkWwQF5BsR+R2az/y2czj0hTkUD atlIB7wM20Z0qDCE/tCCElLBgSPZ/t8DZuPjw1yTaxaz86Ckj9LMHYcrKYnKWr7Yx4eI SH65dPWSyjoUzcn9uHWNZ/Bgt+I9MTJ7+i50Nj7khFpgK1ul/Tv/z20AfBack3SQWCOh wDlCBfwx560pATO4ZvaeAUMcXOnmm+F4TvWwlSuWiBQjWUiyBEYY9XdVPZl0JgJW0Cqu WWSA== 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=me9z6wzjmpjhEX2s1lpu2qPDIfP/6uqKoj24b307Bsw=; b=S99YYfXCNQpR65NN3ucwWRUTu4gPOLuMjedKuzU9pCPsqcIX6k0GderdHkfDXDQWI/ rv7yJyVKje5/2vzTWoAdHa9qJKnFC03/cbLZHbKCF5BtWzcdfFGkQfgw6iePzqvBqpU1 XNVrxDTCYAkn6KX1Ddu64uBXUakxpUTvx4CS6vhQdj6X0RsgBC8bIrH3mbbKZID6DHnx as3myc5pbjoa/eWsUSAAsCMCpnB6CmtQ4hIugqu0YfAAxoFj6oIPikfola6Yr2pJR+QI t1jhJCi3VftSmJQsUqNGcAkmBf9I3Ir7EsMG84hRUC99rPbGJ8F3n8m1PRwUS1T0u8P3 COmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=s8rwtno1; 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 10si5141428pgl.30.2019.01.31.12.27.47; Thu, 31 Jan 2019 12:28:02 -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=s8rwtno1; 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 S1728621AbfAaU1Q (ORCPT + 99 others); Thu, 31 Jan 2019 15:27:16 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:4315 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728510AbfAaU1O (ORCPT ); Thu, 31 Jan 2019 15:27:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1548966434; x=1580502434; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=me9z6wzjmpjhEX2s1lpu2qPDIfP/6uqKoj24b307Bsw=; b=s8rwtno15R2v+TQU8IKosQOWeWpZyu/F8/XlJbM4NICwixTUToNu5s2A ssxEloPsxzvi24xrjnOKHi4XlL75M4EjI2cBi5hP9Pt2uyUqbQYdegyPh p/qhcXUHzkc0/Fi9/ejIwi/8eY4MjTzaTunv1yTh3o2CZSS5eJfyKaQVQ 0=; X-IronPort-AV: E=Sophos;i="5.56,545,1539648000"; d="scan'208";a="656822847" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 31 Jan 2019 20:27:13 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (iad7-ws-svc-lb50-vlan3.amazon.com [10.0.93.214]) by email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x0VKR6Xs007883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 31 Jan 2019 20:27:08 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 x0VKR5b9029022; Thu, 31 Jan 2019 21:27:05 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id x0VKR4cU029015; Thu, 31 Jan 2019 21:27:04 +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 11/14] KVM/nVMX: Use kvm_vcpu_map for accessing the shadow VMCS Date: Thu, 31 Jan 2019 21:24:41 +0100 Message-Id: <1548966284-28642-12-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 for accessing the shadow VMCS since using kvm_vcpu_gpa_to_page() and kmap() will only work for guest memory that has a "struct page". Signed-off-by: KarimAllah Ahmed Reviewed-by: Konrad Rzessutek Wilk --- v4 -> v5: - unmap with dirty flag --- arch/x86/kvm/vmx/nested.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 53b1063..3c173b9 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -588,20 +588,20 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu, static void nested_cache_shadow_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { + struct kvm_host_map map; struct vmcs12 *shadow; - struct page *page; if (!nested_cpu_has_shadow_vmcs(vmcs12) || vmcs12->vmcs_link_pointer == -1ull) return; shadow = get_shadow_vmcs12(vcpu); - page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->vmcs_link_pointer); - memcpy(shadow, kmap(page), VMCS12_SIZE); + if (kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->vmcs_link_pointer), &map)) + return; - kunmap(page); - kvm_release_page_clean(page); + memcpy(shadow, map.hva, VMCS12_SIZE); + kvm_vcpu_unmap(vcpu, &map, false); } static void nested_flush_cached_shadow_vmcs12(struct kvm_vcpu *vcpu, @@ -2637,9 +2637,9 @@ static int nested_vmx_check_vmentry_prereqs(struct kvm_vcpu *vcpu, static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { - int r; - struct page *page; + int r = 0; struct vmcs12 *shadow; + struct kvm_host_map map; if (vmcs12->vmcs_link_pointer == -1ull) return 0; @@ -2647,17 +2647,16 @@ static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu, if (!page_address_valid(vcpu, vmcs12->vmcs_link_pointer)) return -EINVAL; - page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->vmcs_link_pointer); - if (is_error_page(page)) + if (kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->vmcs_link_pointer), &map)) return -EINVAL; - r = 0; - shadow = kmap(page); + shadow = map.hva; + if (shadow->hdr.revision_id != VMCS12_REVISION || shadow->hdr.shadow_vmcs != nested_cpu_has_shadow_vmcs(vmcs12)) r = -EINVAL; - kunmap(page); - kvm_release_page_clean(page); + + kvm_vcpu_unmap(vcpu, &map, false); return r; } -- 2.7.4