From: "Michael Kelley (LINUX)" <mikelley@microsoft.com>
To: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Jeremi Piotrowski <jpiotrowski@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Tianyu Lan <Tianyu.Lan@microsoft.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
Brijesh Singh <brijesh.singh@amd.com>,
Michael Roth <michael.roth@amd.com>,
Ashish Kalra <ashish.kalra@amd.com>,
Tom Lendacky <thomas.lendacky@amd.com>
Subject: RE: [RFC PATCH v1 4/6] x86/amd: Configure necessary MSRs for SNP during CPU init when running as a guest
Date: Sun, 29 Jan 2023 04:44:05 +0000 [thread overview]
Message-ID: <BYAPR21MB1688094AE8B2D0EA02A17335D7D29@BYAPR21MB1688.namprd21.prod.outlook.com> (raw)
In-Reply-To: <20230123165128.28185-5-jpiotrowski@linux.microsoft.com>
From: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> Sent: Monday, January 23, 2023 8:51 AM
>
> Hyper-V may expose the SEV/SEV-SNP CPU features to the guest, but it is
> up to the guest to use them. early_detect_mem_encrypt() checks
> SYSCFG[MEM_ENCRYPT] and HWCR[SMMLOCK] and if these are not set the
> SEV-SNP features are cleared. Check if we are running under a
> hypervisor and if so - update SYSCFG and skip the HWCR check.
>
> It would be great to make this check more specific (checking for
> Hyper-V) but this code runs before hypervisor detection on the boot cpu.
Could you elaborate on why we would want this check to be Hyper-V
specific? Per my comments on Patch 3 of this series, I would think the
opposite. If possible, we want code like this to work on any hypervisor,
and not have Hyper-V specific behavior in code outside of the Hyper-V
modules. But I don't know this code well at all, so maybe there's an
aspect I'm missing.
Michael
>
> Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com>
> ---
> arch/x86/kernel/cpu/amd.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
> index c7884198ad5b..17d91ac62937 100644
> --- a/arch/x86/kernel/cpu/amd.c
> +++ b/arch/x86/kernel/cpu/amd.c
> @@ -565,6 +565,12 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
> * don't advertise the feature under CONFIG_X86_32.
> */
> if (cpu_has(c, X86_FEATURE_SME) || cpu_has(c, X86_FEATURE_SEV)) {
> + if (cpu_has(c, X86_FEATURE_HYPERVISOR)) {
> + rdmsrl(MSR_AMD64_SYSCFG, msr);
> + msr |= MSR_AMD64_SYSCFG_MEM_ENCRYPT;
> + wrmsrl(MSR_AMD64_SYSCFG, msr);
> + }
> +
> /* Check if memory encryption is enabled */
> rdmsrl(MSR_AMD64_SYSCFG, msr);
> if (!(msr & MSR_AMD64_SYSCFG_MEM_ENCRYPT))
> @@ -584,7 +590,7 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
> setup_clear_cpu_cap(X86_FEATURE_SME);
>
> rdmsrl(MSR_K7_HWCR, msr);
> - if (!(msr & MSR_K7_HWCR_SMMLOCK))
> + if (!(msr & MSR_K7_HWCR_SMMLOCK) && !cpu_has(c, X86_FEATURE_HYPERVISOR))
> goto clear_sev;
>
> return;
> --
> 2.25.1
next prev parent reply other threads:[~2023-01-29 4:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-23 16:51 [RFC PATCH v1 0/6] Support nested SNP KVM guests on Hyper-V Jeremi Piotrowski
2023-01-23 16:51 ` [RFC PATCH v1 1/6] x86/hyperv: Allocate RMP table during boot Jeremi Piotrowski
2023-01-28 19:26 ` Michael Kelley (LINUX)
2023-01-30 15:03 ` Jeremi Piotrowski
2023-01-23 16:51 ` [RFC PATCH v1 2/6] x86/sev: Add support for NestedVirtSnpMsr Jeremi Piotrowski
2023-01-28 19:48 ` Michael Kelley (LINUX)
2023-01-30 15:25 ` Jeremi Piotrowski
2023-01-30 15:39 ` Michael Kelley (LINUX)
2023-01-23 16:51 ` [RFC PATCH v1 3/6] x86/sev: Maintain shadow rmptable on Hyper-V Jeremi Piotrowski
2023-01-29 4:37 ` Michael Kelley (LINUX)
2023-01-30 16:51 ` Jeremi Piotrowski
2023-01-23 16:51 ` [RFC PATCH v1 4/6] x86/amd: Configure necessary MSRs for SNP during CPU init when running as a guest Jeremi Piotrowski
2023-01-29 4:44 ` Michael Kelley (LINUX) [this message]
2023-01-30 17:25 ` Jeremi Piotrowski
2023-01-23 16:51 ` [RFC PATCH v1 5/6] iommu/amd: Don't fail snp_enable when running virtualized Jeremi Piotrowski
2023-01-23 16:51 ` [RFC PATCH v1 6/6] crypto: ccp - Introduce quirk to always reclaim pages after SEV-legacy commands Jeremi Piotrowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BYAPR21MB1688094AE8B2D0EA02A17335D7D29@BYAPR21MB1688.namprd21.prod.outlook.com \
--to=mikelley@microsoft.com \
--cc=Tianyu.Lan@microsoft.com \
--cc=ashish.kalra@amd.com \
--cc=bp@alien8.de \
--cc=brijesh.singh@amd.com \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=jpiotrowski@linux.microsoft.com \
--cc=jpiotrowski@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=wei.liu@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®