Received: by 10.223.164.202 with SMTP id h10csp1199353wrb; Tue, 7 Nov 2017 23:59:22 -0800 (PST) X-Google-Smtp-Source: ABhQp+QuN9uJ3QXK3khvZsvTj2NxIEEkfv4zg7+d179a9X8AVEv8iheIdeBI3QuqlSqo+QULPrOt X-Received: by 10.84.254.79 with SMTP id a15mr1456316pln.413.1510127962616; Tue, 07 Nov 2017 23:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510127962; cv=none; d=google.com; s=arc-20160816; b=rHtu6uZ38Tc73NW5b+jenKjlB5OCQUm3dTOeTKEtSV3lnfzhjBlbH04YCQEr5Dqvox q6oA0Unj3QOQUyR99J6zBG1cRSJlTMfN4VtaWyAQVOcjB34eTleq/6/kWlsLarhVA+3K JbrqnihI4RF9bsR+9JesNSAl5sMKsG7vT7iGaU3ksAS5Qqiuoxhh4jJ7efQGQQBzw2si RJ8XsU6qeNvBM+bw8Y44PosCtk0XrkXQVmumILFULKLM+tUTun3iNsd6ujMZuFmxcKcA jhnbIMhcBcnfKf5vItw0PDNaHduK4J6fqdoK/bByez8fsWj/UhMk8FWjms0E+i99m+MW 6JtQ== 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=0ec0Pj2WFNbo2s7aOdOuAWpbvOmRlyuIFIiffvqpD14=; b=MJSohLBPHX7NWIAU2t6TPObh4TjvnVVIMkO6CFdC2Tg573paZQwphC2DSOtrQdju90 YG7bw+3nn811iA4zn/jCTDxJZwrasJZ6BXMY7H3k1EsAcoxJFln/0yOKsB1ru+hZ+ewR 3X+la65D4n6YzcdIRyj4V2hONt7Ba/UAMscqI3FzQsrYB1j2VNUiyAKQijccLl8RJNc2 FybgtJGu21iNiLlp5CB2x6/0f6eh2euf67sIxZLWLuFwTIBpasW/16aUMcEKNdtUyuHd kQjYS+bDKV9Zvba1HsdNaYRiH5ec3eN+yCoNyuQjfQNuIl91b1KtuDVx+1Z6J3YFoIek A1Cw== 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 f189si3480129pfa.45.2017.11.07.23.59.10; Tue, 07 Nov 2017 23:59:22 -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; 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 S1751428AbdKHH6C (ORCPT + 89 others); Wed, 8 Nov 2017 02:58:02 -0500 Received: from mga01.intel.com ([192.55.52.88]:4953 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751049AbdKHH4u (ORCPT ); Wed, 8 Nov 2017 02:56:50 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2017 23:56:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,363,1505804400"; d="scan'208";a="1241320401" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 07 Nov 2017 23:56:47 -0800 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, Konrad Rzeszutek Wilk , Olif Chapman , Mikulas Patocka , Haozhong Zhang , Ingo Molnar Subject: [PATCH v5 2/2] KVM: MMU: consider host cache mode in MMIO page check Date: Wed, 8 Nov 2017 15:56:30 +0800 Message-Id: <20171108075630.16991-3-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171108075630.16991-1-haozhong.zhang@intel.com> References: <20171108075630.16991-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 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 0b481cc9c725..7715476bc5c9 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2708,7 +2708,20 @@ 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_enabled() || pat_pfn_is_uc_or_uc_minus(pfn)); return true; } -- 2.14.1 From 1583468622039692839@xxx Wed Nov 08 03:55:55 +0000 2017 X-GM-THRID: 1583468622039692839 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread