yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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