[PATCH v2] qemu: Fix libvirt hang due to early TPM device stop

Stefan Berger posted 1 patch 3 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20210219155741.2418482-1-stefanb@linux.vnet.ibm.com
Test syntax-check failed
src/qemu/qemu_process.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
[PATCH v2] qemu: Fix libvirt hang due to early TPM device stop
Posted by Stefan Berger 3 years, 1 month ago
This patch partially reverts commit 5cde9dee where the qemuExtDevicesStop()
was moved to a location before the QEMU process is stopped. It may be
alright to tear down some devices before QEMU is stopped, but it doesn't work
for the external TPM (swtpm) which assumes that QEMU sends it a signal to stop
it before libvirt may try to clean it up. So this patch moves the
virFileDeleteTree() calls after the call to qemuExtDevicesStop() so that the
pid file of virtiofsd is not deleted before that call.

Afftected libvirt versions are 6.10 and 7.0.

Fixes: 5cde9dee8c70b17c458d031ab6cf71dce476eea2
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 src/qemu/qemu_process.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7feb35e609..d930ff9a74 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7659,11 +7659,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
     /* Do this before we delete the tree and remove pidfile. */
     qemuProcessKillManagedPRDaemon(vm);
 
-    qemuExtDevicesStop(driver, vm);
-
-    virFileDeleteTree(priv->libDir);
-    virFileDeleteTree(priv->channelTargetDir);
-
     ignore_value(virDomainChrDefForeach(vm->def,
                                         false,
                                         qemuProcessCleanupChardevDevice,
@@ -7677,10 +7672,15 @@ void qemuProcessStop(virQEMUDriverPtr driver,
 
     qemuDomainCleanupRun(driver, vm);
 
+    qemuExtDevicesStop(driver, vm);
+
     qemuDBusStop(driver, vm);
 
     vm->def->id = -1;
 
+    virFileDeleteTree(priv->libDir);
+    virFileDeleteTree(priv->channelTargetDir);
+
     /* Stop autodestroy in case guest is restarted */
     qemuProcessAutoDestroyRemove(driver, vm);
 
-- 
2.26.2

Re: [PATCH v2] qemu: Fix libvirt hang due to early TPM device stop
Posted by Michal Privoznik 3 years, 1 month ago
On 2/19/21 4:57 PM, Stefan Berger wrote:
> This patch partially reverts commit 5cde9dee where the qemuExtDevicesStop()
> was moved to a location before the QEMU process is stopped. It may be
> alright to tear down some devices before QEMU is stopped, but it doesn't work
> for the external TPM (swtpm) which assumes that QEMU sends it a signal to stop
> it before libvirt may try to clean it up. So this patch moves the
> virFileDeleteTree() calls after the call to qemuExtDevicesStop() so that the
> pid file of virtiofsd is not deleted before that call.
> 
> Afftected libvirt versions are 6.10 and 7.0.
> 
> Fixes: 5cde9dee8c70b17c458d031ab6cf71dce476eea2
> Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
>   src/qemu/qemu_process.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

and pushed.

Michal