forked from rpms/qemu-kvm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.6 KiB
128 lines
4.6 KiB
From 2872c423fa44dcbf50b581a5c3feac064a0473a0 Mon Sep 17 00:00:00 2001
|
|
From: Michael Roth <michael.roth@amd.com>
|
|
Date: Tue, 9 Apr 2024 18:07:41 -0500
|
|
Subject: [PATCH 024/100] i386/sev: Add 'legacy-vm-type' parameter for SEV
|
|
guest objects
|
|
|
|
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
RH-MergeRequest: 245: SEV-SNP support
|
|
RH-Jira: RHEL-39544
|
|
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
RH-Acked-by: Bandan Das <bdas@redhat.com>
|
|
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
|
|
RH-Commit: [24/91] ce35d1b09fe8aa8772ff149543f7760455c1e6b5 (bonzini/rhel-qemu-kvm)
|
|
|
|
QEMU will currently automatically make use of the KVM_SEV_INIT2 API for
|
|
initializing SEV and SEV-ES guests verses the older
|
|
KVM_SEV_INIT/KVM_SEV_ES_INIT interfaces.
|
|
|
|
However, the older interfaces will silently avoid sync'ing FPU/XSAVE
|
|
state to the VMSA prior to encryption, thus relying on behavior and
|
|
measurements that assume the related fields to be allow zero.
|
|
|
|
With KVM_SEV_INIT2, this state is now synced into the VMSA, resulting in
|
|
measurements changes and, theoretically, behaviorial changes, though the
|
|
latter are unlikely to be seen in practice.
|
|
|
|
To allow a smooth transition to the newer interface, while still
|
|
providing a mechanism to maintain backward compatibility with VMs
|
|
created using the older interfaces, provide a new command-line
|
|
parameter:
|
|
|
|
-object sev-guest,legacy-vm-type=true,...
|
|
|
|
and have it default to false.
|
|
|
|
Signed-off-by: Michael Roth <michael.roth@amd.com>
|
|
Message-ID: <20240409230743.962513-2-michael.roth@amd.com>
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
(cherry picked from commit 023267334da375226720e62963df9545aa8fc2fd)
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
---
|
|
qapi/qom.json | 11 ++++++++++-
|
|
target/i386/sev.c | 18 +++++++++++++++++-
|
|
2 files changed, 27 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/qapi/qom.json b/qapi/qom.json
|
|
index 85e6b4f84a..38dde6d785 100644
|
|
--- a/qapi/qom.json
|
|
+++ b/qapi/qom.json
|
|
@@ -898,6 +898,14 @@
|
|
# designated guest firmware page for measured boot with -kernel
|
|
# (default: false) (since 6.2)
|
|
#
|
|
+# @legacy-vm-type: Use legacy KVM_SEV_INIT KVM interface for creating the VM.
|
|
+# The newer KVM_SEV_INIT2 interface syncs additional vCPU
|
|
+# state when initializing the VMSA structures, which will
|
|
+# result in a different guest measurement. Set this to
|
|
+# maintain compatibility with older QEMU or kernel versions
|
|
+# that rely on legacy KVM_SEV_INIT behavior.
|
|
+# (default: false) (since 9.1)
|
|
+#
|
|
# Since: 2.12
|
|
##
|
|
{ 'struct': 'SevGuestProperties',
|
|
@@ -908,7 +916,8 @@
|
|
'*handle': 'uint32',
|
|
'*cbitpos': 'uint32',
|
|
'reduced-phys-bits': 'uint32',
|
|
- '*kernel-hashes': 'bool' } }
|
|
+ '*kernel-hashes': 'bool',
|
|
+ '*legacy-vm-type': 'bool' } }
|
|
|
|
##
|
|
# @ThreadContextProperties:
|
|
diff --git a/target/i386/sev.c b/target/i386/sev.c
|
|
index 9dab4060b8..f4ee317cb0 100644
|
|
--- a/target/i386/sev.c
|
|
+++ b/target/i386/sev.c
|
|
@@ -67,6 +67,7 @@ struct SevGuestState {
|
|
uint32_t cbitpos;
|
|
uint32_t reduced_phys_bits;
|
|
bool kernel_hashes;
|
|
+ bool legacy_vm_type;
|
|
|
|
/* runtime state */
|
|
uint32_t handle;
|
|
@@ -356,6 +357,16 @@ static void sev_guest_set_kernel_hashes(Object *obj, bool value, Error **errp)
|
|
sev->kernel_hashes = value;
|
|
}
|
|
|
|
+static bool sev_guest_get_legacy_vm_type(Object *obj, Error **errp)
|
|
+{
|
|
+ return SEV_GUEST(obj)->legacy_vm_type;
|
|
+}
|
|
+
|
|
+static void sev_guest_set_legacy_vm_type(Object *obj, bool value, Error **errp)
|
|
+{
|
|
+ SEV_GUEST(obj)->legacy_vm_type = value;
|
|
+}
|
|
+
|
|
bool
|
|
sev_enabled(void)
|
|
{
|
|
@@ -863,7 +874,7 @@ static int sev_kvm_type(X86ConfidentialGuest *cg)
|
|
}
|
|
|
|
kvm_type = (sev->policy & SEV_POLICY_ES) ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM;
|
|
- if (kvm_is_vm_type_supported(kvm_type)) {
|
|
+ if (kvm_is_vm_type_supported(kvm_type) && !sev->legacy_vm_type) {
|
|
sev->kvm_type = kvm_type;
|
|
} else {
|
|
sev->kvm_type = KVM_X86_DEFAULT_VM;
|
|
@@ -1381,6 +1392,11 @@ sev_guest_class_init(ObjectClass *oc, void *data)
|
|
sev_guest_set_kernel_hashes);
|
|
object_class_property_set_description(oc, "kernel-hashes",
|
|
"add kernel hashes to guest firmware for measured Linux boot");
|
|
+ object_class_property_add_bool(oc, "legacy-vm-type",
|
|
+ sev_guest_get_legacy_vm_type,
|
|
+ sev_guest_set_legacy_vm_type);
|
|
+ object_class_property_set_description(oc, "legacy-vm-type",
|
|
+ "use legacy VM type to maintain measurement compatibility with older QEMU or kernel versions.");
|
|
}
|
|
|
|
static void
|
|
--
|
|
2.39.3
|
|
|