[libvirt PATCH for 8.6.0] qemu_migration_params: Avoid deadlock in qemuMigrationParamsReset

Jiri Denemark posted 1 patch 1 year, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/ef04124fa9e038dfd2a44bc75953f980395d6cb5.1659016900.git.jdenemar@redhat.com
src/qemu/qemu_migration_params.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
[libvirt PATCH for 8.6.0] qemu_migration_params: Avoid deadlock in qemuMigrationParamsReset
Posted by Jiri Denemark 1 year, 9 months ago
In my recent comnmit v8.5.0-188-gc47f1abb81 I accidentally moved
qemuMigrationParamsResetTLS after qemuDomainObjEnterMonitorAsync not
noticing qemuMigrationParamsResetTLS will try to enter the monitor
again. The second call will time out and return with a domain object
locked. But we're still in monitor section and the object should be
unlocked which means qemuDomainObjExitMonitor will deadlock trying to
lock it again.

Fixes: c47f1abb81194461377a0c608a7ecd87f9ce9146
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_migration_params.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index be7966a18a..9da2fd6d98 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -1291,6 +1291,7 @@ qemuMigrationParamsReset(virQEMUDriver *driver,
 {
     virErrorPtr err;
     g_autoptr(virBitmap) clearCaps = NULL;
+    int rc;
 
     virErrorPreserveLast(&err);
 
@@ -1305,11 +1306,16 @@ qemuMigrationParamsReset(virQEMUDriver *driver,
 
     clearCaps = virBitmapNew(0);
 
-    if (qemuMigrationParamsApplyCaps(vm, clearCaps) == 0 &&
-        qemuMigrationParamsApplyValues(vm, origParams, false) == 0)
-        qemuMigrationParamsResetTLS(driver, vm, asyncJob, origParams, apiFlags);
+    rc = 0;
+    if (qemuMigrationParamsApplyCaps(vm, clearCaps) < 0 ||
+        qemuMigrationParamsApplyValues(vm, origParams, false) < 0)
+        rc = -1;
 
     qemuDomainObjExitMonitor(vm);
+    if (rc < 0)
+        goto cleanup;
+
+    qemuMigrationParamsResetTLS(driver, vm, asyncJob, origParams, apiFlags);
 
  cleanup:
     virErrorRestore(&err);
-- 
2.35.1
Re: [libvirt PATCH for 8.6.0] qemu_migration_params: Avoid deadlock in qemuMigrationParamsReset
Posted by Michal Prívozník 1 year, 9 months ago
On 7/28/22 16:01, Jiri Denemark wrote:
> In my recent comnmit v8.5.0-188-gc47f1abb81 I accidentally moved
> qemuMigrationParamsResetTLS after qemuDomainObjEnterMonitorAsync not
> noticing qemuMigrationParamsResetTLS will try to enter the monitor
> again. The second call will time out and return with a domain object
> locked. But we're still in monitor section and the object should be
> unlocked which means qemuDomainObjExitMonitor will deadlock trying to
> lock it again.
> 
> Fixes: c47f1abb81194461377a0c608a7ecd87f9ce9146
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/qemu/qemu_migration_params.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)


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

Michal