]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Extend QEMU with tpm-spapr support
authorStefan Berger <stefanb@linux.ibm.com>
Wed, 5 Feb 2020 18:35:48 +0000 (13:35 -0500)
committerJán Tomko <jtomko@redhat.com>
Wed, 5 Feb 2020 18:57:10 +0000 (19:57 +0100)
Extend QEMU with tpm-spapr support. Assign a device address to the
vTPM device model.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
src/qemu/qemu_domain.c
src/qemu/qemu_domain_address.c

index 81f5fa34163834f623fd4b58bf78bd1bca348de6..0dbd78124b7860fdc3a3e83f81c76ccb55f6c09a 100644 (file)
@@ -9064,15 +9064,19 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
 
 
 static char *
-qemuBuildTPMDevStr(const virDomainDef *def)
+qemuBuildTPMDevStr(const virDomainDef *def,
+                   virQEMUCapsPtr qemuCaps)
 {
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    const virDomainTPMDef *tpm = def->tpm;
+    virDomainTPMDef *tpm = def->tpm;
     const char *model = virDomainTPMModelTypeToString(tpm->model);
 
     virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
                       model, tpm->info.alias, tpm->info.alias);
 
+    if (qemuBuildDeviceAddressStr(&buf, def, &tpm->info, qemuCaps) < 0)
+        return NULL;
+
     return virBufferContentAndReset(&buf);
 }
 
@@ -9162,7 +9166,8 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
 
 static int
 qemuBuildTPMCommandLine(virCommandPtr cmd,
-                        const virDomainDef *def)
+                        const virDomainDef *def,
+                        virQEMUCapsPtr qemuCaps)
 {
     char *optstr;
     g_autofree char *chardev = NULL;
@@ -9202,7 +9207,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
         VIR_FREE(fdset);
     }
 
-    if (!(optstr = qemuBuildTPMDevStr(def)))
+    if (!(optstr = qemuBuildTPMDevStr(def, qemuCaps)))
         return -1;
 
     virCommandAddArgList(cmd, "-device", optstr, NULL);
@@ -9918,7 +9923,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
                                     chardevStdioLogd) < 0)
         return NULL;
 
-    if (qemuBuildTPMCommandLine(cmd, def) < 0)
+    if (qemuBuildTPMCommandLine(cmd, def, qemuCaps) < 0)
         return NULL;
 
     if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
index 39513a726ef911a000927359dfc9fcce9e66b54a..851f750bd7928dc85612e6a57e7c41504d6300c1 100644 (file)
@@ -7798,6 +7798,8 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
         flag = QEMU_CAPS_DEVICE_TPM_CRB;
         break;
     case VIR_DOMAIN_TPM_MODEL_SPAPR:
+        flag = QEMU_CAPS_DEVICE_TPM_SPAPR;
+        break;
     case VIR_DOMAIN_TPM_MODEL_LAST:
     default:
         virReportEnumRangeError(virDomainTPMModel, tpm->model);
index 409d850a06e4b6704dfef796bac5ed8f1800b61d..c7d8a3ac3ba1bcd4d9f7bb48eb2d03a3a70491b4 100644 (file)
@@ -35,6 +35,7 @@ VIR_LOG_INIT("qemu.qemu_domain_address");
 #define VIO_ADDR_SCSI 0x2000ul
 #define VIO_ADDR_SERIAL 0x30000000ul
 #define VIO_ADDR_NVRAM 0x3000ul
+#define VIO_ADDR_TPM 0x4000ul
 
 
 /**
@@ -267,6 +268,14 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
             return -1;
     }
 
+    if (def->tpm) {
+        if (qemuDomainIsPSeries(def))
+            def->tpm->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
+        if (qemuDomainAssignSpaprVIOAddress(def, &def->tpm->info,
+                                            VIO_ADDR_TPM) < 0)
+            return -1;
+    }
+
     /* No other devices are currently supported on spapr-vio */
 
     return 0;