Received: by 10.223.164.221 with SMTP id h29csp3778908wrb; Tue, 31 Oct 2017 04:51:29 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QBvBeRJS4E1k/h3Kh+Rz2txLWi8j4QYJf+bTl8tWYdqPhw8Syn7LuaXrYoHNRabFNtvL3o X-Received: by 10.98.192.134 with SMTP id g6mr1786794pfk.254.1509450689461; Tue, 31 Oct 2017 04:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509450689; cv=none; d=google.com; s=arc-20160816; b=G7F9TZYkAMJ9+AFPQAREWO9EIl8XXu1olUhGdpdqqQ+Wtbn7JhWDLmnNz5ZZDCSlLT 3lIdnoYGpGRCog31lND8loYMt/RuxMTsGUMnUuKjsnygNJWAf/roTNBkMqRsasuAe4km ieTTakUBdaH4RGvNV5HERKBXFjwzHXogpCb76NYzDP1O+L7GQxidJ8lR1I9PRgKQm0HZ 5UCqKQHSO8W1xxqeH9nx+hXXltR7C0rhqgLCLQ5G2rcgVI9t5m0TNn/7eF91xoE/Hp2y r5jH+BlJvCM1SezTO//jBq1lcNzYs5jNReFElOQS+/plYitnRP+VE6uGmk5XccecU9Vb 2uzg== 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:arc-authentication-results; bh=agNTJ1sh8GCquH6DsYHOR5SJscCNd4HDTRFCoMRjW/k=; b=loLD1+pa2942P1PgvMc6zwJSStqW2jLauUbW6fh1dBiefaDb/pwC9IQrlMuYgWwRYF lXxZaXJ4CX0ihCYa8GD+qz5XArRQEfOTyfuKxCJB262zYxy9wzOAvBFjkoTjnU/FBk6Z k6Dm/PBvBCgxwwakvzdMRkkjvtBXymo7mv8Bc9qFfXho5nkPppOZlz67oN62KsFlxWDl oPDfoIjgwA0A3itX5io0p0/9A20smJ/CXcaw2K7cs8MP/HPwOYkkZ+RWu0ZSuITFtuYs sFoYiNQOWMF5LIuTSTg0/mzhjTakWictGoamw23QLgPKLUVmXiy85g0OZiUdgXz2uZRR IBXg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si1379176plb.462.2017.10.31.04.51.16; Tue, 31 Oct 2017 04:51:29 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753186AbdJaLsk (ORCPT + 99 others); Tue, 31 Oct 2017 07:48:40 -0400 Received: from mga14.intel.com ([192.55.52.115]:15618 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753085AbdJaLsi (ORCPT ); Tue, 31 Oct 2017 07:48:38 -0400 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Oct 2017 04:48:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,323,1505804400"; d="scan'208";a="169982821" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga006.fm.intel.com with ESMTP; 31 Oct 2017 04:48:34 -0700 From: Haozhong Zhang To: kvm@vger.kernel.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , rkrcmar@redhat.com, Xiao Guangrong , Dan Williams , ivan.d.cuevas.escareno@intel.com, karthik.kumar@intel.com, Haozhong Zhang Subject: [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check Date: Tue, 31 Oct 2017 19:48:40 +0800 Message-Id: <20171031114840.12615-3-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171031114840.12615-1-haozhong.zhang@intel.com> References: <20171031114840.12615-1-haozhong.zhang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some reserved pages, such as those from NVDIMM DAX devices, are not for MMIO, and can be mapped with cached memory type for better performance. However, the above check misconceives those pages as MMIO. Because KVM maps MMIO pages with UC memory type, the performance of guest accesses to those pages would be harmed. Therefore, we check the host memory type by lookup_memtype() in addition and only treat UC/UC- pages as MMIO. Signed-off-by: Haozhong Zhang Reported-by: Cuevas Escareno, Ivan D Reported-by: Kumar, Karthik --- arch/x86/kvm/mmu.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 0b481cc9c725..206828d18857 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2707,10 +2707,34 @@ static bool mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn, static bool kvm_is_mmio_pfn(kvm_pfn_t pfn) { - if (pfn_valid(pfn)) - return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn)); + bool is_mmio = true; - return true; + if (pfn_valid(pfn)) { + is_mmio = !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn)); + + /* + * Some reserved pages, such as those from NVDIMM DAX + * devices, are not for MMIO, and can be mapped with + * cached memory type for better performance. However, + * the above check misconceives those pages as MMIO. + * Because KVM maps MMIO pages with UC memory type, + * the performance of guest accesses to those pages + * would be harmed. Therefore, we check the host + * memory type by lookup_memtype() in addition and + * only treat UC/UC- pages as MMIO. + * + * lookup_memtype() works only when PAT is enabled, so + * add pat_enabled() check here. + */ + if (is_mmio && pat_enabled()) { + enum page_cache_mode cm = lookup_memtype(PFN_PHYS(pfn)); + + is_mmio = (cm == _PAGE_CACHE_MODE_UC || + cm == _PAGE_CACHE_MODE_UC_MINUS); + } + } + + return is_mmio; } static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep, -- 2.14.1 From 1582940863145819526@xxx Thu Nov 02 08:07:25 +0000 2017 X-GM-THRID: 1582940863145819526 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread