Received: by 10.223.164.221 with SMTP id h29csp3150148wrb; Fri, 3 Nov 2017 02:32:03 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RLf8ft2oAoTxhjgEugOub1BtDPrABNNy4mwFIbMFiPFy+pw00Ab3atRwyCIEZ4gy8HPhQf X-Received: by 10.84.160.227 with SMTP id v32mr6057760plg.367.1509701523205; Fri, 03 Nov 2017 02:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509701523; cv=none; d=google.com; s=arc-20160816; b=ez5d6IQ7Xv9O35HHMKdVjtmVzB531plf7ikDKTmIKWKlsFT7HrQdesHE9plYGLdCvA HMZi4DZfd9spRS3Erw1y8L7ZJVlJkMvbHgVoAOgo3V3DiT1OhqBurhkN+VJIPmEN6KRp UF5FJob+IuqC8WiKQvZfFGqx40FIZ5/QO6bnSNSzN6zNpUKPf8gWuoCuKgaEu7vH/LpK YJ+BExA+MdUWfWdPfBn9+0OG/aE7fdcm3/PvL6pkw5CJzwa8oRnhV+zF7UEPieHwbREd 72YXonGzDWRKY0W5RWqP7QWpchA8V6JOBx/mBEUl3Iu2IEvgQr/14mSvbFQRzPIiAjGR 5nCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:arc-authentication-results; bh=ehCf0r4Ju8WA62hgKMAAg7Pk0VQLctMB6H0l9nWoWMo=; b=ZjP4owH/Ir+aqqjOhgK3stkt3c1OPx6T/ZAjDh7EtEDpE/Wbjpcqv9lWDJtP2wtBR9 5Xoz7gL9w43+g+BFOMTMHLFJTWQrJu2Ev5aJv3o27NnJXW2+zEIRD7LIZdreTtVymobf YkW/UQr8gjqAWnkCZq3uFPEPUzZzD2SEoi/koHyl+GfXlre+a+WID1BPpxF2Re6McUt3 ifVsE3XYsBO09iMZP74JWPO73fiozY/JRchUqMIBufOxZHRpLOpiYvFS5WC7HZH2gaVH 00jPQ8t8vHqKeH98jgPw4OFpBojg6c/uMCXopfMVHWc14gCDoBY/+NzBeYAooI9pAJtx sBrw== 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 64si5844909pft.267.2017.11.03.02.31.49; Fri, 03 Nov 2017 02:32:03 -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 S1755816AbdKCJ3z (ORCPT + 97 others); Fri, 3 Nov 2017 05:29:55 -0400 Received: from mga09.intel.com ([134.134.136.24]:47621 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754185AbdKCJ3x (ORCPT ); Fri, 3 Nov 2017 05:29:53 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Nov 2017 02:29:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,338,1505804400"; d="scan'208";a="331614227" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga004.fm.intel.com with ESMTP; 03 Nov 2017 02:29:49 -0700 Date: Fri, 3 Nov 2017 17:29:56 +0800 From: Haozhong Zhang To: Xiao Guangrong Cc: Xiao Guangrong , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , rkrcmar@redhat.com, Dan Williams , ivan.d.cuevas.escareno@intel.com, karthik.kumar@intel.com, Konrad Rzeszutek Wilk , Olif Chapman , Ingo Molnar Subject: Re: [PATCH v4 3/3] KVM: MMU: consider host cache mode in MMIO page check Message-ID: <20171103092956.y6sbvvyh3dg3mjyw@hz-desktop> Mail-Followup-To: Xiao Guangrong , Xiao Guangrong , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , rkrcmar@redhat.com, Dan Williams , ivan.d.cuevas.escareno@intel.com, karthik.kumar@intel.com, Konrad Rzeszutek Wilk , Olif Chapman , Ingo Molnar References: <20171103055327.21684-1-haozhong.zhang@intel.com> <20171103055327.21684-4-haozhong.zhang@intel.com> <745df599-b65b-bcfe-a20c-05ae6d99a0b5@gmail.com> <20171103085130.itjzxoaorvw34vnm@hz-desktop> <20171103090244.swsna6h4hk5j4bdh@hz-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170714 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/03/17 17:24 +0800, Xiao Guangrong wrote: > > > On 11/03/2017 05:02 PM, Haozhong Zhang wrote: > > On 11/03/17 16:51 +0800, Haozhong Zhang wrote: > > > On 11/03/17 14:54 +0800, Xiao Guangrong wrote: > > > > > > > > > > > > On 11/03/2017 01:53 PM, Haozhong Zhang wrote: > > > > > 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 | 19 ++++++++++++++++++- > > > > > 1 file changed, 18 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c > > > > > index 0b481cc9c725..e9ed0e666a83 100644 > > > > > --- a/arch/x86/kvm/mmu.c > > > > > +++ b/arch/x86/kvm/mmu.c > > > > > @@ -2708,7 +2708,24 @@ 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)); > > > > > + return !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 in addition and > > > > > + * only treat UC/UC- pages as MMIO. > > > > > + * > > > > > + * pat_pfn_is_uc() works only when PAT is enabled, > > > > > + * so check pat_enabled() as well. > > > > > + */ > > > > > + (!pat_enabled() || > > > > > + pat_pfn_is_uc(kvm_pfn_t_to_pfn_t(pfn))); > > > > > > > > Can it be compiled if !CONFIG_PAT? > > > > > > Yes. > > > > > > What I check via pat_enabled() is not only whether PAT support is > > > compiled, but also whether PAT is enabled at runtime. > > > > > > > > > > > It would be better if we move pat_enabled out of kvm as well, > > > > > > Surely I can combine them in one function like > > > > > > bool pat_pfn_is_uc(pfn_t pfn) > > > { > > > enum page_cache_mode cm; > > > > > > if (!pat_enabled()) > > > return false; > > > > > > cm = lookup_memtype(pfn_t_to_phys(pfn)); > > > > > > return cm == _PAGE_CACHE_MODE_UC || cm == _PAGE_CACHE_MODE_UC_MINUS; > > > } > > > > In addition, I think it's better to split this function into > > pat_pfn_is_uc() and pat_pfn_is_uc_minus() to avoid additional > > confusion. > > Why not use pat_pfn_is_uc_or_uc_minus(). :) Just in case that other places other than KVM do not need both of them. From 1583036622199770910@xxx Fri Nov 03 09:29:28 +0000 2017 X-GM-THRID: 1583005689428392726 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread