From 7ace0fd221f74f9109f09418ef9cbbc074144c21 Mon Sep 17 00:00:00 2001
From: Andrea Bolognani <abologna@redhat.com>
Date: Fri, 25 Jun 2021 15:57:38 +0200
Subject: [PATCH] qemu: Default to TPM 2.0 for ARM virt guests

The TPM 2.0 specification predates ARM virtualization, and so
implementing TPM 1.2 support on ARM was not considered a useful
endeavor.

This is technically a breaking change, but TPM support on ARM was
only introduced fairly recently (libvirt 7.1.0) and the previous
default resulted in non working TPM devices; anyone who has a
working configuration is not going to be affected.

https://bugzilla.redhat.com/show_bug.cgi?id=1970310

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Tested-by: Liu Yiding <liuyd.fnst@fujitsu.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index fc60e15eea..8488f58e09 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4445,7 +4445,8 @@ qemuDomainDefTPMsPostParse(virDomainDef *def)
         /* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
         if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT) {
             if (tpm->model == VIR_DOMAIN_TPM_MODEL_SPAPR ||
-                tpm->model == VIR_DOMAIN_TPM_MODEL_CRB)
+                tpm->model == VIR_DOMAIN_TPM_MODEL_CRB ||
+                qemuDomainIsARMVirt(def))
                 tpm->version = VIR_DOMAIN_TPM_VERSION_2_0;
             else
                 tpm->version = VIR_DOMAIN_TPM_VERSION_1_2;