Blame SOURCES/kvm-block-Fix-AioContext-switch-for-bs-drv-NULL.patch

383d26
From b495f8e19a84ce58d711fd1ec34b2d8234e4b542 Mon Sep 17 00:00:00 2001
383d26
From: Kevin Wolf <kwolf@redhat.com>
383d26
Date: Thu, 9 May 2019 15:34:15 +0200
383d26
Subject: [PATCH 12/12] block: Fix AioContext switch for bs->drv == NULL
383d26
383d26
RH-Author: Kevin Wolf <kwolf@redhat.com>
383d26
Message-id: <20190509153415.29673-2-kwolf@redhat.com>
383d26
Patchwork-id: 87216
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 1/1] block: Fix AioContext switch for bs->drv == NULL
383d26
Bugzilla: 1631227
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
383d26
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
383d26
Even for block nodes with bs->drv == NULL, we can't just ignore a
383d26
bdrv_set_aio_context() call. Leaving the node in its old context can
383d26
mean that it's still in an iothread context in bdrv_close_all() during
383d26
shutdown, resulting in an attempted unlock of the AioContext lock which
383d26
we don't hold.
383d26
383d26
This is an example stack trace of a related crash:
383d26
383d26
 #0  0x00007ffff59da57f in raise () at /lib64/libc.so.6
383d26
 #1  0x00007ffff59c4895 in abort () at /lib64/libc.so.6
383d26
 #2  0x0000555555b97b1e in error_exit (err=<optimized out>, msg=msg@entry=0x555555d386d0 <__func__.19059> "qemu_mutex_unlock_impl") at util/qemu-thread-posix.c:36
383d26
 #3  0x0000555555b97f7f in qemu_mutex_unlock_impl (mutex=mutex@entry=0x5555568002f0, file=file@entry=0x555555d378df "util/async.c", line=line@entry=507) at util/qemu-thread-posix.c:97
383d26
 #4  0x0000555555b92f55 in aio_context_release (ctx=ctx@entry=0x555556800290) at util/async.c:507
383d26
 #5  0x0000555555b05cf8 in bdrv_prwv_co (child=child@entry=0x7fffc80012f0, offset=offset@entry=131072, qiov=qiov@entry=0x7fffffffd4f0, is_write=is_write@entry=true, flags=flags@entry=0)
383d26
         at block/io.c:833
383d26
 #6  0x0000555555b060a9 in bdrv_pwritev (qiov=0x7fffffffd4f0, offset=131072, child=0x7fffc80012f0) at block/io.c:990
383d26
 #7  0x0000555555b060a9 in bdrv_pwrite (child=0x7fffc80012f0, offset=131072, buf=<optimized out>, bytes=<optimized out>) at block/io.c:990
383d26
 #8  0x0000555555ae172b in qcow2_cache_entry_flush (bs=bs@entry=0x555556810680, c=c@entry=0x5555568cc740, i=i@entry=0) at block/qcow2-cache.c:51
383d26
 #9  0x0000555555ae18dd in qcow2_cache_write (bs=bs@entry=0x555556810680, c=0x5555568cc740) at block/qcow2-cache.c:248
383d26
 #10 0x0000555555ae15de in qcow2_cache_flush (bs=0x555556810680, c=<optimized out>) at block/qcow2-cache.c:259
383d26
 #11 0x0000555555ae16b1 in qcow2_cache_flush_dependency (c=0x5555568a1700, c=0x5555568a1700, bs=0x555556810680) at block/qcow2-cache.c:194
383d26
 #12 0x0000555555ae16b1 in qcow2_cache_entry_flush (bs=bs@entry=0x555556810680, c=c@entry=0x5555568a1700, i=i@entry=0) at block/qcow2-cache.c:194
383d26
 #13 0x0000555555ae18dd in qcow2_cache_write (bs=bs@entry=0x555556810680, c=0x5555568a1700) at block/qcow2-cache.c:248
383d26
 #14 0x0000555555ae15de in qcow2_cache_flush (bs=bs@entry=0x555556810680, c=<optimized out>) at block/qcow2-cache.c:259
383d26
 #15 0x0000555555ad242c in qcow2_inactivate (bs=bs@entry=0x555556810680) at block/qcow2.c:2124
383d26
 #16 0x0000555555ad2590 in qcow2_close (bs=0x555556810680) at block/qcow2.c:2153
