Message ID | 20230110065427.20767-1-jgross@suse.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2591883wrt; Mon, 9 Jan 2023 22:56:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXuqo35QNQNRQEugjTj30mc1+XQkSmrq6ZOFR075t8dxyVdK+GGJtCB3XM3Yq0bPZToR+njq X-Received: by 2002:a17:902:e845:b0:186:7a6b:dcdb with SMTP id t5-20020a170902e84500b001867a6bdcdbmr88946914plg.40.1673333819289; Mon, 09 Jan 2023 22:56:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673333819; cv=none; d=google.com; s=arc-20160816; b=tnmgVb4WhUV3C68rGfCzlTYQAGoJ2H35uBWNz+MZhUQfK/GyL1K5CfnTr3TcDBiTjS wyjBuPy4EUA5pdQ5ZOvjeDCuYkq8eRnuUDpw/W3iHMmdSglR+UiLdAEdFmFWLTmNJtzM azo3bjxl5jTkuPrXZNgDMvX118vMs3ARRzmfnrM9xCmoB6pbKS9hvRpXV5dbfMD5Tbdx t4wnbLvgzLV9tgsmfhn8cvoFLuPEZffl/8Eu71etezhV3r8QSIxRbd+KF53hqXzGo2qZ TfcpMCzAuh+z51hI4+KdlqI0vTk6AZtoR1AiG0WwX1Ee+XoC12gRT02T+iESFgD3/uHB fGSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=EY5VTFqEZnBurGAFOn7Hf0q4d99CjK26BXkX9qKxYzI=; b=KZzPshiVSgvLgJIW447DAQ4SsFAd1R+hyTHOIQ+LzT0YJIcSV6ZX29FqUMDMxXS+i7 K6T4y6xtXch9N1iHtrE7VY7JM2EZUk2PcJG2hFSEWhi+qhXLGjUrUGo/bTgWlaIGP5bf 1Jdv7BKsEybG7gmmgiyLzuHadIf04ZO3ddVLGHyJ9OkBEBKKZzQaKTu1jWZ4F1qA16NH LK7NIvN761zUGuhXJxQ/5kJl/XyxSM2vXIeuC4CokZrVeA8xHWWP0LbWCNzoMchJiq+B MfAS0hLBgS0kZl61f6YOUB25bYuCmAqpEUN8mGpmzspaWkrtDCNM8RGE2RYFbE1Ajg8i Cdfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=uCasEm8p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a4-20020a1709027d8400b00186892f9f29si9581223plm.488.2023.01.09.22.56.46; Mon, 09 Jan 2023 22:56:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=uCasEm8p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjAJGyi (ORCPT <rfc822;syz17693488234@gmail.com> + 99 others); Tue, 10 Jan 2023 01:54:38 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <jgross@suse.com>); Tue, 10 Jan 2023 06:54:28 +0000 From: Juergen Gross <jgross@suse.com> To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: mikelley@microsoft.com, Juergen Gross <jgross@suse.com>, Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com> 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: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754617682676232543?= X-GMAIL-MSGID: =?utf-8?q?1754617682676232543?= |
Series |
x86/pat: fix pat_x_mtrr_type() for MTRR disabled case
|
|
Commit Message
Juergen Gross
Jan. 10, 2023, 6:54 a.m. UTC
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 when running on Xen")
Reported-by: Michael Kelley (LINUX) <mikelley@microsoft.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
arch/x86/mm/pat/memtype.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
From: Juergen Gross <jgross@suse.com> Sent: Monday, January 9, 2023 10:54 PM > > 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 when running on Xen") > Reported-by: Michael Kelley (LINUX) <mikelley@microsoft.com> > Signed-off-by: Juergen Gross <jgross@suse.com> > --- > 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; > > mtrr_type = mtrr_type_lookup(start, end, &uniform); > - if (mtrr_type != MTRR_TYPE_WRBACK) > + if (mtrr_type != MTRR_TYPE_WRBACK && > + mtrr_type != MTRR_TYPE_INVALID) > return _PAGE_CACHE_MODE_UC_MINUS; > > return _PAGE_CACHE_MODE_WB; > -- > 2.35.3 This looks good to me. I've tested my specific use case of a SEV-SNP guest running under Hyper-V, where the MTRRs are not visible in the guest but the PAT is functional. Previously, this use case showed many "uncached-minus" entries in /sys/kernel/debug/x86/pat_memtype_list even though the mapping requests were made as WB. With this patch, those entries show "write-back", as expected. Thanks! Reviewed-by: Michael Kelley <mikelley@microsoft.com> Tested-by: Michael Kelley <mikelley@microsoft.com>
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; mtrr_type = mtrr_type_lookup(start, end, &uniform); - if (mtrr_type != MTRR_TYPE_WRBACK) + if (mtrr_type != MTRR_TYPE_WRBACK && + mtrr_type != MTRR_TYPE_INVALID) return _PAGE_CACHE_MODE_UC_MINUS; return _PAGE_CACHE_MODE_WB;