Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2269682pxb; Mon, 11 Jan 2021 05:39:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTCHRtLkL/Xe4Q3O4HQnfxYHUlKOcbIRxViQKBhqPX5Cx92BqZ02J17gYKE3r4bY4sNxzK X-Received: by 2002:a17:907:1010:: with SMTP id ox16mr11062947ejb.439.1610372384038; Mon, 11 Jan 2021 05:39:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610372384; cv=none; d=google.com; s=arc-20160816; b=n5v0GDmSLwIyKWQIf2R/hyvCecqlpAeUASrjckxYuMshqUB1Wtqu9vAZCwqYZtjlZk wSeIDUlZ59g+GKIERDU6alQzMGthYXm3gZoQEE2RC1nTs7rBK59RXhs8pxfszS+LFvCE H96SXsPQqkh4vnlf4L4gvKP3Iz0LSM/UswRsgjTpkQsZ7ji5SG+XTVfEZJmvqf6ZP0xA KrlZnWLyps6ade2nvmCV4L1zOXrhc/t1D0A9AyoPTsLUYHR0wmA00NitEw9HcJ06frNN O2mPrIGSZMdpETleRtFCgw7DBLm8d85wyXeofH8nDaC7pZY82dIqlLDo3aNFVjiK9Igh PNxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XQKHm9g3+IQpdyXAUMvsRMqkgLSuGYGAI9jE+zr7bKs=; b=bu1X+kRZfLSCLDCU6IKwOHclzg7a8/RDVFgFCQmhzfEBn++QF0sZlkHr/q+2g9AadS 9q5DUtz7nAcIrtUFr7IFYOJiCxC5klrReRlufKhHz3IrfArOIp7UFW1od81ug+KmUzYy mJHBRnFoiLZ5q5EKVWCmxMByKHa+S/5gXh0UvMAjbW3NNSJeiFgVykVLhPLec+2zVx0y 07y4oWmca2JtWzo22cS+0xfZxrbu86YfgcF1gi1kI0GdM63qUJ5SpB3OMa1G9Y2Lsvjs BGI9MM14jLfgq/KOM75ZLFXH6w8U/3FUmabrzrB/d49AJGiCToEpaAoqqP4rXNzky/6L ICfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rwADn/jo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si6928393edx.272.2021.01.11.05.39.19; Mon, 11 Jan 2021 05:39:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rwADn/jo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731944AbhAKNNh (ORCPT + 99 others); Mon, 11 Jan 2021 08:13:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:58908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731638AbhAKNNM (ORCPT ); Mon, 11 Jan 2021 08:13:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6CFDC22AAB; Mon, 11 Jan 2021 13:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370776; bh=hlR4DTAutJKTaLyj2TlIyWV1L+EXEmeTeWFnEO5mTsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rwADn/joqEvHPX+69actKsfxLpPia22TMafGyILt0mZHXFda7SRAopi9T2EpzIjnI QgqPkjkwDKUe4SN87A+6bfVKvBJ5PFUblZAwCj471KV1KGNq0RkvJyW3YGG+Zp7AhU gs/zEbJrlrmQVMfQMfQHmerohJvZVF/rMB9Sd/1w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ying-Tsun Huang , Borislav Petkov Subject: [PATCH 5.4 91/92] x86/mtrr: Correct the range check before performing MTRR type lookups Date: Mon, 11 Jan 2021 14:02:35 +0100 Message-Id: <20210111130043.543092815@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130039.165470698@linuxfoundation.org> References: <20210111130039.165470698@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ying-Tsun Huang commit cb7f4a8b1fb426a175d1708f05581939c61329d4 upstream. In mtrr_type_lookup(), if the input memory address region is not in the MTRR, over 4GB, and not over the top of memory, a write-back attribute is returned. These condition checks are for ensuring the input memory address region is actually mapped to the physical memory. However, if the end address is just aligned with the top of memory, the condition check treats the address is over the top of memory, and write-back attribute is not returned. And this hits in a real use case with NVDIMM: the nd_pmem module tries to map NVDIMMs as cacheable memories when NVDIMMs are connected. If a NVDIMM is the last of the DIMMs, the performance of this NVDIMM becomes very low since it is aligned with the top of memory and its memory type is uncached-minus. Move the input end address change to inclusive up into mtrr_type_lookup(), before checking for the top of memory in either mtrr_type_lookup_{variable,fixed}() helpers. [ bp: Massage commit message. ] Fixes: 0cc705f56e40 ("x86/mm/mtrr: Clean up mtrr_type_lookup()") Signed-off-by: Ying-Tsun Huang Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20201215070721.4349-1-ying-tsun.huang@amd.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/mtrr/generic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -167,9 +167,6 @@ static u8 mtrr_type_lookup_variable(u64 *repeat = 0; *uniform = 1; - /* Make end inclusive instead of exclusive */ - end--; - prev_match = MTRR_TYPE_INVALID; for (i = 0; i < num_var_ranges; ++i) { unsigned short start_state, end_state, inclusive; @@ -261,6 +258,9 @@ u8 mtrr_type_lookup(u64 start, u64 end, int repeat; u64 partial_end; + /* Make end inclusive instead of exclusive */ + end--; + if (!mtrr_state_set) return MTRR_TYPE_INVALID;