From nobody Sun Feb 8 05:17:34 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 31231C46467 for ; Tue, 10 Jan 2023 06:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbjAJGyl (ORCPT ); Tue, 10 Jan 2023 01:54:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjAJGyb (ORCPT ); Tue, 10 Jan 2023 01:54:31 -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 EC1666329 for ; Mon, 9 Jan 2023 22:54:30 -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 0DAFB4DF19; Tue, 10 Jan 2023 06:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673333669; 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; bh=EY5VTFqEZnBurGAFOn7Hf0q4d99CjK26BXkX9qKxYzI=; b=uCasEm8pmLDgbmNRkOO2o0yoCwC7zvpOG0NPvrbSwLbuuhPWzB8Y+xF4BgoTJNpEq4fNEl cVL/mwX0zuB609+SoTlHs2FvOyGoa97lYSQ/H9iAnpAJ0KtmnvKMbpy6N627DNzF03jEpU VaKzrQAXDZLB0BG5xT8xAo2QysnUvOE= 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 B049113338; Tue, 10 Jan 2023 06:54:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id z5GqKaQLvWN4YQAAMHmgww (envelope-from ); Tue, 10 Jan 2023 06:54:28 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: mikelley@microsoft.com, Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH] x86/pat: fix pat_x_mtrr_type() for MTRR disabled case Date: Tue, 10 Jan 2023 07:54:27 +0100 Message-Id: <20230110065427.20767-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 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" Since commit 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen") PAT can be enabled without MTRR. This has resulted in problems e.g. for a SEV-SNP guest running under Hyper-V, when trying to establish a new mapping via memremap() with WB caching mode, as pat_x_mtrr_type() will call mtrr_type_lookup(), which in turn is returning MTRR_TYPE_INVALID due to MTRR being disabled in this configuration. The result is a mapping with UC- caching, leading to severe performance degradation. Fix that by handling MTRR_TYPE_INVALID the same way as MTRR_TYPE_WRBACK in pat_x_mtrr_type(). Fixes: 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state wh= en running on Xen") Reported-by: Michael Kelley (LINUX) Signed-off-by: Juergen Gross Reviewed-by: Michael Kelley Tested-by: Michael Kelley --- arch/x86/mm/pat/memtype.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 46de9cf5c91d..fb4b1b5e0dea 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -387,7 +387,8 @@ 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) + if (mtrr_type !=3D MTRR_TYPE_WRBACK && + mtrr_type !=3D MTRR_TYPE_INVALID) return _PAGE_CACHE_MODE_UC_MINUS; =20 return _PAGE_CACHE_MODE_WB; --=20 2.35.3