From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758433; cv=none; d=zoho.com; s=zohoarc; b=UUM7JQMBr4kVEIX4PrROCqpUQRIp4M/qTxhXOcBKn3/tab6BZ+t484tSyzQ3QN/IXR57n2Dsw3vFf12Gh6mdowzyhZ/a67ZhexV2NDNg3mnaYScZeq/Qc1vuM4CrABEH/UaVSY9Av1SqHy94mSe/NX6hBjrZwyYw7rhHfgn/wWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758433; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1xh+kYpl64/lhGe9fDnckHCq81F7ZpXGFWJx8wO2fW4=; b=i2uXIUDtjjWiIS6lbTJgHh6vKfqApyWxW0F9asc67jqo+YX8Qzr6CnpRKwOyb0bae/B+7CEbhoWMnjW4yokuqugMcIj3xHD2HsB9KYwMVNr3xQd9l9aI0WNgZ+YUf6m9Cd72/mmiGTlARwhxWh31XBqAaX6BQpuJ+984b4xkPL0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758433082140.66263330715663; Fri, 2 Aug 2019 08:07:13 -0700 (PDT) Received: from localhost ([::1]:35550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ9E-0006X9-3Y for importer@patchew.org; Fri, 02 Aug 2019 11:07:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47106) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8Q-0004qh-Fw for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8P-0005JH-55 for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33718) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8O-0005Iv-TR for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:21 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BE33305B1C1 for ; Fri, 2 Aug 2019 15:06:20 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D26C60BEC; Fri, 2 Aug 2019 15:06:14 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:05:57 +0200 Message-Id: <20190802150605.5880-2-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 02 Aug 2019 15:06:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/9] qdev/qbus: Add hidden device support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This adds support for hiding a device to the qbus and qdev APIs. qdev_device_add() is modified to check for a standby argument in the option string. A DeviceListener callback should_be_hidden() is added. It can be used by a standby device to inform qdev that this device should not be added now. The standby device handler can store the device options to plug the device in at a later point in time. Signed-off-by: Jens Freimann --- hw/core/qdev.c | 19 +++++++++++++++++++ hw/vfio/pci.c | 1 + hw/vfio/pci.h | 1 + include/hw/qdev-core.h | 8 ++++++++ qdev-monitor.c | 43 ++++++++++++++++++++++++++++++++++++++---- vl.c | 6 ++++-- 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 94ebc0a4a1..31e90ebaa2 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -211,6 +211,25 @@ void device_listener_unregister(DeviceListener *listen= er) QTAILQ_REMOVE(&device_listeners, listener, link); } =20 +bool qdev_should_hide_device(QemuOpts *opts, Error **errp) +{ + bool res =3D false; + bool match_found =3D false; + + DeviceListener *listener; + + QTAILQ_FOREACH(listener, &device_listeners, link) { + if (listener->should_be_hidden) { + listener->should_be_hidden(listener, opts, &match_found, &res); + } + + if (match_found) { + break; + } + } + return res; +} + void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version) { diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index d7a4e1875c..d6ae9bd4ac 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3105,6 +3105,7 @@ static Property vfio_pci_dev_properties[] =3D { display, ON_OFF_AUTO_OFF), DEFINE_PROP_UINT32("xres", VFIOPCIDevice, display_xres, 0), DEFINE_PROP_UINT32("yres", VFIOPCIDevice, display_yres, 0), + DEFINE_PROP_STRING("standby", VFIOPCIDevice, standby), DEFINE_PROP_UINT32("x-intx-mmap-timeout-ms", VFIOPCIDevice, intx.mmap_timeout, 1100), DEFINE_PROP_BIT("x-vga", VFIOPCIDevice, features, diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 834a90d646..27d58fc55b 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -134,6 +134,7 @@ typedef struct VFIOPCIDevice { PCIHostDeviceAddress host; EventNotifier err_notifier; EventNotifier req_notifier; + char *standby; int (*resetfn)(struct VFIOPCIDevice *); uint32_t vendor_id; uint32_t device_id; diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 136df7774c..6174538b01 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -158,6 +158,13 @@ struct DeviceState { struct DeviceListener { void (*realize)(DeviceListener *listener, DeviceState *dev); void (*unrealize)(DeviceListener *listener, DeviceState *dev); + /* + * This callback is called just upon init of the DeviceState + * and can be used by a standby device for informing qdev if this + * device should be hidden by checking the device opts + */ + void (*should_be_hidden)(DeviceListener *listener, QemuOpts *device_op= ts, + bool *match_found, bool *res); QTAILQ_ENTRY(DeviceListener) link; }; =20 @@ -457,5 +464,6 @@ void device_listener_unregister(DeviceListener *listene= r); VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev, VMChangeStateHandler = *cb, void *opaque); +bool qdev_should_hide_device(QemuOpts *opts, Error **errp); =20 #endif diff --git a/qdev-monitor.c b/qdev-monitor.c index 58222c2211..c69e283419 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -32,8 +32,10 @@ #include "qemu/help_option.h" #include "qemu/option.h" #include "qemu/qemu-print.h" +#include "qemu/option_int.h" #include "sysemu/block-backend.h" #include "migration/misc.h" +#include "migration/migration.h" =20 /* * Aliases were a bad idea from the start. Let's keep them @@ -561,14 +563,45 @@ void qdev_set_id(DeviceState *dev, const char *id) } } =20 +static int is_failover_device(void *opaque, const char *name, const char *= value, + Error **errp) +{ + if (strcmp(name, "standby") =3D=3D 0) { + QemuOpts *opts =3D (QemuOpts *)opaque; + + if (qdev_should_hide_device(opts, errp) && errp && !*errp) { + return 1; + } else if (errp && *errp) { + return -1; + } + } + + return 0; +} + +static bool should_hide_device(QemuOpts *opts, Error **err) +{ + if (qemu_opt_foreach(opts, is_failover_device, opts, err) =3D=3D 0) { + return false; + } + return true; +} + DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { DeviceClass *dc; const char *driver, *path; - DeviceState *dev; + DeviceState *dev =3D NULL; BusState *bus =3D NULL; Error *err =3D NULL; =20 + if (opts && should_hide_device(opts, &err)) { + if (err) { + goto err_del_dev; + } + return NULL; + } + driver =3D qemu_opt_get(opts, "driver"); if (!driver) { error_setg(errp, QERR_MISSING_PARAMETER, "driver"); @@ -640,8 +673,10 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **e= rrp) =20 err_del_dev: error_propagate(errp, err); - object_unparent(OBJECT(dev)); - object_unref(OBJECT(dev)); + if (dev) { + object_unparent(OBJECT(dev)); + object_unref(OBJECT(dev)); + } return NULL; } =20 @@ -810,7 +845,7 @@ void qdev_unplug(DeviceState *dev, Error **errp) return; } =20 - if (!migration_is_idle()) { + if (!migration_is_idle() && !migration_in_setup(migrate_get_current())= ) { error_setg(errp, "device_del not allowed while migrating"); return; } diff --git a/vl.c b/vl.c index b426b32134..1848195da7 100644 --- a/vl.c +++ b/vl.c @@ -2189,10 +2189,12 @@ static int device_init_func(void *opaque, QemuOpts = *opts, Error **errp) DeviceState *dev; =20 dev =3D qdev_device_add(opts, errp); - if (!dev) { + if (!dev && *errp) { + error_report_err(*errp); return -1; + } else if (dev) { + object_unref(OBJECT(dev)); } - object_unref(OBJECT(dev)); return 0; } =20 --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758438; cv=none; d=zoho.com; s=zohoarc; b=Z1r6X1LoJOn8y/IUrLA73p/tHE+/4UJfRb51oJEG/aZh8t2RB+XobYbiz7yaJl2sCkg85wBR43+JqlWLWa8iOHiq5wY3h9aUSD0r9dNmYfEDocK1aKyGSBD+BXE9HBMQauB/N5oE6foNfclmOuNGyZw6oYFkK0ijCo/j+q5Gby0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758438; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=s0SuQFo0cI6JLzEV967v1Hmkgm2vK43sh9rcx6maX8A=; b=nfAeYf9S8gSeTEuWIhVo4m6yfnL7kl3aWVpZVd+lvrMZmMZL2QI+LmnEvXAOeO404OsUANG8Dzkhnk3RldrjFgAEiG6ybBVLpHxT4HpvfWUKNoinvEB8iCQlYIvph8uq4kseYCeLP8iLMHCB59Y+eHbDp/Wa72prK2s7TimsPtI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758438757128.59311299188118; Fri, 2 Aug 2019 08:07:18 -0700 (PDT) Received: from localhost ([::1]:35552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ9J-0006m7-O7 for importer@patchew.org; Fri, 02 Aug 2019 11:07:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47125) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8T-0004w0-2j for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8R-0005K7-9y for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8R-0005Jl-2R for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5316930821DF for ; Fri, 2 Aug 2019 15:06:22 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A29955D712; Fri, 2 Aug 2019 15:06:21 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:05:58 +0200 Message-Id: <20190802150605.5880-3-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 02 Aug 2019 15:06:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/9] net/virtio: add failover support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch adds support to handle failover device pairs of a virtio-net device and a vfio-pci device, where the virtio-net acts as the standby device and the vfio-pci device as the primary. The general idea is that we have a pair of devices, a vfio-pci and a emulated (virtio-net) device. Before migration the vfio device is unplugged and data flows to the emulated device, on the target side another vfio-pci device is plugged in to take over the data-path. In the guest the net_failover module will pair net devices with the same MAC address. To achieve this we need: 1. Provide a callback function for the should_be_hidden DeviceListener. It is called when the primary device is plugged in. Evaluate the QOpt passed in to check if it is the matching primary device. It returns two values: - one to signal if the device to be added is the matching primary device - another one to signal to qdev if it should actually continue with adding the device or skip it. In the latter case it stores the device options in the VirtioNet struct and the device is added once the VIRTIO_NET_F_STANDBY feature is negotiated during virtio feature negotiation. 2. Register a callback for migration status notifier. When called it will unplug its primary device before the migration happens. Signed-off-by: Jens Freimann --- hw/net/virtio-net.c | 180 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-net.h | 13 +++ include/hw/virtio/virtio.h | 1 + 3 files changed, 194 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b9e1cd71cf..2f29155d9f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -12,6 +12,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/atomic.h" #include "qemu/iov.h" #include "qemu/module.h" #include "hw/virtio/virtio.h" @@ -20,16 +21,24 @@ #include "net/tap.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/option.h" +#include "qemu/option_int.h" +#include "qemu/config-file.h" +#include "qapi/qmp/qdict.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "net/announce.h" #include "hw/virtio/virtio-bus.h" #include "qapi/error.h" #include "qapi/qapi-events-net.h" +#include "qapi/qapi-types-migration.h" +#include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" #include "standard-headers/linux/ethtool.h" #include "trace.h" +#include "monitor/qdev.h" +#include "hw/pci/pci.h" =20 #define VIRTIO_NET_VM_VERSION 11 =20 @@ -743,6 +752,24 @@ static inline uint64_t virtio_net_supported_guest_offl= oads(VirtIONet *n) return virtio_net_guest_offloads_by_features(vdev->guest_features); } =20 +static void failover_add_primary(VirtIONet *n) +{ + Error *err =3D NULL; + + n->primary_device_opts =3D qemu_opts_find(qemu_find_opts("device"), + n->primary_device_id); + if (n->primary_device_opts) { + n->primary_dev =3D qdev_device_add(n->primary_device_opts, &err); + if (n->primary_dev) { + n->primary_bus =3D n->primary_dev->parent_bus; + } + } + if (err) { + error_report_err(err); + } +} + + static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) { VirtIONet *n =3D VIRTIO_NET(vdev); @@ -787,6 +814,11 @@ static void virtio_net_set_features(VirtIODevice *vdev= , uint64_t features) } else { memset(n->vlans, 0xff, MAX_VLAN >> 3); } + + if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) { + atomic_set(&n->primary_should_be_hidden, false); + failover_add_primary(n); + } } =20 static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, @@ -2627,6 +2659,119 @@ void virtio_net_set_netclient_name(VirtIONet *n, co= nst char *name, n->netclient_type =3D g_strdup(type); } =20 +static bool failover_unplug_primary(VirtIONet *n) +{ + HotplugHandler *hotplug_ctrl; + PCIDevice *pci_dev; + Error *err =3D NULL; + + hotplug_ctrl =3D qdev_get_hotplug_handler(n->primary_dev); + if (hotplug_ctrl) { + pci_dev =3D PCI_DEVICE(n->primary_dev); + pci_dev->partially_hotplugged =3D true; + hotplug_handler_unplug_request(hotplug_ctrl, n->primary_dev, &err); + if (err) { + error_report_err(err); + return false; + } + } else { + return false; + } + return true; +} + +static bool failover_replug_primary(VirtIONet *n, Error *err) +{ + HotplugHandler *hotplug_ctrl; + + if (!n->primary_device_opts) { + n->primary_device_opts =3D qemu_opts_from_qdict( + qemu_find_opts("device"), + n->primary_device_dict, &err); + } + if (n->primary_device_opts) { + qdev_set_parent_bus(n->primary_dev, n->primary_bus); + n->primary_should_be_hidden =3D false; + qemu_opt_set_bool(n->primary_device_opts, + "partially_hotplugged", true, &err); + hotplug_ctrl =3D qdev_get_hotplug_handler(n->primary_dev); + if (hotplug_ctrl) { + hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, &err); + hotplug_handler_plug(hotplug_ctrl, n->primary_dev, &err); + } + if (!n->primary_dev) { + error_setg(&err, "virtio_net: couldn't find primary device"); + } + } + return err !=3D NULL; +} + +static void virtio_net_handle_migration_primary(VirtIONet *n, + MigrationState *s) +{ + bool should_be_hidden; + Error *err =3D NULL; + + should_be_hidden =3D atomic_read(&n->primary_should_be_hidden); + + if (!n->primary_dev) { + error_report("virtio_net: couldn't find primary device"); + return; + } + + if (migration_in_setup(s) && !should_be_hidden && + n->primary_dev) { + if (failover_unplug_primary(n)) { + vmstate_unregister(n->primary_dev, qdev_get_vmsd(n->primary_de= v), + n->primary_dev); + qapi_event_send_unplug_primary(n->primary_device_id); + atomic_set(&n->primary_should_be_hidden, true); + } else { + error_report("virtio_net: Couldn't unplug primary device"); + } + } else if (migration_has_failed(s)) { + /* We already unplugged the device let's plugged it back */ + if (!failover_replug_primary(n, err)) { + error_report_err(err); + } + } +} + +static void migration_state_notifier(Notifier *notifier, void *data) +{ + MigrationState *s =3D data; + VirtIONet *n =3D container_of(notifier, VirtIONet, migration_state); + virtio_net_handle_migration_primary(n, s); +} + +static void virtio_net_primary_should_be_hidden(DeviceListener *listener, + QemuOpts *device_opts, bool *match_found, bool *res) +{ + VirtIONet *n =3D container_of(listener, VirtIONet, primary_listener); + + if (device_opts) { + n->primary_device_dict =3D qemu_opts_to_qdict(device_opts, + n->primary_device_dict); + n->primary_device_opts =3D device_opts; + } + g_free(n->standby_id); + n->standby_id =3D g_strdup(qdict_get_try_str(n->primary_device_dict, + "standby")); + if (n->standby_id) { + *match_found =3D true; + } + /* primary_should_be_hidden is set during feature negotiation */ + if (atomic_read(&n->primary_should_be_hidden) && *match_found) { + *res =3D true; + } else if (*match_found) { + n->primary_device_dict =3D qemu_opts_to_qdict(device_opts, + n->primary_device_dict); + *res =3D false; + } + g_free(n->primary_device_id); + n->primary_device_id =3D g_strdup(device_opts->id); +} + static void virtio_net_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -2657,6 +2802,16 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) n->host_features |=3D (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); } =20 + if (n->failover) { + n->primary_listener.should_be_hidden =3D + virtio_net_primary_should_be_hidden; + atomic_set(&n->primary_should_be_hidden, true); + device_listener_register(&n->primary_listener); + n->migration_state.notify =3D migration_state_notifier; + add_migration_state_change_notifier(&n->migration_state); + n->host_features |=3D (1ULL << VIRTIO_NET_F_STANDBY); + } + virtio_net_set_config_size(n, n->host_features); virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size); =20 @@ -2779,6 +2934,13 @@ static void virtio_net_device_unrealize(DeviceState = *dev, Error **errp) g_free(n->mac_table.macs); g_free(n->vlans); =20 + if (n->failover) { + g_free(n->primary_device_id); + g_free(n->standby_id); + qobject_unref(n->primary_device_dict); + n->primary_device_dict =3D NULL; + } + max_queues =3D n->multiqueue ? n->max_queues : 1; for (i =3D 0; i < max_queues; i++) { virtio_net_del_queue(n, i); @@ -2816,6 +2978,21 @@ static int virtio_net_pre_save(void *opaque) return 0; } =20 +static bool primary_unplug_pending(void *opaque) +{ + VirtIONet *n =3D opaque; + + return n ? n->primary_dev->pending_deleted_event : false; +} + +static bool dev_unplug_pending(void *opaque) +{ + DeviceState *dev =3D opaque; + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(dev); + + return vdc->primary_unplug_pending(dev); +} + static const VMStateDescription vmstate_virtio_net =3D { .name =3D "virtio-net", .minimum_version_id =3D VIRTIO_NET_VM_VERSION, @@ -2825,6 +3002,7 @@ static const VMStateDescription vmstate_virtio_net = =3D { VMSTATE_END_OF_LIST() }, .pre_save =3D virtio_net_pre_save, + .dev_unplug_pending =3D dev_unplug_pending, }; =20 static Property virtio_net_properties[] =3D { @@ -2886,6 +3064,7 @@ static Property virtio_net_properties[] =3D { true), DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN), DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), + DEFINE_PROP_BOOL("failover", VirtIONet, failover, false), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -2910,6 +3089,7 @@ static void virtio_net_class_init(ObjectClass *klass,= void *data) vdc->guest_notifier_pending =3D virtio_net_guest_notifier_pending; vdc->legacy_features |=3D (0x1 << VIRTIO_NET_F_GSO); vdc->vmsd =3D &vmstate_virtio_net_device; + vdc->primary_unplug_pending =3D primary_unplug_pending; } =20 static const TypeInfo virtio_net_info =3D { diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index b96f0c643f..08392df2cd 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -18,6 +18,7 @@ #include "standard-headers/linux/virtio_net.h" #include "hw/virtio/virtio.h" #include "net/announce.h" +#include "qemu/option_int.h" =20 #define TYPE_VIRTIO_NET "virtio-net-device" #define VIRTIO_NET(obj) \ @@ -43,6 +44,7 @@ typedef struct virtio_net_conf int32_t speed; char *duplex_str; uint8_t duplex; + char *primary_id_str; } virtio_net_conf; =20 /* Coalesced packets type & status */ @@ -185,6 +187,17 @@ struct VirtIONet { AnnounceTimer announce_timer; bool needs_vnet_hdr_swap; bool mtu_bypass_backend; + QemuOpts *primary_device_opts; + QDict *primary_device_dict; + DeviceState *primary_dev; + BusState *primary_bus; + char *primary_device_id; + char *standby_id; + bool primary_should_be_hidden; + bool failover; + DeviceListener primary_listener; + QEMUTimer *primary_device_timer; + Notifier migration_state; }; =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b189788cb2..dcb3ee6916 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -159,6 +159,7 @@ typedef struct VirtioDeviceClass { void (*save)(VirtIODevice *vdev, QEMUFile *f); int (*load)(VirtIODevice *vdev, QEMUFile *f, int version_id); const VMStateDescription *vmsd; + bool (*primary_unplug_pending)(void *opaque); } VirtioDeviceClass; =20 void virtio_instance_init_common(Object *proxy_obj, void *data, --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758498; cv=none; d=zoho.com; s=zohoarc; b=bFzWWIi/gpWJOVcsWBZSZSNNw6kQ5PgxNPBohx381cQ0AWGA5AixRudCU/+zk353dGC54wGDMl3seKPqNXmxcwftAcF6t2vp6T+S2fLHzMgsw4Kl+5wAohemwtBULoIbihk+ClDt7AdTZE6zOWd1wikQwxQqiCtJc1uIB79c76E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758498; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Nn+6XZcqAkdLXX4f2KSSE1cQDSkfAyincbOB0MKx6Sc=; b=ZmIYwLIADDUHOQPMtT1JUWRqPEyUuc0RvKMcR9j+UMkBxtItmJH5taPGS8LwG02tjSleuX1CMnnFwGdwgbClpSM09kFwdyzuk+rBXskOqx0CpKoFPTABcO6Cf7WrEH3TBPiIIIum6DT7cTNPbSJcSUhhzj87tCef5wkPP+h8UEw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758498120125.89713337972921; Fri, 2 Aug 2019 08:08:18 -0700 (PDT) Received: from localhost ([::1]:35575 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZAH-0001JY-4A for importer@patchew.org; Fri, 02 Aug 2019 11:08:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47160) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8a-0005Jf-Hq for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8Z-0005NK-CZ for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47696) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8Z-0005N4-54 for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D233C027339 for ; Fri, 2 Aug 2019 15:06:30 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7301600C8; Fri, 2 Aug 2019 15:06:23 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:05:59 +0200 Message-Id: <20190802150605.5880-4-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Aug 2019 15:06:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/9] vfio: unplug failover primary device before migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" As usual block all vfio-pci devices from being migrated, but make an exception for failover primary devices. This is achieved by setting unmigratable to 0 but also add a migration blocker for all vfio-pci devices except failover primary devices. These will be unplugged before migration happens by the migration handler of the corresponding virtio-net standby device. Signed-off-by: Jens Freimann --- hw/vfio/pci.c | 24 +++++++++++++++++++++++- hw/vfio/pci.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index d6ae9bd4ac..398d26669b 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -35,6 +35,9 @@ #include "pci.h" #include "trace.h" #include "qapi/error.h" +#include "migration/blocker.h" +#include "qemu/option.h" +#include "qemu/option_int.h" =20 #define TYPE_VFIO_PCI "vfio-pci" #define PCI_VFIO(obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI) @@ -2693,6 +2696,12 @@ static void vfio_unregister_req_notifier(VFIOPCIDevi= ce *vdev) vdev->req_enabled =3D false; } =20 +static int has_standby_arg(void *opaque, const char *name, + const char *value, Error **errp) +{ + return strcmp(name, "standby") =3D=3D 0; +} + static void vfio_realize(PCIDevice *pdev, Error **errp) { VFIOPCIDevice *vdev =3D PCI_VFIO(pdev); @@ -2706,6 +2715,19 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) int i, ret; bool is_mdev; =20 + if (qemu_opt_foreach(pdev->qdev.opts, has_standby_arg, + (void *) pdev->qdev.opts, &err) =3D=3D 0) { + error_setg(&vdev->migration_blocker, + "VFIO device doesn't support migration"); + ret =3D migrate_add_blocker(vdev->migration_blocker, &err); + if (err) { + error_propagate(errp, err); + error_free(vdev->migration_blocker); + } + } else { + pdev->qdev.allow_unplug_during_migration =3D true; + } + if (!vdev->vbasedev.sysfsdev) { if (!(~vdev->host.domain || ~vdev->host.bus || ~vdev->host.slot || ~vdev->host.function)) { @@ -3148,7 +3170,7 @@ static Property vfio_pci_dev_properties[] =3D { =20 static const VMStateDescription vfio_pci_vmstate =3D { .name =3D "vfio-pci", - .unmigratable =3D 1, + .unmigratable =3D 0, }; =20 static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 27d58fc55b..0f6f8cb395 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -169,6 +169,7 @@ typedef struct VFIOPCIDevice { bool no_vfio_ioeventfd; bool enable_ramfb; VFIODisplay *dpy; + Error *migration_blocker; } VFIOPCIDevice; =20 uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758597; cv=none; d=zoho.com; s=zohoarc; b=MWbwEDhC2mVm5E4fczfxSnIf4kmTpx7l/11TMBykmO+j3Krfij/pDrGvQMxTpxdI3Fo2w4BKv/HrvxN5KYxtuGY2fFKogZuUIoagkLhhF4DYLQeJfx5HyFzBempL9bo/7kRrxqc6K8CWUzmDTdUbmrbrcNlEMBkd9rK2ziDfMNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758597; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4v/f44smzSERAFH8pzW/nj68KZ68AhLKPEt2Lu2MTGM=; b=boEfPZBIzFY12QTBycsTzjNKmmofahNgVLtQ/LaJhY54IPWkyrlZLpTQ/SQih398Y0e3DoFN9FlIdGkwFSkSPlnvNVgVwW/4maYuHzHbxyaEWq+jTdggaRUfykzeW+BX/nkk7tS11qcNdph4M1fOcmOHb9YLuzHuZ5gXU5/DVyk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758597234472.1363144958665; Fri, 2 Aug 2019 08:09:57 -0700 (PDT) Received: from localhost ([::1]:35596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZBs-0004WW-9a for importer@patchew.org; Fri, 02 Aug 2019 11:09:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47191) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8h-0005gh-Js for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8g-0005Pn-Gi for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8g-0005PX-BU for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6CEA882EA for ; Fri, 2 Aug 2019 15:06:37 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F41DB60605; Fri, 2 Aug 2019 15:06:31 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:06:00 +0200 Message-Id: <20190802150605.5880-5-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 02 Aug 2019 15:06:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/9] migration: allow unplug during migration for failover devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In "b06424de62 migration: Disable hotplug/unplug during migration" we added a check to disable unplug for all devices until we have figured out what works. For failover primary devices qdev_unplug() is called from the migration handler, i.e. during migration. This patch adds a flag to DeviceState which is set to false for all devices and makes an exception for vfio-pci devices that are also primary devices in a failover pair. Signed-off-by: Jens Freimann --- hw/core/qdev.c | 1 + include/hw/qdev-core.h | 1 + qdev-monitor.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 31e90ebaa2..f43f744133 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -973,6 +973,7 @@ static void device_initfn(Object *obj) =20 dev->instance_id_alias =3D -1; dev->realized =3D false; + dev->allow_unplug_during_migration =3D false; =20 object_property_add_bool(obj, "realized", device_get_realized, device_set_realized, NUL= L); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 6174538b01..af4857d391 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -147,6 +147,7 @@ struct DeviceState { bool pending_deleted_event; QemuOpts *opts; int hotplugged; + bool allow_unplug_during_migration; BusState *parent_bus; QLIST_HEAD(, NamedGPIOList) gpios; QLIST_HEAD(, BusState) child_bus; diff --git a/qdev-monitor.c b/qdev-monitor.c index c69e283419..e7ab5cacb3 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -845,7 +845,7 @@ void qdev_unplug(DeviceState *dev, Error **errp) return; } =20 - if (!migration_is_idle() && !migration_in_setup(migrate_get_current())= ) { + if (!migration_is_idle() && !dev->allow_unplug_during_migration) { error_setg(errp, "device_del not allowed while migrating"); return; } --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758453; cv=none; d=zoho.com; s=zohoarc; b=Twy5UZbclPxN6sSb3x3QZvI5KciaSjrYA4SaAL0vwuFNJHeBtTk4zS6EN/3GPBQhH+chpwKqKAWLtt3CI6QVYqxnUqlilIMGxItPGZhxn5CkJ+5WT4/MmaqPiaKkwq6HUEYAIdah/tqOIGsVgfQprZf6BnVqvMICXOCQEwjahA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758453; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/B+zHSbEpY80RyAbjY3k0LAK+S+yyQ5G0D6l0rTjOyw=; b=ILXAbExduEpDAego5OKvzMYeJP4V6lAPG07saBxG34OhxkZfQO+FYwo4pf54ziiTrgwRAVXY707Wr0Zm4r2niNmUkifQMIOAqyJk/r3RM/lQvouIklGfLfOo7oNonEDU2XgnSSKFSjWsvmhFlUtstiwSlJOBevxKBk1+A37OoJ8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758453530335.72885600280927; Fri, 2 Aug 2019 08:07:33 -0700 (PDT) Received: from localhost ([::1]:35554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ9Y-0007UY-C0 for importer@patchew.org; Fri, 02 Aug 2019 11:07:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47206) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8j-0005ka-AH for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8i-0005QW-CY for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8i-0005QE-78 for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87F2F3082E20 for ; Fri, 2 Aug 2019 15:06:39 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DFF660623; Fri, 2 Aug 2019 15:06:39 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:06:01 +0200 Message-Id: <20190802150605.5880-6-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 02 Aug 2019 15:06:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/9] qapi: add unplug primary event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add new qmp event to send the device id of a device that was requested to be unplugged by the guest OS. =20 Signed-off-by: Jens Freimann --- qapi/migration.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/qapi/migration.json b/qapi/migration.json index 9cfbaf8c6c..d567ac9fc3 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1445,3 +1445,22 @@ # Since: 3.0 ## { 'command': 'migrate-pause', 'allow-oob': true } + +## +# @UNPLUG_PRIMARY: +# +# Emitted from source side of a migration when migration state is +# WAIT_UNPLUG. Device was unplugged by guest operating system. +# Device resources in QEMU are kept on standby to be able to re-plug it in= case +# of migration failure. +# +# @device_id: QEMU device id of the unplugged device +# +# Since: 4.2 +# +# Example: +# {"event": "UNPLUG_PRIMARY", "data": {"device_id": "hostdev0"} } +# +## +{ 'event': 'UNPLUG_PRIMARY', + 'data': { 'device_id': 'str' } } --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758521; cv=none; d=zoho.com; s=zohoarc; b=LB4wSgV9CtmUW6KuUkqaKGjgQTzCnYxbNbTRwZd9yYCNgeZJkRYUYU8iPip3xBq7yXdh42XayzUyZemn6YPjd2WvIfz0muwGaCI2KdaA8ehsa6TnV1nJHakGUNl7x4sK8k0ss/YYy/DTiikTPxByv/aXSReEdChJoEnmPaSir1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758521; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=3TtMbHh7mncbB8bHB0oGrXGhFbMWL4LfyDpyaDLfDas=; b=a2rn6tjCTwfZWkIObtA5PWgn38NeGFlCdTuuD1EEDvnzAN0XEyA5QJ+Pv/VTRmiy+ARPJWt3Bys00vHwBBtPUfItRFLktQxNgwVEO/0AXzB+wZL6IutxgwQ9zvSwszHmldRcKo5Jue504Rjh7NzDcJcuwaxSEQNbaXlfV7K2CF4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758521110640.1106761507523; Fri, 2 Aug 2019 08:08:41 -0700 (PDT) Received: from localhost ([::1]:35580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZAe-0002UX-5Y for importer@patchew.org; Fri, 02 Aug 2019 11:08:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47234) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8q-000662-Cb for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8p-0005T0-C2 for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8p-0005Sg-6w for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36A6781F01 for ; Fri, 2 Aug 2019 15:06:46 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04B505D9E2; Fri, 2 Aug 2019 15:06:40 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:06:02 +0200 Message-Id: <20190802150605.5880-7-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 02 Aug 2019 15:06:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 6/9] qapi: Add failover negotiated event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This event is sent to let libvirt know that VIRTIO_NET_F_STANDBY feature was not negotiated during virtio feature negotiation. If this event is received it means any primary devices hotplugged before this were were never really added to QEMU devices. Signed-off-by: Jens Freimann --- qapi/net.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qapi/net.json b/qapi/net.json index 728990f4fb..8c5f3f1fb2 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -737,3 +737,19 @@ ## { 'command': 'announce-self', 'boxed': true, 'data' : 'AnnounceParameters'} + +## +# @FAILOVER_NEGOTIATED: +# +# Emitted when VIRTIO_NET_F_STANDBY was negotiated during feature negotiat= ion +# +# Since: 4.2 +# +# Example: +# +# <- { "event": "FAILOVER_NEGOTIATED", +# "data": {} } +# +## +{ 'event': 'FAILOVER_NEGOTIATED', + 'data': {} } --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758618; cv=none; d=zoho.com; s=zohoarc; b=BJDJ+2vdSrn+uUCOWTB5wjtll4MDsgsyLXe5lox6mgGjJiLZQ4c0W6+fMcOneo4yJQOt6rM1vIKkECWuMqor0wljNmP9SFkeK4k6JaYZVbRd2rSDih8Bzf4YmL2N+GQbAuEEhlBpu+ogvl+yOzz1n8wIIq57s8npAzzyMdfShEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758618; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Eh7VAUnN365rKLNj/0FyHtdvbBofoynNVxMWobTfHEU=; b=moCup2Y57RFYouAlBFfkQ0rvVw27IbsgQX4rUp/iwmo3ytGnv0paRXBHcyCm2vKKtxvnVdAOB3x7N19YtzHulf5oqpuiUcN54oMedKDjGTZifDKUqc3ELr47bnDkugIvhqNOzufv8YWcHad1ET8mflLK6Wk7gF8YXsJRLUBIXu4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758618126109.65588021196072; Fri, 2 Aug 2019 08:10:18 -0700 (PDT) Received: from localhost ([::1]:35600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZCD-0005NU-79 for importer@patchew.org; Fri, 02 Aug 2019 11:10:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47246) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8s-0006AN-FQ for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8r-0005Tq-43 for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8q-0005TL-Rf for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18BABC057EC0 for ; Fri, 2 Aug 2019 15:06:48 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A889A5D9D3; Fri, 2 Aug 2019 15:06:47 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:06:03 +0200 Message-Id: <20190802150605.5880-8-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 02 Aug 2019 15:06:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 7/9] migration: Add new migration state wait-unplug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch is not ready for inclusion yet, I'm looking for feedback/ideas on a particular problem. See below. This patch adds a new migration state called wait-unplug. It is entered after the SETUP state and will transition into ACTIVE once all devices were succesfully unplugged from the guest. So if a guest doesn't respond or takes long to honor the unplug request the user will see the migration state 'wait-unplug'. It adds a new function callback to VMStateDescription which is called for every device that implements it and reports its device_pending status. Now this loop in the migration thread: while (qemu_savevm_state_guest_unplug_pending()) { continue; } clearly needs a condition to terminate after a while/or a certain number of iterations. But I'm not sure what is a good solution. How much waiting time is acceptable for a migration? Signed-off-by: Jens Freimann --- include/migration/vmstate.h | 2 ++ migration/migration.c | 14 ++++++++++++++ migration/savevm.c | 18 ++++++++++++++++++ migration/savevm.h | 1 + qapi/migration.json | 5 ++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index c2bfa7a7f0..8b2a125c4c 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -187,6 +187,8 @@ struct VMStateDescription { int (*pre_save)(void *opaque); int (*post_save)(void *opaque); bool (*needed)(void *opaque); + bool (*dev_unplug_pending)(void *opaque); + const VMStateField *fields; const VMStateDescription **subsections; }; diff --git a/migration/migration.c b/migration/migration.c index 8a607fe1e2..a7d21b73fe 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -946,6 +946,9 @@ static void fill_source_migration_info(MigrationInfo *i= nfo) case MIGRATION_STATUS_CANCELLED: info->has_status =3D true; break; + case MIGRATION_STATUS_WAIT_UNPLUG: + info->has_status =3D true; + break; } info->status =3D s->state; } @@ -1680,6 +1683,7 @@ bool migration_is_idle(void) case MIGRATION_STATUS_COLO: case MIGRATION_STATUS_PRE_SWITCHOVER: case MIGRATION_STATUS_DEVICE: + case MIGRATION_STATUS_WAIT_UNPLUG: return false; case MIGRATION_STATUS__MAX: g_assert_not_reached(); @@ -1712,6 +1716,7 @@ void migrate_init(MigrationState *s) error_free(s->error); s->error =3D NULL; =20 + /* go to WAIT_UNPLUG first? */ migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_S= ETUP); =20 s->start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); @@ -3218,6 +3223,15 @@ static void *migration_thread(void *opaque) =20 qemu_savevm_state_setup(s->to_dst_file); =20 + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_WAIT_UNPLUG); + while (qemu_savevm_state_guest_unplug_pending()) { + continue; + } + migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG, + MIGRATION_STATUS_ACTIVE);=20 + + s->setup_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE); diff --git a/migration/savevm.c b/migration/savevm.c index 79ed44d475..2bb54b3a8a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1085,6 +1085,24 @@ void qemu_savevm_state_header(QEMUFile *f) } } =20 +bool qemu_savevm_state_guest_unplug_pending(void) +{ + SaveStateEntry *se; + bool ret =3D false; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (!se->vmsd || !se->vmsd->dev_unplug_pending) { + continue; + } + ret =3D se->vmsd->dev_unplug_pending(se->opaque); + if (ret) { + break; + } + } + + return ret; +} + void qemu_savevm_state_setup(QEMUFile *f) { SaveStateEntry *se; diff --git a/migration/savevm.h b/migration/savevm.h index 51a4b9caa8..ba64a7e271 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -31,6 +31,7 @@ =20 bool qemu_savevm_state_blocked(Error **errp); void qemu_savevm_state_setup(QEMUFile *f); +bool qemu_savevm_state_guest_unplug_pending(void); int qemu_savevm_state_resume_prepare(MigrationState *s); void qemu_savevm_state_header(QEMUFile *f); int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy); diff --git a/qapi/migration.json b/qapi/migration.json index d567ac9fc3..c42381a85f 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -133,6 +133,9 @@ # @device: During device serialisation when pause-before-switchover is ena= bled # (since 2.11) # +# @wait-unplug: wait for device unplug request by guest OS to be completed. +# (since 4.2)=20 +# # Since: 2.3 # ## @@ -140,7 +143,7 @@ 'data': [ 'none', 'setup', 'cancelling', 'cancelled', 'active', 'postcopy-active', 'postcopy-paused', 'postcopy-recover', 'completed', 'failed', 'colo', - 'pre-switchover', 'device' ] } + 'pre-switchover', 'device', 'wait-unplug' ] } =20 ## # @MigrationInfo: --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758506; cv=none; d=zoho.com; s=zohoarc; b=oXgZEqto2EH4rvHGvD9OSwQjnzkrYzxaTbBoi4DTC/gMCleIhupP0Fb65YcHK0WS7EodqBZ835VIOfboluwViZiUZL3qVgb5MoFTxfxrXtf6BT9AVZyQwMEnXbHFQ3hYIN0qIvxMD0TX/yp1OK/Ozbh3uiE+KlNU79uPmY1lHfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758506; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ikt9zLbg411eRQvS7vRgP0nHqXQGt0alk6VJecMeV+w=; b=B73vtugcDRmGKEfirub6nP5AOeAzjdWZIRj2rOqoKlob+QS7D+jkJFf+6VzIEQ8CbBNlsazZGABg9zp7J2kD/X6r9Wdmkwg9atjmNdZRodKv+Tv/HksBrYnwhI7KSxUxdRQHYkLHmzx426jUPkiQ0v2Ja/KX/urXnYO+DNjmURg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758506616454.2017227240393; Fri, 2 Aug 2019 08:08:26 -0700 (PDT) Received: from localhost ([::1]:35578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZAP-0001kJ-MY for importer@patchew.org; Fri, 02 Aug 2019 11:08:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47272) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ8u-0006Ff-0m for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8s-0005US-Om for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36796) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8s-0005UD-Jl for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC7F5307D88C for ; Fri, 2 Aug 2019 15:06:49 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D4EC5D9D3; Fri, 2 Aug 2019 15:06:49 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:06:04 +0200 Message-Id: <20190802150605.5880-9-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 02 Aug 2019 15:06:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 8/9] pci: mark devices partially unplugged X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Only the guest unplug request was triggered. This is needed for the failover feature. In case of a failed migration we need to plug the device back to the guest. Signed-off-by: Jens Freimann --- hw/pci/pci.c | 2 ++ hw/pci/pcie.c | 3 +++ include/hw/pci/pci.h | 1 + 3 files changed, 6 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 8076a80ab3..935127a98f 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2074,6 +2074,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error= **errp) Error *local_err =3D NULL; bool is_default_rom; =20 + pci_dev->partially_hotplugged =3D false; + /* initialize cap_present for pci_is_express() and pci_config_size(), * Note that hybrid PCIs are not set automatically and need to manage * QEMU_PCI_CAP_EXPRESS manually */ diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index a6beb567bd..19363ff8ce 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -456,6 +456,9 @@ static void pcie_unplug_device(PCIBus *bus, PCIDevice *= dev, void *opaque) { HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(dev)); =20 + if (dev->partially_hotplugged) { + return; + } hotplug_handler_unplug(hotplug_ctrl, DEVICE(dev), &error_abort); object_unparent(OBJECT(dev)); } diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index aaf1b9f70d..e0b82d3ad4 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -265,6 +265,7 @@ typedef struct PCIReqIDCache PCIReqIDCache; =20 struct PCIDevice { DeviceState qdev; + bool partially_hotplugged; =20 /* PCI config space */ uint8_t *config; --=20 2.21.0 From nobody Sun May 19 01:15:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564758502; cv=none; d=zoho.com; s=zohoarc; b=IAO+Ww5POtYADo+W6gOLr3Iu3d/rEl0FgmatQq5ZND6Ca7ABZSZy//O8CIH/06nnN9YVSPCCp8VDJBnWHEPhIrW8NhNVdZP18+9m49zGwCMWMpCJ1wW1tyFgXlhn1dpHCLMx350leD7fR9MWGMsy+LbAqPIyveJUol4kL8dLRJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564758502; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=XiocduzpqkNcQ5CsTezb/79dMcBff+m7HNkItDQZfIo=; b=UU6MZ3G9vuNIczZaGEglFwovBQ4LukwSK1s/TusW1NyVWH0/lxWsRkLTP+gUptGJufaxRX3APj3RT3qqk6HVrdNO5wTbfGOAAxYATx3TMYRY2iG74gknKjZKB6i8FYFxX8Jhcl+X3Y8wqZhegZGKB9IBpbivg+SCoWueGK2N5Ik= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564758502101888.2067767159083; Fri, 2 Aug 2019 08:08:22 -0700 (PDT) Received: from localhost ([::1]:35576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZAL-0001V5-5W for importer@patchew.org; Fri, 02 Aug 2019 11:08:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47312) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htZ90-0006Zh-5B for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htZ8z-0005Xr-85 for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56932) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htZ8z-0005XX-36 for qemu-devel@nongnu.org; Fri, 02 Aug 2019 11:06:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DD268F91B for ; Fri, 2 Aug 2019 15:06:56 +0000 (UTC) Received: from localhost (dhcp-192-195.str.redhat.com [10.33.192.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 66A4C60623; Fri, 2 Aug 2019 15:06:51 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 2 Aug 2019 17:06:05 +0200 Message-Id: <20190802150605.5880-10-jfreimann@redhat.com> In-Reply-To: <20190802150605.5880-1-jfreimann@redhat.com> References: <20190802150605.5880-1-jfreimann@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 02 Aug 2019 15:06:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 9/9] pci: mark device having guest unplug request pending X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, berrange@redhat.com, ehabkost@redhat.com, mst@redhat.com, aadam@redhat.com, laine@redhat.com, ailan@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Set pending_deleted_event before triggering the unplug request and reset it in the unplug handler when the device is marked as partially hotplugged. This is required to be able to plug it back in in case of a migration failure. Signed-off-by: Jens Freimann --- hw/pci/pcie.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 19363ff8ce..08718188bb 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -457,6 +457,7 @@ static void pcie_unplug_device(PCIBus *bus, PCIDevice *= dev, void *opaque) HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(dev)); =20 if (dev->partially_hotplugged) { + dev->qdev.pending_deleted_event =3D false; return; } hotplug_handler_unplug(hotplug_ctrl, DEVICE(dev), &error_abort); @@ -476,6 +477,8 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *ho= tplug_dev, return; } =20 + dev->pending_deleted_event =3D true; + /* In case user cancel the operation of multi-function hot-add, * remove the function that is unexposed to guest individually, * without interaction with guest. --=20 2.21.0