All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Raphael Norwitz <raphael.norwitz@nutanix.com>,
	Dima Stepanov <dimastep@yandex-team.ru>
Subject: [PULL v4 06/48] vhost: recheck dev state in the vhost_migration_log routine
Date: Tue, 29 Sep 2020 03:21:06 -0400	[thread overview]
Message-ID: <20200929071948.281157-7-mst@redhat.com> (raw)
In-Reply-To: <20200929071948.281157-1-mst@redhat.com>

From: Dima Stepanov <dimastep@yandex-team.ru>

vhost-user devices can get a disconnect in the middle of the VHOST-USER
handshake on the migration start. If disconnect event happened right
before sending next VHOST-USER command, then the vhost_dev_set_log()
call in the vhost_migration_log() function will return error. This error
will lead to the assert() and close the QEMU migration source process.
For the vhost-user devices the disconnect event should not break the
migration process, because:
  - the device will be in the stopped state, so it will not be changed
    during migration
  - if reconnect will be made the migration log will be reinitialized as
    part of reconnect/init process:
    #0  vhost_log_global_start (listener=0x563989cf7be0)
    at hw/virtio/vhost.c:920
    #1  0x000056398603d8bc in listener_add_address_space (listener=0x563989cf7be0,
        as=0x563986ea4340 <address_space_memory>)
    at softmmu/memory.c:2664
    #2  0x000056398603dd30 in memory_listener_register (listener=0x563989cf7be0,
        as=0x563986ea4340 <address_space_memory>)
    at softmmu/memory.c:2740
    #3  0x0000563985fd6956 in vhost_dev_init (hdev=0x563989cf7bd8,
        opaque=0x563989cf7e30, backend_type=VHOST_BACKEND_TYPE_USER,
        busyloop_timeout=0)
    at hw/virtio/vhost.c:1385
    #4  0x0000563985f7d0b8 in vhost_user_blk_connect (dev=0x563989cf7990)
    at hw/block/vhost-user-blk.c:315
    #5  0x0000563985f7d3f6 in vhost_user_blk_event (opaque=0x563989cf7990,
        event=CHR_EVENT_OPENED)
    at hw/block/vhost-user-blk.c:379
Update the vhost-user-blk device with the internal started_vu field which
will be used for initialization (vhost_user_blk_start) and clean up
(vhost_user_blk_stop). This additional flag in the VhostUserBlk structure
will be used to track whether the device really needs to be stopped and
cleaned up on a vhost-user level.
The disconnect event will set the overall VHOST device (not vhost-user) to
the stopped state, so it can be used by the general vhost_migration_log
routine.
Such approach could be propogated to the other vhost-user devices, but
better idea is just to make the same connect/disconnect code for all the
vhost-user devices.

This migration issue was slightly discussed earlier:
  - https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg01509.html
  - https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg05241.html

Signed-off-by: Dima Stepanov <dimastep@yandex-team.ru>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <9fbfba06791a87813fcee3e2315f0b904cc6789a.1599813294.git.dimastep@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/vhost-user-blk.h | 10 ++++++++++
 hw/block/vhost-user-blk.c          | 19 ++++++++++++++++---
 hw/virtio/vhost.c                  | 27 ++++++++++++++++++++++++---
 3 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h
index f536576d20..7c91f15040 100644
--- a/include/hw/virtio/vhost-user-blk.h
+++ b/include/hw/virtio/vhost-user-blk.h
@@ -40,7 +40,17 @@ struct VHostUserBlk {
     VhostUserState vhost_user;
     struct vhost_virtqueue *vhost_vqs;
     VirtQueue **virtqs;
+
+    /*
+     * There are at least two steps of initialization of the
+     * vhost-user device. The first is a "connect" step and
+     * second is a "start" step. Make a separation between
+     * those initialization phases by using two fields.
+     */
+    /* vhost_user_blk_connect/vhost_user_blk_disconnect */
     bool connected;
+    /* vhost_user_blk_start/vhost_user_blk_stop */
+    bool started_vu;
 };
 
 #endif
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 39aec42dae..a076b1e54d 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -150,6 +150,7 @@ static int vhost_user_blk_start(VirtIODevice *vdev)
         error_report("Error starting vhost: %d", -ret);
         goto err_guest_notifiers;
     }
