Received: by 10.223.164.221 with SMTP id h29csp3144683wrb; Fri, 3 Nov 2017 02:25:18 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TJUFtx/+rZAfO1rBcpAg1P/QflmiKh3XlBiBNkSCqqOjV5NAPis6qnwxwTM0FsGljPBR4y X-Received: by 10.99.176.72 with SMTP id z8mr3576071pgo.175.1509701118471; Fri, 03 Nov 2017 02:25:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509701118; cv=none; d=google.com; s=arc-20160816; b=t8URUROxZATdosVcvXzK/bKVaqm6RBTzq4+9SoNJKAQfFDHJzoUJ/Gn3VRDJSeA1nv qUz5R2qa6x/4b8Ih8xZgGE2M5wFdGh2JCxMB6/Y2vX9tccV4pgdMqOOs38yJK1ehm2fD uoBRGQqvC9bupBqTqTAy/KpQlthyz77MPPryiOGqsWd0D2A7Omy88IBhgPu4EYbzmKiV eF/WJI7CVcU9KFf1C3RTw/1ePm6xZ4FHJpqLpeTwxHS6QCGtGnld0zJxH2Wjv5OVoYAq VJXHkbMRsyPXOXxN4hu3eK8xKP7dVUXJnm8Wl9MBv398K9XYGLwFNtxTtwjmKj2XzA6x dLAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature :arc-authentication-results; bh=MtRZEhtzJLnSIdC7ags06cjZTLDCBDruWtLJm0er3j0=; b=G+buCT4APlxR3oa+R2aOYp+H66RrlY9RRl/N2bFakOt0WPgf8SkUnTfESUuLlUR2JA S9c5pmpmDetQpDP69+HSfRfKIl2slRPDaCLc4n0HE6eaHJiHU0arcwYy0JD6C52z1IFm PCrU4IeD+COJbsXERfPNtIqeXDoFxZFT6wseAJvNY86IAuXQUNdw7xVosLzoBDt0eRTM RgZoB67kRExK65m8I3YjF14xyyosy4wM3fHp0B3CJIMe4RYn5kqq5BPtADrIrIw3VZ6F K5mA8TTqlOrYOMbluNi/T8toub14i1nqw7uOQ6WYzm8UP2syjj+D+p4tplzF/j20+4m6 gxBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lfTN1t8s; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si5969813pfh.412.2017.11.03.02.25.04; Fri, 03 Nov 2017 02:25:18 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lfTN1t8s; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754573AbdKCJYZ (ORCPT + 97 others); Fri, 3 Nov 2017 05:24:25 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:53467 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752469AbdKCJYX (ORCPT ); Fri, 3 Nov 2017 05:24:23 -0400 Received: by mail-pg0-f67.google.com with SMTP id s2so1959499pge.10; Fri, 03 Nov 2017 02:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=MtRZEhtzJLnSIdC7ags06cjZTLDCBDruWtLJm0er3j0=; b=lfTN1t8sN20UenMJJ2CL9U+3gzruEvlV7DOJ3waTgOTcepW+eQ/JzZgsqNgekokzHK 1WQMatytoDkfQB/JTsOe/Ky3Qo7mCUGK0B0Pu6pWQbGpz/wZy2VobdITxWS+kwHdM753 4hd49Ov04qK6EIHw7OKMlKXONiZwy+JSIJWhZ4QKG9GghdwR2IERymnJmKevW7uxaN+s U2QkkNZm24ATrpVXmBlXFsiXDKDJKKiRI6P3Gpcyg/ct+ZKEZ9A3c2FyoXkK9p97jDo/ 6NwbBkhU5m1JmTcWvlOffiViXxvBheDxs0JQy3yoW8iqFr869LO4eZ4DTls/JLyyUknX N61w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=MtRZEhtzJLnSIdC7ags06cjZTLDCBDruWtLJm0er3j0=; b=ROvpG6q1crRAAeess8HG9Veu7tzM7z9fORXkfLjFsckv3XuC2/ajU5+rklYAWqgZiq PKzzvyvp+p/OCD4o1sVvDBOZC2m4XpRFVBXy6ausE5RYcahCqHqRJRd/d6NhW/NIqXF+ FpGWmgHMGn88vkHXNFagOLw82kDjSRRIVwlK5W+sg43yyG0HQJubRR/xwu/wqmAn//Io KRK0IlvFm6/1RoWfbhZ5Bd21wihOuqE2OD4U9r+sPG1rgMgLBJCeQEHBFG5qzjZA2OVp 1+5CpA69tn7ap1U2vt4Xkz+M0ndYv6J1ilHbkU34edyG5/Kauhxxwk31VPZ57IwR6DCW d3uw== X-Gm-Message-State: AMCzsaXCvEz6vkkdmPi8i6Qr0QGe+eNE1J9WcSla3tOmYznVKpalTEk1 fnJDWUXoSbGKDE+lbupsGRw= X-Received: by 10.98.29.211 with SMTP id d202mr6920556pfd.49.1509701062650; Fri, 03 Nov 2017 02:24:22 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.35]) by smtp.gmail.com with ESMTPSA id u6sm11056439pfg.175.2017.11.03.02.24.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 02:24:22 -0700 (PDT) Subject: Re: [PATCH v4 3/3] KVM: MMU: consider host cache mode in MMIO page check To: 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> From: Xiao Guangrong Message-ID: Date: Fri, 3 Nov 2017 17:24:43 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171103090244.swsna6h4hk5j4bdh@hz-desktop> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). :) From 1583035476095541200@xxx Fri Nov 03 09:11:15 +0000 2017 X-GM-THRID: 1583005689428392726 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread