Blame SOURCES/kvm-block-avoid-recursive-AioContext-acquire-in-bdrv_ina.patch

4a2fec
From 14279ae97888ecd51bcf04771d064fa11a3df7a1 Mon Sep 17 00:00:00 2001
4a2fec
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
4a2fec
Date: Wed, 20 Dec 2017 12:29:52 +0100
4a2fec
Subject: [PATCH 02/42] block: avoid recursive AioContext acquire in
4a2fec
 bdrv_inactivate_all()
4a2fec
4a2fec
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
Message-id: <20171220122952.9799-2-dgilbert@redhat.com>
4a2fec
Patchwork-id: 78418
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 1/1] block: avoid recursive AioContext acquire in bdrv_inactivate_all()
4a2fec
Bugzilla: 1520824
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
4a2fec
From: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
4a2fec
BDRV_POLL_WHILE() does not support recursive AioContext locking.  It
4a2fec
only releases the AioContext lock once regardless of how many times the
4a2fec
caller has acquired it.  This results in a hang since the IOThread does
4a2fec
not make progress while the AioContext is still locked.
4a2fec
4a2fec
The following steps trigger the hang:
4a2fec
4a2fec
  $ qemu-system-x86_64 -M accel=kvm -m 1G -cpu host \
4a2fec
                       -object iothread,id=iothread0 \
4a2fec
                       -device virtio-scsi-pci,iothread=iothread0 \
4a2fec
                       -drive if=none,id=drive0,file=test.img,format=raw \
4a2fec
                       -device scsi-hd,drive=drive0 \
4a2fec
                       -drive if=none,id=drive1,file=test.img,format=raw \
4a2fec
                       -device scsi-hd,drive=drive1
4a2fec
  $ qemu-system-x86_64 ...same options... \
4a2fec
                       -incoming tcp::1234
4a2fec
  (qemu) migrate tcp:127.0.0.1:1234
4a2fec
  ...hang...
4a2fec
4a2fec
Tested-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
Reviewed-by: Eric Blake <eblake@redhat.com>
4a2fec
Message-id: 20171207201320.19284-2-stefanha@redhat.com
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
(cherry picked from commit bd6458e410c1e7d2912357aeb399fe7d8ee9f9a3)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 block.c | 14 +++++++++++---
4a2fec
 1 file changed, 11 insertions(+), 3 deletions(-)
4a2fec
4a2fec
diff --git a/block.c b/block.c
4a2fec
index bc8b80b..b5736dd 100644
4a2fec
--- a/block.c
4a2fec
+++ b/block.c
4a2fec
@@ -4221,9 +4221,15 @@ int bdrv_inactivate_all(void)
4a2fec
     BdrvNextIterator it;
4a2fec
     int ret = 0;
4a2fec
     int pass;
4a2fec
+    GSList *aio_ctxs = NULL, *ctx;
4a2fec
 
4a2fec
     for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
4a2fec
-        aio_context_acquire(bdrv_get_aio_context(bs));
4a2fec
+        AioContext *aio_context = bdrv_get_aio_context(bs);
4a2fec
+
4a2fec
+        if (!g_slist_find(aio_ctxs, aio_context)) {
4a2fec
+            aio_ctxs = g_slist_prepend(aio_ctxs, aio_context);
4a2fec
+            aio_context_acquire(aio_context);
4a2fec
+        }
4a2fec
     }
4a2fec
 
4a2fec
     /* We do two passes of inactivation. The first pass calls to drivers'
4a2fec
@@ -4240,9 +4246,11 @@ int bdrv_inactivate_all(void)
4a2fec
     }
4a2fec
 
4a2fec
 out:
4a2fec
-    for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
4a2fec
-        aio_context_release(bdrv_get_aio_context(bs));
4a2fec
+    for (ctx = aio_ctxs; ctx != NULL; ctx = ctx->next) {
4a2fec
+        AioContext *aio_context = ctx->data;
4a2fec
+        aio_context_release(aio_context);
4a2fec
     }
4a2fec
+    g_slist_free(aio_ctxs);
4a2fec
 
4a2fec
     return ret;
4a2fec
 }
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec