[PATCH v2 4/6] qemu: Extend QEMU with tpm-spapr support

Stefan Berger posted 6 patches 9 weeks ago

[PATCH v2 4/6] qemu: Extend QEMU with tpm-spapr support

Posted by Stefan Berger 9 weeks ago
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>
---
 src/qemu/qemu_command.c        | 15 ++++++++++-----
 src/qemu/qemu_domain.c         |  2 ++
 src/qemu/qemu_domain_address.c | 10 ++++++++++
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c8195cfbb9..3df72232ca 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 1bf3102f59..1f0f7949fc 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7794,6 +7794,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);
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 409d850a06..ef17e84d7c 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -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,15 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
             return -1;
     }
 
+    if (def->tpm) {
+        if (ARCH_IS_PPC64(def->os.arch) &&
+            STRPREFIX(def->os.machine, "pseries"))
+            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;
-- 
2.17.1


Re: [PATCH v2 4/6] qemu: Extend QEMU with tpm-spapr support

Posted by Ján Tomko 9 weeks ago
On Mon, Feb 03, 2020 at 10:59:19AM -0500, Stefan Berger wrote:
>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>
>---
> src/qemu/qemu_command.c        | 15 ++++++++++-----
> src/qemu/qemu_domain.c         |  2 ++
> src/qemu/qemu_domain_address.c | 10 ++++++++++
> 3 files changed, 22 insertions(+), 5 deletions(-)
>
>diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
>index 409d850a06..ef17e84d7c 100644
>--- a/src/qemu/qemu_domain_address.c
>+++ b/src/qemu/qemu_domain_address.c
>@@ -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,15 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
>             return -1;
>     }
>
>+    if (def->tpm) {

>+        if (ARCH_IS_PPC64(def->os.arch) &&
>+            STRPREFIX(def->os.machine, "pseries"))

if (qemuDomainIsPSeries(def))

as the condition right above uses

>+            def->tpm->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
>+        if (qemuDomainAssignSpaprVIOAddress(def, &def->tpm->info,
>+                                            VIO_ADDR_TPM) < 0)
>+            return -1;
>+    }
>+

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano

Re: [PATCH v2 4/6] qemu: Extend QEMU with tpm-spapr support

Posted by Stefan Berger 9 weeks ago
On 2/5/20 10:19 AM, Ján Tomko wrote:
> On Mon, Feb 03, 2020 at 10:59:19AM -0500, Stefan Berger wrote:
>> 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>
>> ---
>> src/qemu/qemu_command.c        | 15 ++++++++++-----
>> src/qemu/qemu_domain.c         |  2 ++
>> src/qemu/qemu_domain_address.c | 10 ++++++++++
>> 3 files changed, 22 insertions(+), 5 deletions(-)
>>
>> diff --git a/src/qemu/qemu_domain_address.c 
>> b/src/qemu/qemu_domain_address.c
>> index 409d850a06..ef17e84d7c 100644
>> --- a/src/qemu/qemu_domain_address.c
>> +++ b/src/qemu/qemu_domain_address.c
>> @@ -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,15 @@ 
>> qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
>>             return -1;
>>     }
>>
>> +    if (def->tpm) {
>
>> +        if (ARCH_IS_PPC64(def->os.arch) &&
>> +            STRPREFIX(def->os.machine, "pseries"))
>
> if (qemuDomainIsPSeries(def))
>
> as the condition right above uses


Thanks!

   I will be posting v3. Can you check it in?


    Stefan