From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: michael.roth@amd.com, zixchen@redhat.com
Subject: [RFC PATCH 2/2] target/i386/SEV: implement mask_cpuid_features
Date: Wed, 3 Jul 2024 13:01:34 +0200 [thread overview]
Message-ID: <20240703110134.1645979-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20240703110134.1645979-1-pbonzini@redhat.com>
SNP firmware rejects several features that KVM implements without needing
hardware support. If these are specified, for example with "-cpu host",
the guest will fail to start.
I am marking this as RFC because it's not future proof. If in the future
AMD processors do provide any of these bits, this is going to break
(tsc_deadline and tsc_adjust are the most likely one). Including the
bits if they are present in host CPUID is not super safe either, since
the firmware might not be updated to follow suit.
Reported-by: Zixi Chen <zixchen@redhat.com>
Not-quite-signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/cpu.h | 4 ++++
target/i386/sev.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 9bea7142bf4..31c9b43849e 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -812,6 +812,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);
/* Support RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE */
#define CPUID_7_0_EBX_FSGSBASE (1U << 0)
+/* Support TSC adjust MSR */
+#define CPUID_7_0_EBX_TSC_ADJUST (1U << 1)
/* Support SGX */
#define CPUID_7_0_EBX_SGX (1U << 2)
/* 1st Group of Advanced Bit Manipulation Extensions */
@@ -1002,6 +1004,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);
#define CPUID_8000_0008_EBX_STIBP_ALWAYS_ON (1U << 17)
/* Speculative Store Bypass Disable */
#define CPUID_8000_0008_EBX_AMD_SSBD (1U << 24)
+/* Paravirtualized Speculative Store Bypass Disable MSR */
+#define CPUID_8000_0008_EBX_VIRT_SSBD (1U << 25)
/* Predictive Store Forwarding Disable */
#define CPUID_8000_0008_EBX_AMD_PSFD (1U << 28)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 2a0f94d390d..280eaef8723 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -945,6 +945,38 @@ out:
return ret;
}
+static uint32_t
+sev_snp_mask_cpuid_features(X86ConfidentialGuest *cg, uint32_t feature, uint32_t index,
+ int reg, uint32_t value)
+{
+ switch (feature) {
+ case 1:
+ if (reg == R_ECX) {
+ return value & ~CPUID_EXT_TSC_DEADLINE_TIMER;
+ }
+ break;
+ case 7:
+ if (index == 0 && reg == R_EBX) {
+ return value & ~CPUID_7_0_EBX_TSC_ADJUST;
+ }
+ if (index == 0 && reg == R_EDX) {
+ return value & ~(CPUID_7_0_EDX_SPEC_CTRL |
+ CPUID_7_0_EDX_STIBP |
+ CPUID_7_0_EDX_FLUSH_L1D |
+ CPUID_7_0_EDX_ARCH_CAPABILITIES |
+ CPUID_7_0_EDX_CORE_CAPABILITY |
+ CPUID_7_0_EDX_SPEC_CTRL_SSBD);
+ }
+ break;
+ case 0x80000008:
+ if (reg == R_EBX) {
+ return value & ~CPUID_8000_0008_EBX_VIRT_SSBD;
+ }
+ break;
+ }
+ return value;
+}
+
static int
sev_launch_update_data(SevCommonState *sev_common, hwaddr gpa,
uint8_t *addr, size_t len)
@@ -2315,6 +2347,7 @@ sev_snp_guest_class_init(ObjectClass *oc, void *data)
klass->launch_finish = sev_snp_launch_finish;
klass->launch_update_data = sev_snp_launch_update_data;
klass->kvm_init = sev_snp_kvm_init;
+ x86_klass->mask_cpuid_features = sev_snp_mask_cpuid_features;
x86_klass->kvm_type = sev_snp_kvm_type;
object_class_property_add(oc, "policy", "uint64",
--
2.45.2
next prev parent reply other threads:[~2024-07-03 11:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 11:01 [RFC PATCH 0/2] target/i386: SEV: allow running SNP guests with "-cpu host" Paolo Bonzini
2024-07-03 11:01 ` [RFC PATCH 1/2] target/i386: add support for masking CPUID features in confidential guests Paolo Bonzini
2024-07-03 11:01 ` Paolo Bonzini [this message]
2024-07-04 0:26 ` [RFC PATCH 0/2] target/i386: SEV: allow running SNP guests with "-cpu host" Michael Roth
2024-07-04 5:46 ` Paolo Bonzini
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=20240703110134.1645979-3-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=michael.roth@amd.com \
--cc=qemu-devel@nongnu.org \
--cc=zixchen@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).