Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp524045imu; Wed, 9 Jan 2019 01:45:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN4bSCu9KZs0N12MLy5RSyJy4g80kUZbYalT4t9AYF3wTXWkrxLN2Z5WVHuwfP4PDklAriOM X-Received: by 2002:a63:ea15:: with SMTP id c21mr4491953pgi.361.1547027112081; Wed, 09 Jan 2019 01:45:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547027112; cv=none; d=google.com; s=arc-20160816; b=bdo3nIRXv6fgYu3o/N/1rlF31Six2UhdhkpXkUvoG0QpDAaQ9bIO4cMNVTj1hN9wiu dCI483BKLG/cutr7wZCprdjcTkrXfhmmhlWmwG/JWdTL/Tk9ZqYQ8BOg8r88fs7fVcBP xXx+c7HhIR7fWbJ7RqEeqM6yoYkYpDa/KnBcwdw+nRBZOU/rdT1Ee/+zEvP5igBUKthw MZ8XomLIOmCYFUSXXIhYYM7v5ZjOLh8c6xAUBplRi7En1/0yD1WcfiaZXm3WX8uQWcQn 3SLL0csc1SLvD1qmrdXGA9YokImCzXZJoQ1guhX31MHQWRjHWSf3XdHyawWw5polvwUz JLtw== 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=UZb1p4sLrN6RruG6/MmAj6BS9+S+F2r8tm9M137yg1M=; b=wlQunQiNhZjJQBzXtidliQ3vGvdv9kbI52AIbyooG2kqa0Vbg+ZWhBeR+wRjKaGJK4 n/1Peeb97PetV13WDV/l2ex900o0rlSCzM0iOZasOCUoVHOEdixmbaDjX/KM6NhHMnnP 9rG9KzKW9LomzTqF/CPSZqbC5EA/S29YAjPwkqBbj/Xu1ZzM2MmwDV7cdPgQ7Wrh8WMQ +kmC1W5TpRwBt3mS2rar39/jp1gYXYdFTcMmzA0pX/DGicl+XnZRcHCbA8/UcnvbYjxA u5fb02bSCKJxS55klVERUzwX4vy/fccOnq6WsKWK6bN+/bwEvOYrot7YaUKRBxsLTAN5 ThjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=RaSCcnM8; 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 l4si2515890pgr.346.2019.01.09.01.44.56; Wed, 09 Jan 2019 01:45:12 -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=RaSCcnM8; 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 S1730470AbfAIJm2 (ORCPT + 99 others); Wed, 9 Jan 2019 04:42:28 -0500 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:26334 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730382AbfAIJm0 (ORCPT ); Wed, 9 Jan 2019 04:42:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1547026946; x=1578562946; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=UZb1p4sLrN6RruG6/MmAj6BS9+S+F2r8tm9M137yg1M=; b=RaSCcnM8MhuNmrXnybZ41DCPniFqGIpATsQpSJ0VLLCUozJIERtxEJoq ivl5TV1elG/2bx2Wh8Fn8xZ3GVKoOvY++scyzz7qAWkWODJc4cK3YvX+E iFoPtfRY9oY9czdBzePYK7LBaPLUZ0xSX/v/jIL/g8wqm9V1hw+gWbgi+ A=; X-IronPort-AV: E=Sophos;i="5.56,253,1539648000"; d="scan'208";a="753236067" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-579b7f5b.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 09 Jan 2019 09:42:24 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2c-579b7f5b.us-west-2.amazon.com (Postfix) with ESMTPS id C05BEA1F2A; Wed, 9 Jan 2019 09:42:23 +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 x099gLhk031343; Wed, 9 Jan 2019 10:42:21 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id x099gLqY031341; Wed, 9 Jan 2019 10:42:21 +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 11/13] KVM/nVMX: Use kvm_vcpu_map for accessing the shadow VMCS Date: Wed, 9 Jan 2019 10:42:11 +0100 Message-Id: <1547026933-31226-12-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 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 --- 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 b4230ce..04a8b43 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(&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(&map, false); return r; } -- 2.7.4