From nobody Tue Feb 10 23:01:57 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 54CB5C6FD1D for ; Sat, 1 Apr 2023 06:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233493AbjDAGim (ORCPT ); Sat, 1 Apr 2023 02:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233502AbjDAGi0 (ORCPT ); Sat, 1 Apr 2023 02:38:26 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D52B1D908 for ; Fri, 31 Mar 2023 23:38:00 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 885F421A48; Sat, 1 Apr 2023 06:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680331072; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8lUW3P9mpcWjI7lNcX7PnUpBYL4zKefFnDWcjHwwm2k=; b=HexWFFQQVN5UN/qYGGwLOJTZXbNlqk67Lpl8/tvSu3uH7ydHzS+4O0feVIQhQJ973OGmFu Psqrkxh0wv+Fq+GClVWHorkEtZeRfyGUFk8NUfWidg5ha0oOMlOmIGoGC0+ODkliqiqFeo QhdZuv8XWJF+uveQWPaarVoXwuvvc5k= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4290B134FB; Sat, 1 Apr 2023 06:37:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MbvdDkDRJ2RwdwAAMHmgww (envelope-from ); Sat, 01 Apr 2023 06:37:52 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Michael Kelley Subject: [PATCH v5 10/15] x86/mtrr: add get_effective_type() service function Date: Sat, 1 Apr 2023 08:36:47 +0200 Message-Id: <20230401063652.23522-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230401063652.23522-1-jgross@suse.com> References: <20230401063652.23522-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Tested-by: Michael Kelley --- V3: - new patch --- 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 5d60b46187f7..005f07ebb3a3 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -78,31 +78,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 /** --=20 2.35.3