383d26
 #17 0x0000555555ab0c62 in bdrv_close (bs=0x555556810680) at block.c:3358
383d26
 #18 0x0000555555ab0c62 in bdrv_delete (bs=0x555556810680) at block.c:3542
383d26
 #19 0x0000555555ab0c62 in bdrv_unref (bs=0x555556810680) at block.c:4598
383d26
 #20 0x0000555555af4d72 in blk_remove_bs (blk=blk@entry=0x5555568103d0) at block/block-backend.c:785
383d26
 #21 0x0000555555af4dbb in blk_remove_all_bs () at block/block-backend.c:483
383d26
 #22 0x0000555555aae02f in bdrv_close_all () at block.c:3412
383d26
 #23 0x00005555557f9796 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:4776
383d26
383d26
The reproducer I used is a qcow2 image on gluster volume, where the
383d26
virtual disk size (4 GB) is larger than the gluster volume size (64M),
383d26
so we can easily trigger an ENOSPC. This backend is assigned to a
383d26
virtio-blk device using an iothread, and then from the guest a
383d26
'dd if=/dev/zero of=/dev/vda bs=1G count=1' causes the VM to stop
383d26
because of an I/O error. qemu_gluster_co_flush_to_disk() sets
383d26
bs->drv = NULL on error, so when virtio-blk stops the dataplane, the
383d26
block nodes stay in the iothread AioContext. A 'quit' monitor command
383d26
issued from this paused state crashes the process.
383d26
383d26
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1631227
383d26
Cc: qemu-stable@nongnu.org
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
Reviewed-by: Eric Blake <eblake@redhat.com>
383d26
Reviewed-by: Max Reitz <mreitz@redhat.com>
383d26
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
383d26
(cherry picked from commit 1bffe1ae7a7b707c3a14ea2ccd00d3609d3ce4d8)
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block.c | 12 ++----------
383d26
 1 file changed, 2 insertions(+), 10 deletions(-)
383d26
383d26
diff --git a/block.c b/block.c
383d26
index e3e0e34..7061f9b 100644
383d26
--- a/block.c
383d26
+++ b/block.c
383d26
@@ -4946,10 +4946,6 @@ void bdrv_detach_aio_context(BlockDriverState *bs)
383d26
     BdrvAioNotifier *baf, *baf_tmp;
383d26
     BdrvChild *child;
383d26
 
383d26
-    if (!bs->drv) {
383d26
-        return;
383d26
-    }
383d26
-
383d26
     assert(!bs->walking_aio_notifiers);
383d26
     bs->walking_aio_notifiers = true;
383d26
     QLIST_FOREACH_SAFE(baf, &bs->aio_notifiers, list, baf_tmp) {
383d26
@@ -4964,7 +4960,7 @@ void bdrv_detach_aio_context(BlockDriverState *bs)
383d26
      */
383d26
     bs->walking_aio_notifiers = false;
383d26
 
383d26
-    if (bs->drv->bdrv_detach_aio_context) {
383d26
+    if (bs->drv && bs->drv->bdrv_detach_aio_context) {
383d26
         bs->drv->bdrv_detach_aio_context(bs);
383d26
     }
383d26
     QLIST_FOREACH(child, &bs->children, next) {
383d26
@@ -4983,10 +4979,6 @@ void bdrv_attach_aio_context(BlockDriverState *bs,
383d26
     BdrvAioNotifier *ban, *ban_tmp;
383d26
     BdrvChild *child;
383d26
 
383d26
-    if (!bs->drv) {
383d26
-        return;
383d26
-    }
383d26
-
383d26
     if (bs->quiesce_counter) {
383d26
         aio_disable_external(new_context);
383d26
     }
383d26
@@ -4996,7 +4988,7 @@ void bdrv_attach_aio_context(BlockDriverState *bs,
383d26
     QLIST_FOREACH(child, &bs->children, next) {
383d26
         bdrv_attach_aio_context(child->bs, new_context);
383d26
     }
383d26
-    if (bs->drv->bdrv_attach_aio_context) {
383d26
+    if (bs->drv && bs->drv->bdrv_attach_aio_context) {
383d26
         bs->drv->bdrv_attach_aio_context(bs, new_context);
383d26
     }
383d26
 
383d26
-- 
383d26
1.8.3.1
383d26