qemu: process: sev: Fill missing 'cbitpos' & 'reducedPhysBits' from caps

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>
This commit is contained in:
Erik Skultety 2020-10-08 14:11:45 +02:00
parent 1fdc907325
commit ccb40cf288
2 changed files with 35 additions and 0 deletions

View File

@ -2491,7 +2491,9 @@ struct _virDomainSEVDef {
char *dh_cert; char *dh_cert;
char *session; char *session;
unsigned int policy; unsigned int policy;
bool haveCbitpos;
unsigned int cbitpos; unsigned int cbitpos;
bool haveReducedPhysBits;
unsigned int reduced_phys_bits; unsigned int reduced_phys_bits;
}; };

View 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: * qemuProcessPrepareDomain:
* @driver: qemu driver * @driver: qemu driver
@ -6361,6 +6388,12 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
for (i = 0; i < vm->def->nshmems; i++) for (i = 0; i < vm->def->nshmems; i++)
qemuDomainPrepareShmemChardev(vm->def->shmems[i]); qemuDomainPrepareShmemChardev(vm->def->shmems[i]);
if (vm->def->sev) {
VIR_DEBUG("Updating SEV platform info");
if (qemuProcessUpdateSEVInfo(vm) < 0)
return -1;
}
return 0; return 0;
} }