+    s->started_vu = true;
 
     /* guest_notifier_mask/pending not used yet, so just unmask
      * everything here. virtio-pci will do the right thing by
@@ -175,6 +176,11 @@ static void vhost_user_blk_stop(VirtIODevice *vdev)
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
     int ret;
 
+    if (!s->started_vu) {
+        return;
+    }
+    s->started_vu = false;
+
     if (!k->set_guest_notifiers) {
         return;
     }
@@ -341,9 +347,7 @@ static void vhost_user_blk_disconnect(DeviceState *dev)
     }
     s->connected = false;
 
-    if (s->dev.started) {
-        vhost_user_blk_stop(vdev);
-    }
+    vhost_user_blk_stop(vdev);
 
     vhost_dev_cleanup(&s->dev);
 }
@@ -399,6 +403,15 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event)
                     NULL, NULL, false);
             aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, opaque);
         }
+
+        /*
+         * Move vhost device to the stopped state. The vhost-user device
+         * will be clean up and disconnected in BH. This can be useful in
+         * the vhost migration code. If disconnect was caught there is an
+         * option for the general vhost code to get the dev state without
+         * knowing its type (in this case vhost-user).
+         */
+        s->dev.started = false;
         break;
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 8087f200e9..60bc516003 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -871,21 +871,42 @@ static int vhost_migration_log(MemoryListener *listener, bool enable)
         dev->log_enabled = enable;
         return 0;
     }
+
+    r = 0;
     if (!enable) {
         r = vhost_dev_set_log(dev, false);
         if (r < 0) {
-            return r;
+            goto check_dev_state;
         }
         vhost_log_put(dev, false);
     } else {
         vhost_dev_log_resize(dev, vhost_get_log_size(dev));
         r = vhost_dev_set_log(dev, true);
         if (r < 0) {
-            return r;
+            goto check_dev_state;
         }
     }
+
+check_dev_state:
     dev->log_enabled = enable;
-    return 0;
+    /*
+     * vhost-user-* devices could change their state during log
+     * initialization due to disconnect. So check dev state after
+     * vhost communication.
+     */
+    if (!dev->started) {
+        /*
+         * Since device is in the stopped state, it is okay for
+         * migration. Return success.
+         */
+        r = 0;
+    }
+    if (r) {
+        /* An error is occured. */
+        dev->log_enabled = false;
+    }
+
+    return r;
 }
 
 static void vhost_log_global_start(MemoryListener *listener)
