Blame SOURCES/kvm-cpus-Fix-event-order-on-resume-of-stopped-guest.patch

1bdc94
From f94e1c832c510a3ca1b8bf0d383e7be2dce4909c Mon Sep 17 00:00:00 2001
1bdc94
From: Markus Armbruster <armbru@redhat.com>
1bdc94
Date: Wed, 9 May 2018 14:42:21 +0200
1bdc94
Subject: [PATCH 13/13] cpus: Fix event order on resume of stopped guest
1bdc94
1bdc94
RH-Author: Markus Armbruster <armbru@redhat.com>
1bdc94
Message-id: <20180509144221.14799-2-armbru@redhat.com>
1bdc94
Patchwork-id: 80191
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 1/1] cpus: Fix event order on resume of stopped guest
1bdc94
Bugzilla: 1566153
1bdc94
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
1bdc94
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
1bdc94
1bdc94
When resume of a stopped guest immediately runs into block device
1bdc94
errors, the BLOCK_IO_ERROR event is sent before the RESUME event.
1bdc94
1bdc94
Reproducer:
1bdc94
1bdc94
1. Create a scratch image
1bdc94
   $ dd if=/dev/zero of=scratch.img bs=1M count=100
1bdc94
1bdc94
   Size doesn't actually matter.
1bdc94
1bdc94
2. Prepare blkdebug configuration:
1bdc94
1bdc94
   $ cat >blkdebug.conf <
1bdc94
   [inject-error]
1bdc94
   event = "write_aio"
1bdc94
   errno = "5"
1bdc94
   EOF
1bdc94
1bdc94
   Note that errno 5 is EIO.
1bdc94
1bdc94
3. Run a guest with an additional scratch disk, i.e. with additional
1bdc94
   arguments
1bdc94
   -drive if=none,id=scratch-drive,format=raw,werror=stop,file=blkdebug:blkdebug.conf:scratch.img
1bdc94
   -device virtio-blk-pci,id=scratch,drive=scratch-drive
1bdc94
1bdc94
   The blkdebug part makes all writes to the scratch drive fail with
1bdc94
   EIO.  The werror=stop pauses the guest on write errors.
1bdc94
1bdc94
4. Connect to the QMP socket e.g. like this:
1bdc94
   $ socat UNIX:/your/qmp/socket READLINE,history=$HOME/.qmp_history,prompt='QMP> '
1bdc94
1bdc94
   Issue QMP command 'qmp_capabilities':
1bdc94
   QMP> { "execute": "qmp_capabilities" }
1bdc94
1bdc94
5. Boot the guest.
1bdc94
1bdc94
6. In the guest, write to the scratch disk, e.g. like this:
1bdc94
1bdc94
   # dd if=/dev/zero of=/dev/vdb count=1
1bdc94
1bdc94
   Do double-check the device specified with of= is actually the
1bdc94
   scratch device!
1bdc94
1bdc94
7. Issue QMP command 'cont':
1bdc94
   QMP> { "execute": "cont" }
1bdc94
1bdc94
After step 6, I get a BLOCK_IO_ERROR event followed by a STOP event.  Good.
1bdc94
1bdc94
After step 7, I get BLOCK_IO_ERROR, then RESUME, then STOP.  Not so
1bdc94
good; I'd expect RESUME, then BLOCK_IO_ERROR, then STOP.
1bdc94
1bdc94
The funny event order confuses libvirt: virsh -r domstate DOMAIN
1bdc94
--reason reports "paused (unknown)" rather than "paused (I/O error)".
1bdc94
1bdc94
The culprit is vm_prepare_start().
1bdc94
1bdc94
    /* Ensure that a STOP/RESUME pair of events is emitted if a
1bdc94
     * vmstop request was pending.  The BLOCK_IO_ERROR event, for
1bdc94
     * example, according to documentation is always followed by
1bdc94
     * the STOP event.
1bdc94
     */
1bdc94
    if (runstate_is_running()) {
1bdc94
        qapi_event_send_stop(&error_abort);
1bdc94
        res = -1;
1bdc94
    } else {
1bdc94
        replay_enable_events();
1bdc94
        cpu_enable_ticks();
1bdc94
        runstate_set(RUN_STATE_RUNNING);
1bdc94
        vm_state_notify(1, RUN_STATE_RUNNING);
1bdc94
    }
1bdc94
1bdc94
    /* We are sending this now, but the CPUs will be resumed shortly later */
1bdc94
    qapi_event_send_resume(&error_abort);
1bdc94
    return res;
1bdc94
1bdc94
When resuming a stopped guest, we take the else branch before we get
1bdc94
to sending RESUME.  vm_state_notify() runs virtio_vmstate_change(),
1bdc94
among other things.  This restarts I/O, triggering the BLOCK_IO_ERROR
1bdc94
event.
1bdc94
1bdc94
Reshuffle vm_prepare_start() to send the RESUME event earlier.
1bdc94
1bdc94
Fixes RHBZ 1566153.
1bdc94
1bdc94
Cc: Paolo Bonzini <pbonzini@redhat.com>
1bdc94
Signed-off-by: Markus Armbruster <armbru@redhat.com>
1bdc94
Message-Id: <20180423084518.2426-1-armbru@redhat.com>
1bdc94
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1bdc94
(cherry picked from commit f056158d694d2adc63ff120ca71c73ae8b14426c)
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 cpus.c | 16 ++++++++--------
1bdc94
 1 file changed, 8 insertions(+), 8 deletions(-)
1bdc94
1bdc94
diff --git a/cpus.c b/cpus.c
1bdc94
index 38eba8b..398392b 100644
1bdc94
--- a/cpus.c
1bdc94
+++ b/cpus.c
1bdc94
@@ -2043,7 +2043,6 @@ int vm_stop(RunState state)
1bdc94
 int vm_prepare_start(void)
1bdc94
 {
1bdc94
     RunState requested;
1bdc94
-    int res = 0;
1bdc94
 
1bdc94
     qemu_vmstop_requested(&requested);
1bdc94
     if (runstate_is_running() && requested == RUN_STATE__MAX) {
1bdc94
@@ -2057,17 +2056,18 @@ int vm_prepare_start(void)
1bdc94
      */
1bdc94
     if (runstate_is_running()) {
1bdc94
         qapi_event_send_stop(&error_abort);
1bdc94
-        res = -1;
1bdc94
-    } else {
1bdc94
-        replay_enable_events();
1bdc94
-        cpu_enable_ticks();
1bdc94
-        runstate_set(RUN_STATE_RUNNING);
1bdc94
-        vm_state_notify(1, RUN_STATE_RUNNING);
1bdc94
+        qapi_event_send_resume(&error_abort);
1bdc94
+        return -1;
1bdc94
     }
1bdc94
 
1bdc94
     /* We are sending this now, but the CPUs will be resumed shortly later */
1bdc94
     qapi_event_send_resume(&error_abort);
1bdc94
-    return res;
1bdc94
+
1bdc94
+    replay_enable_events();
1bdc94
+    cpu_enable_ticks();
1bdc94
+    runstate_set(RUN_STATE_RUNNING);
1bdc94
+    vm_state_notify(1, RUN_STATE_RUNNING);
1bdc94
+    return 0;
1bdc94
 }
1bdc94
 
1bdc94
 void vm_start(void)
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94