From: Tom Lendacky <thomas.lendacky@amd.com>
To: Dionna Amalie Glaze <dionnaglaze@google.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Michael Roth <michael.roth@amd.com>,
Ashish Kalra <ashish.kalra@amd.com>
Subject: Re: [PATCH] x86/sev: Fix SNP CPUID requests to the hypervisor
Date: Tue, 1 Aug 2023 16:31:57 -0500 [thread overview]
Message-ID: <e9213337-65a6-c8ae-05d9-ca6838278597@amd.com> (raw)
In-Reply-To: <CAAH4kHb-7vjsKYQ-JyHZDyKzX857iN+5K1yY9AC9O2yHyBM35w@mail.gmail.com>
On 7/31/23 22:58, Dionna Amalie Glaze wrote:
>> Fixes: ee0bfa08a345 ("x86/compressed/64: Add support for SEV-SNP CPUID table in #VC handlers")
>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
>
> Nice catch.
>
>> +static int __sev_cpuid_hv_ghcb(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_leaf *leaf)
>> +{
>> + u32 cr4 = native_read_cr4();
>> + int ret;
>> +
>> + ghcb_set_rax(ghcb, leaf->fn);
>> + ghcb_set_rcx(ghcb, leaf->subfn);
>> +
>> + if (cr4 & X86_CR4_OSXSAVE)
>> + /* Safe to read xcr0 */
>> + ghcb_set_xcr0(ghcb, xgetbv(XCR_XFEATURE_ENABLED_MASK));
>> + else
>> + /* xgetbv will cause #GP - use reset value for xcr0 */
>> + ghcb_set_xcr0(ghcb, 1);
>> +
>
> Everything looks good except I'm confused by this last comment. I
> thought xgetbv would #UD if OSXSAVE isn't set in cr4. Is that what
> happens after you set it to 1 as some kind of workaround?
Yes, after checking the APM, it would #UD. This code was copied from the
existing CPUID #VC support. Not sure it requires a new version or if the
maintainers could fix it up when applying.
Thanks,
Tom
>
> ....oh I think I do remember hitting this weird technicality when
> setting up CPUID support. I think it'd be helpful to document a little
> bit more why the ghcb's value is xcr0 is relevant at all when cr4's
> OSXSAVE bit is 0 though.
>
>
prev parent reply other threads:[~2023-08-01 21:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 21:09 Tom Lendacky
2023-08-01 3:58 ` Dionna Amalie Glaze
2023-08-01 21:31 ` Tom Lendacky [this message]
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=e9213337-65a6-c8ae-05d9-ca6838278597@amd.com \
--to=thomas.lendacky@amd.com \
--cc=ashish.kalra@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dionnaglaze@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--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®