Message ID | 20230209072220.6836-4-jgross@suse.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp186540wrn; Wed, 8 Feb 2023 23:23:50 -0800 (PST) X-Google-Smtp-Source: AK7set+syt+5qemY0IBYkCtGr7hNTQQ8uoH5AU5W9bvhOfRp8NaMuPg6CrW1A4qe5fJXX9EwExgg X-Received: by 2002:a17:906:99ca:b0:8af:3e14:583b with SMTP id s10-20020a17090699ca00b008af3e14583bmr719841ejn.18.1675927429983; Wed, 08 Feb 2023 23:23:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675927429; cv=none; d=google.com; s=arc-20160816; b=IxylHZWM/PQMLZ4CrkSx5fhla2OEaJ1iBRlrKXaEFZXZpaVADl8bTU3zSWtqVvT21O yhRI0EEru+ITWpDJFIeph91iBFglIulka5vCR5tL6w3p6/tT/IQ/ac/RcjkORPuPwzKg 11CzRcqQTzcB8kk6btK3gm1GqrcZ6IGkjqs2Q3IXZBMJtryYIu1eRIEWrI+UOzJAfATy 297PhRetyn8Eh6i67Ym34loMyYgnWL+o8ZKNLUSvChRGpw3lZ/cOWO/F5vqOI/636Ytu t8yBma5kRqp5XdvnfExM7X27xoO89KG/GP3vYUkrdXUO7Kw2j7XNVuNi9hOSYp/8uGR2 hshw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zyHEmKeSFHe5+oN4UisgzjtUbIgCf4lrIbd7KednrR0=; b=JzvWcplLRAyNGw5b1Vr4BX99keuywfARFgfQkv6UsdOnBX2TGeL5J11jMdg8oWSqW4 1+iy0dTANQwu57L6yE1AZWPNasBiOb95fzSi0kxOz7+KBB6R6FNW6cV/6MIfFBnJ8JMq rRqB680HU0owYnwqiVFfn4+Y+pKiJNuOxd6+LM0NqxJ9sLOrptmevwtAC8WpYacmZCkK 7jJoXr/2T1MqMdg++NHiYvkOc+zGPjzwl1zyA7WTy2zsKxsJlVr/KND+k1RpBYvJ1W2x 5PuJNA1VsRXDQt33NZj/cFsRPcVqEnZkhHjGX5dM+fee4gkH5gs1HVLGKXnjyAtcURj+ rUcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=k4aWSkE2; 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 12-20020a170906224c00b0087a6a62dd48si1971894ejr.297.2023.02.08.23.23.27; Wed, 08 Feb 2023 23:23:49 -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=k4aWSkE2; 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 S229671AbjBIHXN (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Thu, 9 Feb 2023 02:23:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229788AbjBIHXJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Feb 2023 02:23:09 -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 C85241EBC1; Wed, 8 Feb 2023 23:22:41 -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 7DDD75C221; Thu, 9 Feb 2023 07:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675927360; 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=zyHEmKeSFHe5+oN4UisgzjtUbIgCf4lrIbd7KednrR0=; b=k4aWSkE2BdtZFM8V//WNQjG7991Som7Xdthx3JxwnltctXG4G560YCzM645blnAk5C0FSS dJNKo7/JR5JdWeVZi3grOarBdIRkBuONkWYEoPOKCNkJwSTASjeXt1BQ4CDGaZwVjFKYx+ E7kDdY95qpv+pxR1L9jYpElSa/0WIjc= 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 1FDF71339E; Thu, 9 Feb 2023 07:22:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iS6GBkCf5GP6eAAAMHmgww (envelope-from <jgross@suse.com>); Thu, 09 Feb 2023 07:22:40 +0000 From: Juergen Gross <jgross@suse.com> To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hyperv@vger.kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross <jgross@suse.com>, "K. Y. Srinivasan" <kys@microsoft.com>, Haiyang Zhang <haiyangz@microsoft.com>, Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, "H. Peter Anvin" <hpa@zytor.com> Subject: [PATCH v2 3/8] x86/hyperv: set MTRR state when running as SEV-SNP Hyper-V guest Date: Thu, 9 Feb 2023 08:22:15 +0100 Message-Id: <20230209072220.6836-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230209072220.6836-1-jgross@suse.com> References: <20230209072220.6836-1-jgross@suse.com> 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?1757337280595281211?= X-GMAIL-MSGID: =?utf-8?q?1757337280595281211?= |
Series |
x86/mtrr: fix handling with PAT but without MTRR
|
|
Commit Message
Juergen Gross
Feb. 9, 2023, 7:22 a.m. UTC
In order to avoid mappings using the UC- cache attribute, set the
MTRR state to use WB caching as the default.
This is needed in order to cope with the fact that PAT is enabled,
while MTRRs are disabled by the hypervisor.
Fixes: 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case")
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- new patch
---
arch/x86/kernel/cpu/mshyperv.c | 8 ++++++++
1 file changed, 8 insertions(+)
Comments
From: Juergen Gross <jgross@suse.com> Sent: Wednesday, February 8, 2023 11:22 PM > > In order to avoid mappings using the UC- cache attribute, set the > MTRR state to use WB caching as the default. > > This is needed in order to cope with the fact that PAT is enabled, > while MTRRs are disabled by the hypervisor. > > Fixes: 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case") > Signed-off-by: Juergen Gross <jgross@suse.com> > --- > V2: > - new patch > --- > arch/x86/kernel/cpu/mshyperv.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c > index 46668e255421..51e47dc0e987 100644 > --- a/arch/x86/kernel/cpu/mshyperv.c > +++ b/arch/x86/kernel/cpu/mshyperv.c > @@ -34,6 +34,7 @@ > #include <clocksource/hyperv_timer.h> > #include <asm/numa.h> > #include <asm/coco.h> > +#include <asm/mtrr.h> > > /* Is Linux running as the root partition? */ > bool hv_root_partition; > @@ -335,6 +336,13 @@ static void __init ms_hyperv_init_platform(void) > static_branch_enable(&isolation_type_snp); > #ifdef CONFIG_SWIOTLB > swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; > +#endif Unfortunately, Hyper-V does not filter out the MTRR flag from the CPUID leaf, so this code also needs setup_clear_cpu_cap(X86_FEATURE_MTRR); before calling mtrr_overwrite_state(). I've got a bug filed for the Hyper-V team to fix the flag, but clearing the feature here solves the problem regardless. > +#ifdef CONFIG_MTRR Hopefully this #ifdef can go away, per my comment in Patch 2 of the series. Michael > + /* > + * Set WB as the default cache mode in case MTRRs are > + * disabled by the hypervisor. > + */ > + mtrr_overwrite_state(NULL, 0, NULL, MTRR_TYPE_WRBACK); > #endif > } > /* Isolation VMs are unenlightened SEV-based VMs, thus this check: */ > -- > 2.35.3
On 13.02.23 02:07, Michael Kelley (LINUX) wrote: > From: Juergen Gross <jgross@suse.com> Sent: Wednesday, February 8, 2023 11:22 PM >> >> In order to avoid mappings using the UC- cache attribute, set the >> MTRR state to use WB caching as the default. >> >> This is needed in order to cope with the fact that PAT is enabled, >> while MTRRs are disabled by the hypervisor. >> >> Fixes: 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case") >> Signed-off-by: Juergen Gross <jgross@suse.com> >> --- >> V2: >> - new patch >> --- >> arch/x86/kernel/cpu/mshyperv.c | 8 ++++++++ >> 1 file changed, 8 insertions(+) >> >> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c >> index 46668e255421..51e47dc0e987 100644 >> --- a/arch/x86/kernel/cpu/mshyperv.c >> +++ b/arch/x86/kernel/cpu/mshyperv.c >> @@ -34,6 +34,7 @@ >> #include <clocksource/hyperv_timer.h> >> #include <asm/numa.h> >> #include <asm/coco.h> >> +#include <asm/mtrr.h> >> >> /* Is Linux running as the root partition? */ >> bool hv_root_partition; >> @@ -335,6 +336,13 @@ static void __init ms_hyperv_init_platform(void) >> static_branch_enable(&isolation_type_snp); >> #ifdef CONFIG_SWIOTLB >> swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; >> +#endif > > Unfortunately, Hyper-V does not filter out the MTRR flag from the > CPUID leaf, so this code also needs > > setup_clear_cpu_cap(X86_FEATURE_MTRR); > > before calling mtrr_overwrite_state(). I've got a bug filed for the > Hyper-V team to fix the flag, but clearing the feature here solves the > problem regardless. Okay, will add it. > >> +#ifdef CONFIG_MTRR > > Hopefully this #ifdef can go away, per my comment in Patch 2 of > the series. As said already, fine with me. Juergen
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 46668e255421..51e47dc0e987 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -34,6 +34,7 @@ #include <clocksource/hyperv_timer.h> #include <asm/numa.h> #include <asm/coco.h> +#include <asm/mtrr.h> /* Is Linux running as the root partition? */ bool hv_root_partition; @@ -335,6 +336,13 @@ static void __init ms_hyperv_init_platform(void) static_branch_enable(&isolation_type_snp); #ifdef CONFIG_SWIOTLB swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; +#endif +#ifdef CONFIG_MTRR + /* + * Set WB as the default cache mode in case MTRRs are + * disabled by the hypervisor. + */ + mtrr_overwrite_state(NULL, 0, NULL, MTRR_TYPE_WRBACK); #endif } /* Isolation VMs are unenlightened SEV-based VMs, thus this check: */