thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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