From nobody Sun Feb 8 19:44:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8189EC7EE23 for ; Mon, 5 Jun 2023 14:09:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234444AbjFEOJB (ORCPT ); Mon, 5 Jun 2023 10:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234320AbjFEOId (ORCPT ); Mon, 5 Jun 2023 10:08:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B28F810DD; Mon, 5 Jun 2023 07:08:15 -0700 (PDT) Date: Mon, 05 Jun 2023 14:08:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685974094; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2cC+ObGB+xSsfPslky5orlr06ncXedkCX7VtpUcsTbU=; b=B2anWDs/k+wP7kZJEz1wf1t6dzh9lKq9C8ZsL3Df/ouPII7JuSDn+8Ws+EWHJoyKZMW3SD J5avIBtia+oRHWCvs4mtlIbMv5jMLEp3bJpNwGQ6MgluGWIDNxtHXxRz0tnV0ksdZ2ncxi NIPLhrNbSdDAXWOlKtcBGmFR3eir+0EDlrS2VcXwD6ybuXpTlM1HuyuPEN0LLN6CdZmmDZ xWaTYNHFYDY8Jm1g9U/YUgaRK0nQFUGvgnW1scfsJaF9TobW6ev8b01VCgBJBS5gQmiGIF IK3Fg+ZpHepGfvFwNDueIrbOAxtgJYrJqXsqedK3WX682c19dYgmEMAHpJl22Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685974094; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2cC+ObGB+xSsfPslky5orlr06ncXedkCX7VtpUcsTbU=; b=v+HwJhGtv0G1mnSJg6sGeHY2eEpDR9E7v6a7yo3AsuFTgKaU2Rq6fu786x0wrpgtGjZ2pN CKM4faTksxvQqRCw== From: "tip-bot2 for Juergen Gross" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mtrr] x86/mtrr: Don't let mtrr_type_lookup() return MTRR_TYPE_INVALID Cc: Linus Torvalds , Juergen Gross , "Borislav Petkov (AMD)" , Michael Kelley , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230502120931.20719-15-jgross@suse.com> References: <20230502120931.20719-15-jgross@suse.com> MIME-Version: 1.0 Message-ID: <168597409373.404.18390017504973748078.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/mtrr branch of tip: Commit-ID: 973df1942068c0cc72244ce7dce5e5aeca03ad5f Gitweb: https://git.kernel.org/tip/973df1942068c0cc72244ce7dce5e5aec= a03ad5f Author: Juergen Gross AuthorDate: Tue, 02 May 2023 14:09:29 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 01 Jun 2023 15:04:33 +02:00 x86/mtrr: Don't let mtrr_type_lookup() return MTRR_TYPE_INVALID mtrr_type_lookup() should always return a valid memory type. In case there is no information available, it should return the default UC. This will remove the last case where mtrr_type_lookup() can return MTRR_TYPE_INVALID, so adjust the comment in include/uapi/asm/mtrr.h. Note that removing the MTRR_TYPE_INVALID #define from that header could break user code, so it has to stay. At the same time the mtrr_type_lookup() stub for the !CONFIG_MTRR case should set uniform to 1, as if the memory range would be covered by no MTRR at all. Suggested-by: Linus Torvalds Signed-off-by: Juergen Gross Signed-off-by: Borislav Petkov (AMD) Tested-by: Michael Kelley Link: https://lore.kernel.org/r/20230502120931.20719-15-jgross@suse.com Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/mtrr.h | 7 +++++-- arch/x86/include/uapi/asm/mtrr.h | 6 +++--- arch/x86/kernel/cpu/mtrr/generic.c | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h index 1bae790..5a758ee 100644 --- a/arch/x86/include/asm/mtrr.h +++ b/arch/x86/include/asm/mtrr.h @@ -86,9 +86,12 @@ static inline void mtrr_overwrite_state(struct mtrr_var_= range *var, static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform) { /* - * Return no-MTRRs: + * Return the default MTRR type, without any known other types in + * that range. */ - return MTRR_TYPE_INVALID; + *uniform =3D 1; + + return MTRR_TYPE_UNCACHABLE; } #define mtrr_save_fixed_ranges(arg) do {} while (0) #define mtrr_save_state() do {} while (0) diff --git a/arch/x86/include/uapi/asm/mtrr.h b/arch/x86/include/uapi/asm/m= trr.h index ab194c8..3a8a8eb 100644 --- a/arch/x86/include/uapi/asm/mtrr.h +++ b/arch/x86/include/uapi/asm/mtrr.h @@ -107,9 +107,9 @@ typedef __u8 mtrr_type; #define MTRR_NUM_TYPES 7 =20 /* - * Invalid MTRR memory type. mtrr_type_lookup() returns this value when - * MTRRs are disabled. Note, this value is allocated from the reserved - * values (0x7-0xff) of the MTRR memory types. + * Invalid MTRR memory type. No longer used outside of MTRR code. + * Note, this value is allocated from the reserved values (0x7-0xff) of + * the MTRR memory types. */ #define MTRR_TYPE_INVALID 0xff =20 diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/= generic.c index 4443e71..f6b426d 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -508,13 +508,13 @@ u8 mtrr_type_lookup(u64 start, u64 end, u8 *uniform) if (!mtrr_state_set) { /* Uniformity is unknown. */ *uniform =3D 0; - return MTRR_TYPE_INVALID; + return MTRR_TYPE_UNCACHABLE; } =20 *uniform =3D 1; =20 if (!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED)) - return MTRR_TYPE_INVALID; + return MTRR_TYPE_UNCACHABLE; =20 for (i =3D 0; i < cache_map_n && start < end; i++) { /* Region after current map entry? -> continue with next one. */