]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: process: sev: Fill missing 'cbitpos' & 'reducedPhysBits' from caps
authorErik Skultety <eskultet@redhat.com>
Thu, 8 Oct 2020 12:11:45 +0000 (14:11 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 19 Oct 2020 09:03:27 +0000 (11:03 +0200)
These XML attributes have been mandatory since the introduction of SEV
support to libvirt. This design decision was based on QEMU's
requirement for these to be mandatory for migration purposes, as
differences in these values across platforms must result in the
pre-migration checks failing (not that migration with SEV works at the
time of this patch).

This patch enables autofill of these attributes right before launching
QEMU and thus updating the live XML.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/conf/domain_conf.h
src/qemu/qemu_process.c

index 902dd58112c205f109a308bce2ed08eedcdf0ffb..cd344716a3e2bef4ddb699e0c459d6b12d6cc233 100644 (file)
@@ -2491,7 +2491,9 @@ struct _virDomainSEVDef {
     char *dh_cert;
     char *session;
     unsigned int policy;
+    bool haveCbitpos;
     unsigned int cbitpos;
+    bool haveReducedPhysBits;
     unsigned int reduced_phys_bits;
 };
 
index 16d6f54f6640848780667ad63a21b2610852e095..6422881a3349a6b0cf6f52338933243720f9582b 100644 (file)
@@ -6233,6 +6233,33 @@ qemuProcessPrepareAllowReboot(virDomainObjPtr vm)
 }
 
 
+static int
+qemuProcessUpdateSEVInfo(virDomainObjPtr vm)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virQEMUCapsPtr qemuCaps = priv->qemuCaps;
+    virDomainSEVDefPtr sev = vm->def->sev;
+    virSEVCapabilityPtr sevCaps = NULL;
+
+    /* if platform specific info like 'cbitpos' and 'reducedPhysBits' have
+     * not been supplied, we need to autofill them from caps now as both are
+     * mandatory on QEMU cmdline
+     */
+    sevCaps = virQEMUCapsGetSEVCapabilities(qemuCaps);
+    if (!sev->haveCbitpos) {
+        sev->cbitpos = sevCaps->cbitpos;
+        sev->haveCbitpos = true;
+    }
+
+    if (!sev->haveReducedPhysBits) {
+        sev->reduced_phys_bits = sevCaps->reduced_phys_bits;
+        sev->haveReducedPhysBits = true;
+    }
+
+    return 0;
+}
+
+
 /**
  * qemuProcessPrepareDomain:
  * @driver: qemu driver
@@ -6361,6 +6388,12 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
     for (i = 0; i < vm->def->nshmems; i++)
         qemuDomainPrepareShmemChardev(vm->def->shmems[i]);
 
+    if (vm->def->sev) {
+        VIR_DEBUG("Updating SEV platform info");
+        if (qemuProcessUpdateSEVInfo(vm) < 0)
+            return -1;
+    }
+
     return 0;
 }