From nobody Sun Feb 8 14:57:16 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 6CACBC7EE2C for ; Mon, 5 Jun 2023 14:09:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234496AbjFEOJQ (ORCPT ); Mon, 5 Jun 2023 10:09:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbjFEOIe (ORCPT ); Mon, 5 Jun 2023 10:08:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55DC0113; Mon, 5 Jun 2023 07:08:18 -0700 (PDT) Date: Mon, 05 Jun 2023 14:08:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685974095; 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=dkszJiQUc19TYyvNgf2X+55+itRvbG21PgPWoGQFrV0=; b=LVD0wn/UZQy0PSSc4bR249DJRbyR6sQZphRbLC9u/ieiDrcyFlUAqm1PHvD0gY0tZvxF7N szRJjFHvhJE67E07gSL+E42xJVoymmQlXVPUzlDdxEzPaXBugT7kXx9CyFPBnFb2Z38Z7g EXYKxcsPbJo/Ufo2glLcX3fwke65UEdZdkngH/ZwBkMp6I92JYu4Ojgn0KLE690bWLgyrh jO5OMsFT+tNn5mAPNo6g5W4uHQeTcTxRI0Tfz/EcYTed76eSoZ+vpoquljvvnwIIcUNjZp BDj8Sqog16c19PAQn6wHkAnP59FG+d5ONCFCIfRJq4FogC9G6kE632+uc/yYpg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685974095; 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=dkszJiQUc19TYyvNgf2X+55+itRvbG21PgPWoGQFrV0=; b=nh14nP0AE31w6XbaEJGFup5Q3OCU3Z1TGSEnAiwBvRRIxt/q4Pr0mX8MJzLOd1BwShr7lV BrM/vrNzc0Re36Cg== 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: Add get_effective_type() service function Cc: Juergen Gross , "Borislav Petkov (AMD)" , Michael Kelley , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230502120931.20719-11-jgross@suse.com> References: <20230502120931.20719-11-jgross@suse.com> MIME-Version: 1.0 Message-ID: <168597409499.404.18296081560876564264.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: 1ca12099040fec8c6bbcd9fabf37f04ac0d08e48 Gitweb: https://git.kernel.org/tip/1ca12099040fec8c6bbcd9fabf37f04ac= 0d08e48 Author: Juergen Gross AuthorDate: Tue, 02 May 2023 14:09:25 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 01 Jun 2023 15:04:33 +02:00 x86/mtrr: Add get_effective_type() service function Add a service function for obtaining the effective cache mode of overlapping MTRR registers. Make use of that function in check_type_overlap(). Signed-off-by: Juergen Gross Signed-off-by: Borislav Petkov (AMD) Tested-by: Michael Kelley Link: https://lore.kernel.org/r/20230502120931.20719-11-jgross@suse.com Signed-off-by: Borislav Petkov (AMD) --- arch/x86/kernel/cpu/mtrr/generic.c | 39 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/= generic.c index 4d8ca62..b944271 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -80,31 +80,30 @@ static u64 get_mtrr_size(u64 mask) return size; } =20 +static u8 get_effective_type(u8 type1, u8 type2) +{ + if (type1 =3D=3D MTRR_TYPE_UNCACHABLE || type2 =3D=3D MTRR_TYPE_UNCACHABL= E) + return MTRR_TYPE_UNCACHABLE; + + if ((type1 =3D=3D MTRR_TYPE_WRBACK && type2 =3D=3D MTRR_TYPE_WRTHROUGH) || + (type1 =3D=3D MTRR_TYPE_WRTHROUGH && type2 =3D=3D MTRR_TYPE_WRBACK)) + return MTRR_TYPE_WRTHROUGH; + + if (type1 !=3D type2) + return MTRR_TYPE_UNCACHABLE; + + return type1; +} + /* * Check and return the effective type for MTRR-MTRR type overlap. - * Returns 1 if the effective type is UNCACHEABLE, else returns 0 + * Returns true if the effective type is UNCACHEABLE, else returns false */ -static int check_type_overlap(u8 *prev, u8 *curr) +static bool check_type_overlap(u8 *prev, u8 *curr) { - if (*prev =3D=3D MTRR_TYPE_UNCACHABLE || *curr =3D=3D MTRR_TYPE_UNCACHABL= E) { - *prev =3D MTRR_TYPE_UNCACHABLE; - *curr =3D MTRR_TYPE_UNCACHABLE; - return 1; - } - - if ((*prev =3D=3D MTRR_TYPE_WRBACK && *curr =3D=3D MTRR_TYPE_WRTHROUGH) || - (*prev =3D=3D MTRR_TYPE_WRTHROUGH && *curr =3D=3D MTRR_TYPE_WRBACK)) { - *prev =3D MTRR_TYPE_WRTHROUGH; - *curr =3D MTRR_TYPE_WRTHROUGH; - } + *prev =3D *curr =3D get_effective_type(*curr, *prev); =20 - if (*prev !=3D *curr) { - *prev =3D MTRR_TYPE_UNCACHABLE; - *curr =3D MTRR_TYPE_UNCACHABLE; - return 1; - } - - return 0; + return *prev =3D=3D MTRR_TYPE_UNCACHABLE; } =20 /**