From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsXra-0000Es-E8 for qemu-devel@nongnu.org; Wed, 13 May 2015 10:42:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YsXrU-000672-ED for qemu-devel@nongnu.org; Wed, 13 May 2015 10:42:22 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:42354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsXrU-00065d-68 for qemu-devel@nongnu.org; Wed, 13 May 2015 10:42:16 -0400 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 13 May 2015 15:42:14 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 947BF219005E for ; Wed, 13 May 2015 15:41:52 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t4DEgBww35848334 for ; Wed, 13 May 2015 14:42:11 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t4DEgA9e012559 for ; Wed, 13 May 2015 08:42:10 -0600 From: Cornelia Huck Date: Wed, 13 May 2015 16:42:02 +0200 Message-Id: <1431528122-50960-2-git-send-email-cornelia.huck@de.ibm.com> In-Reply-To: <1431528122-50960-1-git-send-email-cornelia.huck@de.ibm.com> References: <1431528122-50960-1-git-send-email-cornelia.huck@de.ibm.com> Subject: [Qemu-devel] [PATCH RFC 1/1] virtio: migrate config_vector List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Cornelia Huck , borntraeger@de.ibm.com, jjherne@linux.vnet.ibm.com, mst@redhat.com Currently, config_vector is managed in VirtIODevice, but migration is handled by the transport; this led to one transport using config_vector migrating correctly (pci), while the other forgot it (ccw). Let's have the core handle migration of config_vector in a vmstate subsection instead, so that we can keep it backwards compatible and no additional code is needed if config_vector is not used at all. Also provide a callback for virtio-pci so they can avoid introducing a subsection that is not needed and still be compatible in both directions. Reported-by: "Jason J. Herne" Signed-off-by: Cornelia Huck --- hw/virtio/virtio-pci.c | 14 ++++++++++++++ hw/virtio/virtio.c | 25 +++++++++++++++++++++++++ include/hw/virtio/virtio-bus.h | 5 +++++ 3 files changed, 44 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 867c9d1..4959b7d 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -971,6 +971,19 @@ static void virtio_pci_device_unplugged(DeviceState *d) virtio_pci_stop_ioeventfd(proxy); } +static bool virtio_pci_needs_confvec(DeviceState *d) +{ + VirtIOPCIProxy *proxy = VIRTIO_PCI(d); + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + + /* + * We don't want the core to create an unneeded vmstate subsection + * when we already migrate the config vector ourselves. + */ + return (vdev->config_vector != VIRTIO_NO_VECTOR) && + !msix_present(&proxy->pci_dev); +} + static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) { VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev); @@ -1505,6 +1518,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->device_plugged = virtio_pci_device_plugged; k->device_unplugged = virtio_pci_device_unplugged; k->query_nvectors = virtio_pci_query_nvectors; + k->needs_confvec = virtio_pci_needs_confvec; } static const TypeInfo virtio_pci_bus_info = { diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6985e76..3af530e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -903,6 +903,27 @@ static const VMStateDescription vmstate_virtio_device_endian = { } }; +static bool virtio_device_confvec_needed(void *opaque) +{ + VirtIODevice *vdev = opaque; + BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + + return k->needs_confvec ? + k->needs_confvec(qbus->parent) : + (vdev->config_vector != VIRTIO_NO_VECTOR); +} + +static const VMStateDescription vmstate_virtio_device_confvec = { + .name = "virtio/config_vector", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT16(config_vector, VirtIODevice), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_virtio = { .name = "virtio", .version_id = 1, @@ -916,6 +937,10 @@ static const VMStateDescription vmstate_virtio = { .vmsd = &vmstate_virtio_device_endian, .needed = &virtio_device_endian_needed }, + { + .vmsd = &vmstate_virtio_device_confvec, + .needed = &virtio_device_confvec_needed, + }, { 0 } } }; diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index a4588ca..79e6e8b 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -69,6 +69,11 @@ typedef struct VirtioBusClass { * Note that changing this will break migration for this transport. */ bool has_variable_vring_alignment; + /* + * (optional) Does the bus want the core to handle config_vector + * migration? This is for backwards compatibility only. + */ + bool (*needs_confvec)(DeviceState *d); } VirtioBusClass; struct VirtioBusState { -- 2.1.4