-- 
MST



  parent reply	other threads:[~2020-09-29  7:23 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29  7:20 [PULL v4 00/48] virtio,pc,acpi: fixes, tests Michael S. Tsirkin
2020-09-29  7:20 ` [PULL v4 01/48] linux headers: sync to 5.9-rc4 Michael S. Tsirkin
2020-09-29  7:20   ` Michael S. Tsirkin
2020-09-29  7:20 ` [PULL v4 03/48] vhost-vdpa: batch updating IOTLB mappings Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 04/48] virtio-mem: detach the element from the virtqueue when error occurs Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 05/48] pc: fix auto_enable_numa_with_memhp/auto_enable_numa_with_memdev for the 5.0 machine Michael S. Tsirkin
2020-09-29  7:21 ` Michael S. Tsirkin [this message]
2020-09-29  7:21 ` [PULL v4 07/48] vhost: check queue state in the vhost_dev_set_log routine Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 08/48] tests/qtest/vhost-user-test: prepare the tests for adding new dev class Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 09/48] cphp: remove deprecated cpu-add command(s) Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 10/48] virtio-iommu: Check gtrees are non null before destroying them Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 11/48] virtio-iommu-pci: force virtio version 1 Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 12/48] virtio-pmem-pci: " Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 13/48] util/hexdump: introduce qemu_hexdump_line() Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 14/48] vhost-vdpa: add trace-events Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 15/48] configure: Fix build dependencies with vhost-vdpa Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 16/48] virtio: skip legacy support check on machine types less than 5.1 Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 17/48] vhost-vsock-pci: force virtio version 1 Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 18/48] vhost-user-vsock-pci: " Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 19/48] vhost-vsock-ccw: " Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 20/48] virtio: update MemoryRegionCaches when guest set bad features Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 21/48] x86: lpc9: let firmware negotiate 'CPU hotplug with SMI' features Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 22/48] x86: cpuhp: prevent guest crash on CPU hotplug when broadcast SMI is in use Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 23/48] x86: cpuhp: refuse cpu hot-unplug request earlier if not supported Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 24/48] acpi: add aml_land() and aml_break() primitives Michael S. Tsirkin
2020-09-29  7:21 ` [PULL v4 25/48] tests: acpi: mark to be changed tables in bios-tables-test-allowed-diff Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 26/48] x86: ich9: expose "smi_negotiated_features" as a QOM property Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 27/48] x86: acpi: introduce AcpiPmInfo::smi_on_cpuhp Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 28/48] x86: acpi: introduce the PCI0.SMI0 ACPI device Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 29/48] x68: acpi: trigger SMI before sending hotplug Notify event to OSPM Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 30/48] tests: acpi: update acpi blobs with new AML Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 31/48] hw/smbios: support loading OEM strings values from a file Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 32/48] hw/smbios: report error if table size is too large Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 33/48] qemu-options: document SMBIOS type 11 settings Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 34/48] vhost-user: save features of multiqueues if chardev is closed Michael S. Tsirkin
2021-05-12  7:58   ` Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 35/48] tests/acpi: mark addition of table DSDT.roothp for unit testing root pci hotplug Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 36/48] tests/acpi: add new unit test to test hotplug off/on feature on the root pci bus Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 37/48] tests/acpi: add a new ACPI table in order to test root pci hotplug on/off Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 38/48] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 39/48] i440fx/acpi: do not add hotplug related amls for cold plugged bridges Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 40/48] tests/acpi: list added acpi table binary file for pci bridge hotplug test Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 41/48] tests/acpi: unit test for 'acpi-pci-hotplug-with-bridge-support' bridge flag Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 42/48] tests/acpi: add newly added acpi DSDT table blob for pci bridge hotplug flag Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 43/48] Add ACPI DSDT tables for q35 that are being updated by the next patch Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 44/48] piix4: don't reserve hw resources when hotplug is off globally Michael S. Tsirkin
2020-11-07 10:10   ` Philippe Mathieu-Daudé
2020-11-07 11:14     ` Philippe Mathieu-Daudé
2020-11-07 12:22     ` Ani Sinha
2020-11-07 14:18       ` Philippe Mathieu-Daudé
2020-11-07 14:28         ` Michael S. Tsirkin
2020-09-29  7:22 ` [PULL v4 45/48] tests/acpi: update golden master DSDT binary table blobs for q35 Michael S. Tsirkin
2020-09-29  7:23 ` [PULL v4 46/48] hw: virtio-pmem: detach the element fromt the virtqueue when error occurs Michael S. Tsirkin
2020-09-29  7:23 ` [PULL v4 47/48] libvhost-user: return early on virtqueue errors Michael S. Tsirkin
2020-09-29  7:23 ` [PULL v4 48/48] libvhost-user: return on error in vu_log_queue_fill() Michael S. Tsirkin
2020-09-29  7:25 ` [PULL v4 02/48] vhost: switch to use IOTLB v2 format Michael S. Tsirkin
2020-09-29  8:13 ` [PULL v4 00/48] virtio,pc,acpi: fixes, tests no-reply
2020-09-29  8:50 ` no-reply
2020-09-29 11:02 ` Peter Maydell
2020-09-29 11:04 ` Michael S. Tsirkin
2020-09-29 11:07   ` Peter Maydell
2020-09-29 11:13     ` Michael S. Tsirkin
2020-10-01  9:16       ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200929071948.281157-7-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=dimastep@yandex-team.ru \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.