From nobody Sat Sep 13 00:05:27 2025 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 8F276C636CD for ; Tue, 7 Feb 2023 07:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbjBGH3S (ORCPT ); Tue, 7 Feb 2023 02:29:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbjBGH3N (ORCPT ); Tue, 7 Feb 2023 02:29:13 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05FA732E7F for ; Mon, 6 Feb 2023 23:29:11 -0800 (PST) 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 9E32F21EBA; Tue, 7 Feb 2023 07:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675754950; 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=rbY40ezGliGVnHSth5hMXNDNMzMU7QLwqm1NaZ+5dkM=; b=jO5CLX0xWZHkj2UeNFp7sHfonkrtsyyATSHmwc/Kj7LOQ6K7zCAPf53+TN60RGd5qHyeEr QDMFsUrfE5zkMS5871Z37xsigU2CNsjkAmu1NlqLmB3WZ/h+Ab/lSeX1EUiYkCIzl+W5wt V2LD3eJTvJVvptr8534mzNyQfilK9OU= 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 5163613A8C; Tue, 7 Feb 2023 07:29:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 1Wd/Esb94WOfUQAAMHmgww (envelope-from ); Tue, 07 Feb 2023 07:29:10 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 1/6] x86/mtrr: make mtrr_enabled() non-static Date: Tue, 7 Feb 2023 08:28:57 +0100 Message-Id: <20230207072902.5528-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230207072902.5528-1-jgross@suse.com> References: <20230207072902.5528-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" In order to be able to use mtrr_enabled() outside of MTRR code, make it non-static and add a sub for the !CONFIG_MTRR case. Signed-off-by: Juergen Gross --- arch/x86/include/asm/mtrr.h | 6 ++++++ arch/x86/kernel/cpu/mtrr/mtrr.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h index f0eeaf6e5f5f..29ec2d6f0537 100644 --- a/arch/x86/include/asm/mtrr.h +++ b/arch/x86/include/asm/mtrr.h @@ -31,6 +31,7 @@ */ # ifdef CONFIG_MTRR void mtrr_bp_init(void); +bool mtrr_enabled(void); extern u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform); extern void mtrr_save_fixed_ranges(void *); extern void mtrr_save_state(void); @@ -48,6 +49,11 @@ void mtrr_disable(void); void mtrr_enable(void); void mtrr_generic_set_state(void); # else +static inline bool mtrr_enabled(void) +{ + return false; +} + static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform) { /* diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtr= r.c index 783f3210d582..814cc13fd6eb 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.c +++ b/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -59,7 +59,7 @@ #define MTRR_TO_PHYS_WC_OFFSET 1000 =20 u32 num_var_ranges; -static bool mtrr_enabled(void) +bool mtrr_enabled(void) { return !!mtrr_if; } --=20 2.35.3 From nobody Sat Sep 13 00:05:27 2025 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 45FBDC636CD for ; Tue, 7 Feb 2023 07:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjBGH3Z (ORCPT ); Tue, 7 Feb 2023 02:29:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjBGH3T (ORCPT ); Tue, 7 Feb 2023 02:29:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA67836089 for ; Mon, 6 Feb 2023 23:29:17 -0800 (PST) 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-out2.suse.de (Postfix) with ESMTPS id 68AE860F1F; Tue, 7 Feb 2023 07:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675754956; 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=MDR6p3EEVdt6aI87yhW7ogY5yoUM9JM3hkrFmMLxzCQ=; b=tDbv7vnL7LeZnXzm7xPgZ0dgekKLu5Kq2IaGD8+x2/lhyO2fRjp33UC/eYHyw/oto49Z3l ui0fwheHnag2U7JLyNI+QwYEdOnhKIZRbuOMWZCJXEj5R9HbI/ooM4AhK751VnRmDKBsfr HRJ+nvkd9mP2RgasyzPodZaYgpy8G4g= 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 1160313A8C; Tue, 7 Feb 2023 07:29:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id n5fiAsz94WO4UQAAMHmgww (envelope-from ); Tue, 07 Feb 2023 07:29:16 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH 2/6] x86/pat: check for MTRRs enabled in memtype_reserve() Date: Tue, 7 Feb 2023 08:28:58 +0100 Message-Id: <20230207072902.5528-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230207072902.5528-1-jgross@suse.com> References: <20230207072902.5528-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" Today memtype_reserve() bails out early if pat_enabled() returns false. The same can be done in case MTRRs aren't enabled. This will reinstate the behavior of memtype_reserve() before commit 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen"). There have been reports about that commit breaking SEV-SNP guests under Hyper-V, which was tried to be resolved by commit 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case"), but that again resulted in problems with Xen PV guests. Fixes: 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state wh= en running on Xen") Fixes: 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case= ") Signed-off-by: Juergen Gross --- arch/x86/mm/pat/memtype.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index fb4b1b5e0dea..18f612b43763 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -557,8 +557,12 @@ int memtype_reserve(u64 start, u64 end, enum page_cach= e_mode req_type, return -EINVAL; } =20 - if (!pat_enabled()) { - /* This is identical to page table setting without PAT */ + /* + * PAT disabled or MTRRs disabled don't require any memory type + * tracking or type adjustments, as there can't be any conflicts + * between PAT and MTRRs with at least one of both being disabled. + */ + if (!pat_enabled() || !mtrr_enabled()) { if (new_type) *new_type =3D req_type; return 0; @@ -627,7 +631,7 @@ int memtype_free(u64 start, u64 end) int is_range_ram; struct memtype *entry_old; =20 - if (!pat_enabled()) + if (!pat_enabled() || !mtrr_enabled()) return 0; =20 start =3D sanitize_phys(start); --=20 2.35.3 From nobody Sat Sep 13 00:05:27 2025 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 E12CCC636CC for ; Tue, 7 Feb 2023 07:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230283AbjBGH3c (ORCPT ); Tue, 7 Feb 2023 02:29:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbjBGH3Z (ORCPT ); Tue, 7 Feb 2023 02:29:25 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9622036086 for ; Mon, 6 Feb 2023 23:29:23 -0800 (PST) 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 3CC2633AF4; Tue, 7 Feb 2023 07:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675754962; 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=t8iNxepBulbWBgnAjdjtTKND+wFOVAwDCXZSevLudto=; b=Rq9h6mL+GTP/xnNyQnFdDsiIX+OQFnbl36tCwnJMdbwQvxr1N0kws9YN6BmImuHXn1JItC IIx/ndq4Q045WM2t2P6/NFeSRfczbTnJ7931JE1mX4jojk+bgyXvfiN5SHSH0NLWq0irZQ c21gnfbm/eoEHlaEEYJmvju92DYm1h4= 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 DBBD113A8C; Tue, 7 Feb 2023 07:29:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id tUFjNNH94WO+UQAAMHmgww (envelope-from ); Tue, 07 Feb 2023 07:29:21 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH 3/6] x86/mtrr: revert commit 90b926e68f50 Date: Tue, 7 Feb 2023 08:28:59 +0100 Message-Id: <20230207072902.5528-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230207072902.5528-1-jgross@suse.com> References: <20230207072902.5528-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" Commit 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case") has introduced a regression with Xen. Revert the patch. Signed-off-by: Juergen Gross --- arch/x86/mm/pat/memtype.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 18f612b43763..2c6d95f95b49 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -387,8 +387,7 @@ static unsigned long pat_x_mtrr_type(u64 start, u64 end, u8 mtrr_type, uniform; =20 mtrr_type =3D mtrr_type_lookup(start, end, &uniform); - if (mtrr_type !=3D MTRR_TYPE_WRBACK && - mtrr_type !=3D MTRR_TYPE_INVALID) + if (mtrr_type !=3D MTRR_TYPE_WRBACK) return _PAGE_CACHE_MODE_UC_MINUS; =20 return _PAGE_CACHE_MODE_WB; --=20 2.35.3 From nobody Sat Sep 13 00:05:27 2025 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 2018DC636CD for ; Tue, 7 Feb 2023 07:29:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230289AbjBGH3p (ORCPT ); Tue, 7 Feb 2023 02:29:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjBGH3i (ORCPT ); Tue, 7 Feb 2023 02:29:38 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 728B6360B3 for ; Mon, 6 Feb 2023 23:29:29 -0800 (PST) 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-out2.suse.de (Postfix) with ESMTPS id E5D1960F1F; Tue, 7 Feb 2023 07:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675754967; 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=FL8lZ8VzNgVUhkoi8dmft+rrAn+Q6LoB7UFRnauUMu0=; b=dVFX1eOAI+AHMp/mXW02giADSuEANXVa3rEQogBIx/Qwagzw60RQaeO9BHKPUtVaTXgtfX C4zJ64w+HEu6kN8neiYYSg/4W6pAfUK2jWRY1TqABNawzFK0zT6xMk69o4yH321E9wgtBA sAewnLXp/xK10S7tEq5PljbDHH7OAkY= 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 97EE413A8C; Tue, 7 Feb 2023 07:29:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Cmm0I9f94WPQUQAAMHmgww (envelope-from ); Tue, 07 Feb 2023 07:29:27 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 4/6] x86/mtrr: don't let mtrr_type_lookup() return MTRR_TYPE_INVALID Date: Tue, 7 Feb 2023 08:29:00 +0100 Message-Id: <20230207072902.5528-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230207072902.5528-1-jgross@suse.com> References: <20230207072902.5528-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" mtrr_type_lookup() should always return a valid memory type. In case there is no information available, it should return the default UC. 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 --- arch/x86/include/asm/mtrr.h | 7 +++++-- arch/x86/kernel/cpu/mtrr/generic.c | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h index 29ec2d6f0537..c12c73d48f08 100644 --- a/arch/x86/include/asm/mtrr.h +++ b/arch/x86/include/asm/mtrr.h @@ -57,9 +57,12 @@ static inline bool mtrr_enabled(void) 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/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/= generic.c index ee09d359e08f..c749ec4436a1 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -262,10 +262,10 @@ u8 mtrr_type_lookup(u64 start, u64 end, u8 *uniform) end--; =20 if (!mtrr_state_set) - return MTRR_TYPE_INVALID; + return MTRR_TYPE_UNCACHABLE; =20 if (!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED)) - return MTRR_TYPE_INVALID; + return MTRR_TYPE_UNCACHABLE; =20 /* * Look up the fixed ranges first, which take priority over --=20 2.35.3 From nobody Sat Sep 13 00:05:27 2025 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 3BB35C636CD for ; Tue, 7 Feb 2023 07:30:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbjBGHaA (ORCPT ); Tue, 7 Feb 2023 02:30:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbjBGH3n (ORCPT ); Tue, 7 Feb 2023 02:29:43 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E88B37B59 for ; Mon, 6 Feb 2023 23:29:35 -0800 (PST) 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 AD38333E13; Tue, 7 Feb 2023 07:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675754973; 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=JQKD/lPKkbb0qc+8vhUXutdmkqWMq0MqdsxYYVlo8yw=; b=rhN5jlM6O0ZsxdaBTemQtSJgkBZPcxAZaNNtQJLq5Ihc0NbsHPi20j4I7fjRtIto2K4d4X zIDf3658nAGwSKwguO4O/FDqknFHsNoGM589ogc/tD0JkZ0n9T3dret8xtcVctvZFUQg5h qphoyoKo95W/LGOBbq3SIF1tfcz1TUM= 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 54F1713A8C; Tue, 7 Feb 2023 07:29:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 83VgE9394WPaUQAAMHmgww (envelope-from ); Tue, 07 Feb 2023 07:29:33 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH 5/6] x86/mm: only check uniform after calling mtrr_type_lookup() Date: Tue, 7 Feb 2023 08:29:01 +0100 Message-Id: <20230207072902.5528-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230207072902.5528-1-jgross@suse.com> References: <20230207072902.5528-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" Today pud_set_huge() and pmd_set_huge() test for the MTRR type to be WB or INVALID after calling mtrr_type_lookup(). Those tests can be dropped, as the only reason to not use a large mapping would be uniform being 0. Any MTRR type can be accepted as long as it applies to the whole memory range covered by the mapping, as the alternative would only be to map the same region with smaller pages instead using the same PAT type as for the large mapping. Suggested-by: Linus Torvalds Signed-off-by: Juergen Gross --- arch/x86/mm/pgtable.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index e4f499eb0f29..7b9c5443d176 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -721,8 +721,7 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t= prot) u8 mtrr, uniform; =20 mtrr =3D mtrr_type_lookup(addr, addr + PUD_SIZE, &uniform); - if ((mtrr !=3D MTRR_TYPE_INVALID) && (!uniform) && - (mtrr !=3D MTRR_TYPE_WRBACK)) + if (!uniform) return 0; =20 /* Bail out if we are we on a populated non-leaf entry: */ @@ -748,8 +747,7 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t= prot) u8 mtrr, uniform; =20 mtrr =3D mtrr_type_lookup(addr, addr + PMD_SIZE, &uniform); - if ((mtrr !=3D MTRR_TYPE_INVALID) && (!uniform) && - (mtrr !=3D MTRR_TYPE_WRBACK)) { + if (!uniform) { pr_warn_once("%s: Cannot satisfy [mem %#010llx-%#010llx] with a huge-pag= e mapping due to MTRR override.\n", __func__, addr, addr + PMD_SIZE); return 0; --=20 2.35.3 From nobody Sat Sep 13 00:05:27 2025 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 5E5CFC636CD for ; Tue, 7 Feb 2023 07:30:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230079AbjBGHaE (ORCPT ); Tue, 7 Feb 2023 02:30:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230401AbjBGH3v (ORCPT ); Tue, 7 Feb 2023 02:29:51 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2FDA3525B for ; Mon, 6 Feb 2023 23:29:40 -0800 (PST) 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 7003333AEE; Tue, 7 Feb 2023 07:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675754979; 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=8efLSwTwFHqSKPYOUuhtVE2c23rg89tSCfxytpWfroA=; b=Fns5WTkkkQ6yqDv5E+lCxZqrmv7sKPqKMzeVV0ljqwpWsuYhjG83UIs3erUJ7mKFm/pVnp 7HoSHoCrjBQU3f7W/Juzu1+E/kX/5V3bnWHVoqSHxcibyBySOaFL9ezuHhWE9r+KrNi8Sp kLCOxl88lfOFxtr9fM3JbCva+/LFMfQ= 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 1D04E13A8C; Tue, 7 Feb 2023 07:29:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Noq+BeP94WPpUQAAMHmgww (envelope-from ); Tue, 07 Feb 2023 07:29:39 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 6/6] x86/mtrr: drop sanity check in mtrr_type_lookup_fixed() Date: Tue, 7 Feb 2023 08:29:02 +0100 Message-Id: <20230207072902.5528-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230207072902.5528-1-jgross@suse.com> References: <20230207072902.5528-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" mtrr_type_lookup_fixed() contains a sanity check for the case it is being called with a start address above 1 MB. As it is static and it is called only iff the start address is below 1MB, this sanity check can be dropped. 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. Signed-off-by: Juergen Gross --- arch/x86/include/uapi/asm/mtrr.h | 6 +++--- arch/x86/kernel/cpu/mtrr/generic.c | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/uapi/asm/mtrr.h b/arch/x86/include/uapi/asm/m= trr.h index 376563f2bac1..4aa05c2ffa78 100644 --- a/arch/x86/include/uapi/asm/mtrr.h +++ b/arch/x86/include/uapi/asm/mtrr.h @@ -115,9 +115,9 @@ struct mtrr_state_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 c749ec4436a1..c17cb00aac6a 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -114,16 +114,12 @@ static int check_type_overlap(u8 *prev, u8 *curr) * 0xC0000 - 0xFFFFF : This range is divided into sixty-four 4KB sub-rang= es * * Return Values: - * MTRR_TYPE_(type) - Matched memory type - * MTRR_TYPE_INVALID - Unmatched + * MTRR_TYPE_(type) - Memory type */ static u8 mtrr_type_lookup_fixed(u64 start, u64 end) { int idx; =20 - if (start >=3D 0x100000) - return MTRR_TYPE_INVALID; - /* 0x0 - 0x7FFFF */ if (start < 0x80000) { idx =3D 0; --=20 2.35.3