void
-virDomainSEVDefFree(virDomainSEVDef *def)
+virDomainSecDefFree(virDomainSecDef *def)
{
if (!def)
return;
- g_free(def->dh_cert);
- g_free(def->session);
+ switch ((virDomainLaunchSecurity) def->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ g_free(def->data.sev.dh_cert);
+ g_free(def->data.sev.session);
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ break;
+ }
g_free(def);
}
if (def->namespaceData && def->ns.free)
(def->ns.free)(def->namespaceData);
- virDomainSEVDefFree(def->sev);
+ virDomainSecDefFree(def->sec);
xmlFreeNode(def->metadata);
}
-static virDomainSEVDef *
-virDomainSEVDefParseXML(xmlNodePtr sevNode,
+static int
+virDomainSEVDefParseXML(virDomainSEVDef *def,
xmlXPathContextPtr ctxt)
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
- g_autoptr(virDomainSEVDef) def = NULL;
unsigned long policy;
int rc;
- def = g_new0(virDomainSEVDef, 1);
+ if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("failed to get launch security policy"));
+ return -1;
+ }
- ctxt->node = sevNode;
+ /* the following attributes are platform dependent and if missing, we can
+ * autofill them from domain capabilities later
+ */
+ rc = virXPathUInt("string(./cbitpos)", ctxt, &def->cbitpos);
+ if (rc == 0) {
+ def->haveCbitpos = true;
+ } else if (rc == -2) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Invalid format for launch security cbitpos"));
+ return -1;
+ }
- if (virXMLPropEnum(sevNode, "type", virDomainLaunchSecurityTypeFromString,
- VIR_XML_PROP_NONZERO | VIR_XML_PROP_REQUIRED,
- &def->sectype) < 0)
- return NULL;
+ rc = virXPathUInt("string(./reducedPhysBits)", ctxt,
+ &def->reduced_phys_bits);
+ if (rc == 0) {
+ def->haveReducedPhysBits = true;
+ } else if (rc == -2) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Invalid format for launch security "
+ "reduced-phys-bits"));
+ return -1;
+ }
- switch ((virDomainLaunchSecurity) def->sectype) {
- case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
- if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("failed to get launch security policy"));
- return NULL;
- }
+ def->policy = policy;
+ def->dh_cert = virXPathString("string(./dhCert)", ctxt);
+ def->session = virXPathString("string(./session)", ctxt);
- /* the following attributes are platform dependent and if missing, we can
- * autofill them from domain capabilities later
- */
- rc = virXPathUInt("string(./cbitpos)", ctxt, &def->cbitpos);
- if (rc == 0) {
- def->haveCbitpos = true;
- } else if (rc == -2) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("Invalid format for launch security cbitpos"));
- return NULL;
- }
+ return 0;
+}
- rc = virXPathUInt("string(./reducedPhysBits)", ctxt,
- &def->reduced_phys_bits);
- if (rc == 0) {
- def->haveReducedPhysBits = true;
- } else if (rc == -2) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("Invalid format for launch security "
- "reduced-phys-bits"));
- return NULL;
- }
- def->policy = policy;
- def->dh_cert = virXPathString("string(./dhCert)", ctxt);
- def->session = virXPathString("string(./session)", ctxt);
+static virDomainSecDef *
+virDomainSecDefParseXML(xmlNodePtr lsecNode,
+ xmlXPathContextPtr ctxt)
+{
+ g_autoptr(virDomainSecDef) sec = g_new0(virDomainSecDef, 1);
- return g_steal_pointer(&def);
+ ctxt->node = lsecNode;
+
+ if (virXMLPropEnum(lsecNode, "type", virDomainLaunchSecurityTypeFromString,
+ VIR_XML_PROP_NONZERO | VIR_XML_PROP_REQUIRED,
+ &sec->sectype) < 0)
+ return NULL;
+
+ switch ((virDomainLaunchSecurity) sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ if (virDomainSEVDefParseXML(&sec->data.sev, ctxt) < 0)
+ return NULL;
+ break;
case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
default:
virReportError(VIR_ERR_XML_ERROR,
_("unsupported launch security type '%s'"),
- virDomainLaunchSecurityTypeToString(def->sectype));
+ virDomainLaunchSecurityTypeToString(sec->sectype));
return NULL;
}
+
+ return g_steal_pointer(&sec);
}
ctxt->node = node;
VIR_FREE(nodes);
- /* Check for SEV feature */
+ /* Check for launch security e.g. SEV feature */
if ((node = virXPathNode("./launchSecurity", ctxt)) != NULL) {
- def->sev = virDomainSEVDefParseXML(node, ctxt);
- if (!def->sev)
+ def->sec = virDomainSecDefParseXML(node, ctxt);
+ if (!def->sec)
goto error;
}
static void
-virDomainSEVDefFormat(virBuffer *buf, virDomainSEVDef *sev)
+virDomainSecDefFormat(virBuffer *buf, virDomainSecDef *sec)
{
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
- if (!sev)
+ if (!sec)
return;
virBufferAsprintf(&attrBuf, " type='%s'",
- virDomainLaunchSecurityTypeToString(sev->sectype));
+ virDomainLaunchSecurityTypeToString(sec->sectype));
+
+ switch ((virDomainLaunchSecurity) sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV: {
+ virDomainSEVDef *sev = &sec->data.sev;
- switch ((virDomainLaunchSecurity) sev->sectype) {
- case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
if (sev->haveCbitpos)
virBufferAsprintf(&childBuf, "<cbitpos>%d</cbitpos>\n", sev->cbitpos);
virBufferEscapeString(&childBuf, "<session>%s</session>\n", sev->session);
break;
+ }
case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
return;
if (def->keywrap)
virDomainKeyWrapDefFormat(buf, def->keywrap);
- virDomainSEVDefFormat(buf, def->sev);
+ virDomainSecDefFormat(buf, def->sec);
if (def->namespaceData && def->ns.format) {
if ((def->ns.format)(buf, def->namespaceData) < 0)
struct _virDomainSEVDef {
- virDomainLaunchSecurity sectype;
char *dh_cert;
char *session;
unsigned int policy;
unsigned int reduced_phys_bits;
};
-void virDomainSEVDefFree(virDomainSEVDef *def);
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSEVDef, virDomainSEVDefFree);
+struct _virDomainSecDef {
+ virDomainLaunchSecurity sectype;
+ union {
+ virDomainSEVDef sev;
+ } data;
+};
+
+void virDomainSecDefFree(virDomainSecDef *def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSecDef, virDomainSecDefFree);
typedef enum {
VIR_DOMAIN_IOMMU_MODEL_INTEL,
virDomainKeyWrapDef *keywrap;
- /* SEV-specific domain */
- virDomainSEVDef *sev;
+ /* launch security e.g. SEV */
+ virDomainSecDef *sec;
/* Application-specific custom metadata */
xmlNodePtr metadata;
typedef struct _virDomainSEVDef virDomainSEVDef;
+typedef struct _virDomainSecDef virDomainSecDef;
+
typedef struct _virDomainShmemDef virDomainShmemDef;
typedef struct _virDomainSmartcardDef virDomainSmartcardDef;
return -1;
}
- if (vm->def->sev && qemuSetupSEVCgroup(vm) < 0)
+ if (vm->def->sec &&
+ vm->def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV &&
+ qemuSetupSEVCgroup(vm) < 0)
return -1;
return 0;
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_LOADPARM))
qemuAppendLoadparmMachineParm(&buf, def);
- if (def->sev) {
- if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_CONFIDENTAL_GUEST_SUPPORT)) {
- virBufferAddLit(&buf, ",confidential-guest-support=sev0");
- } else {
- virBufferAddLit(&buf, ",memory-encryption=sev0");
+ if (def->sec) {
+ switch ((virDomainLaunchSecurity) def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_CONFIDENTAL_GUEST_SUPPORT)) {
+ virBufferAddLit(&buf, ",confidential-guest-support=sev0");
+ } else {
+ virBufferAddLit(&buf, ",memory-encryption=sev0");
+ }
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sectype);
+ return -1;
}
}
g_autofree char *dhpath = NULL;
g_autofree char *sessionpath = NULL;
- if (!sev)
- return 0;
-
VIR_DEBUG("policy=0x%x cbitpos=%d reduced_phys_bits=%d",
sev->policy, sev->cbitpos, sev->reduced_phys_bits);
return 0;
}
+
+static int
+qemuBuildSecCommandLine(virDomainObj *vm, virCommand *cmd,
+ virDomainSecDef *sec)
+{
+ if (!sec)
+ return 0;
+
+ switch ((virDomainLaunchSecurity) sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ return qemuBuildSEVCommandLine(vm, cmd, &sec->data.sev);
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, sec->sectype);
+ return -1;
+ }
+
+ return 0;
+}
+
+
static int
qemuBuildVMCoreInfoCommandLine(virCommand *cmd,
const virDomainDef *def)
if (qemuBuildVMCoreInfoCommandLine(cmd, def) < 0)
return NULL;
- if (qemuBuildSEVCommandLine(vm, cmd, def->sev) < 0)
+ if (qemuBuildSecCommandLine(vm, cmd, def->sec) < 0)
return NULL;
if (snapshot)
if (virDomainGetLaunchSecurityInfoEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
- if (vm->def->sev) {
+ if (vm->def->sec &&
+ vm->def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
if (qemuDomainGetSEVMeasurement(driver, vm, params, nparams, flags) < 0)
goto cleanup;
}
return false;
}
- if (def->sev &&
- def->sev->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
- if (!supportsSEV) {
- VIR_DEBUG("Domain requires SEV, firmware '%s' doesn't support it",
- path);
- return false;
- }
+ if (def->sec) {
+ switch ((virDomainLaunchSecurity) def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ if (!supportsSEV) {
+ VIR_DEBUG("Domain requires SEV, firmware '%s' doesn't support it",
+ path);
+ return false;
+ }
- if (def->sev->policy & VIR_QEMU_FIRMWARE_AMD_SEV_ES_POLICY &&
- !supportsSEVES) {
- VIR_DEBUG("Domain requires SEV-ES, firmware '%s' doesn't support it",
- path);
- return false;
+ if (def->sec->data.sev.policy & VIR_QEMU_FIRMWARE_AMD_SEV_ES_POLICY &&
+ !supportsSEVES) {
+ VIR_DEBUG("Domain requires SEV-ES, firmware '%s' doesn't support it",
+ path);
+ return false;
+ }
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sectype);
+ return -1;
}
}
qemuDomainSetupLaunchSecurity(virDomainObj *vm,
GSList **paths)
{
- virDomainSEVDef *sev = vm->def->sev;
+ virDomainSecDef *sec = vm->def->sec;
- if (!sev || sev->sectype != VIR_DOMAIN_LAUNCH_SECURITY_SEV)
+ if (!sec)
return 0;
- VIR_DEBUG("Setting up launch security");
+ switch ((virDomainLaunchSecurity) sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ VIR_DEBUG("Setting up launch security for SEV");
- *paths = g_slist_prepend(*paths, g_strdup(QEMU_DEV_SEV));
+ *paths = g_slist_prepend(*paths, g_strdup(QEMU_DEV_SEV));
+
+ VIR_DEBUG("Set up launch security for SEV");
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, sec->sectype);
+ return -1;
+ }
- VIR_DEBUG("Set up launch security");
return 0;
}
{
qemuDomainObjPrivate *priv = vm->privateData;
virQEMUCaps *qemuCaps = priv->qemuCaps;
- virDomainSEVDef *sev = vm->def->sev;
+ virDomainSEVDef *sev = &vm->def->sec->data.sev;
virSEVCapability *sevCaps = NULL;
/* if platform specific info like 'cbitpos' and 'reducedPhysBits' have
for (i = 0; i < vm->def->nshmems; i++)
qemuDomainPrepareShmemChardev(vm->def->shmems[i]);
- if (vm->def->sev) {
+ if (vm->def->sec &&
+ vm->def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
VIR_DEBUG("Updating SEV platform info");
if (qemuProcessUpdateSEVInfo(vm) < 0)
return -1;
static int
qemuProcessPrepareSEVGuestInput(virDomainObj *vm)
{
- virDomainSEVDef *sev = vm->def->sev;
-
- if (!sev)
- return 0;
+ virDomainSEVDef *sev = &vm->def->sec->data.sev;
VIR_DEBUG("Preparing SEV guest");
}
+static int
+qemuProcessPrepareLaunchSecurityGuestInput(virDomainObj *vm)
+{
+ virDomainSecDef *sec = vm->def->sec;
+
+ if (!sec)
+ return 0;
+
+ switch ((virDomainLaunchSecurity) sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ return qemuProcessPrepareSEVGuestInput(vm);
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, sec->sectype);
+ return -1;
+ }
+
+ return 0;
+}
+
+
static int
qemuProcessPrepareHostStorage(virQEMUDriver *driver,
virDomainObj *vm,
if (qemuExtDevicesPrepareHost(driver, vm) < 0)
return -1;
- if (qemuProcessPrepareSEVGuestInput(vm) < 0)
+ if (qemuProcessPrepareLaunchSecurityGuestInput(vm) < 0)
return -1;
return 0;
if (qemuValidateDomainDefPanic(def, qemuCaps) < 0)
return -1;
- if (def->sev &&
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_SEV_GUEST)) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("SEV launch security is not supported with "
- "this QEMU binary"));
- return -1;
+ if (def->sec) {
+ switch ((virDomainLaunchSecurity) def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SEV_GUEST)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("SEV launch security is not supported with "
+ "this QEMU binary"));
+ return -1;
+ }
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sectype);
+ return -1;
+ }
}
if (def->naudios > 1 &&
rc = -1;
}
- if (def->sev) {
+ if (def->sec &&
+ def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
if (virSecurityDACRestoreSEVLabel(mgr, def) < 0)
rc = -1;
}
return -1;
}
- if (def->sev) {
+ if (def->sec &&
+ def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
if (virSecurityDACSetSEVLabel(mgr, def) < 0)
return -1;
}