Received: from eggs.gnu.org ([2001:4830:134:3::10]:56224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX71v-0002EB-0q for qemu-devel@nongnu.org; Wed, 02 Sep 2015 08:20:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZX71q-0007qA-Ct for qemu-devel@nongnu.org; Wed, 02 Sep 2015 08:20:42 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:43192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX71p-0007oO-LO for qemu-devel@nongnu.org; Wed, 02 Sep 2015 08:20:38 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 2 Sep 2015 13:20:35 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 19A6633201C2 for ; Wed, 2 Sep 2015 12:08:15 +0100 (BST) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t82B6WxR31326448 for ; Wed, 2 Sep 2015 11:06:32 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t82B6W1P014040 for ; Wed, 2 Sep 2015 05:06:32 -0600 Date: Wed, 2 Sep 2015 13:06:30 +0200 From: Cornelia Huck Message-ID: <20150902130630.662ae71b.cornelia.huck@de.ibm.com> In-Reply-To: <1441164325-14417-5-git-send-email-jasowang@redhat.com> References: <1441164325-14417-1-git-send-email-jasowang@redhat.com> <1441164325-14417-5-git-send-email-jasowang@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V2 4/8] virtio-pci: fix 1.0 virtqueue migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang Cc: qemu-devel@nongnu.org, mst@redhat.com On Wed, 2 Sep 2015 11:25:21 +0800 Jason Wang wrote: > We don't migrate the followings fields for virtio-pci: > > uint32_t dfselect; > uint32_t gfselect; > uint32_t guest_features[2]; > struct { > uint16_t num; > bool enabled; > uint32_t desc[2]; > uint32_t avail[2]; > uint32_t used[2]; > } vqs[VIRTIO_QUEUE_MAX]; > > This will confuse driver if migrating during initialization. Solves > this issue by: > > - introduce transport specific callbacks to load and store extra > virtqueue states. > - add a new subsection for virtio to migrate transport specific modern > device state. > - implement pci specific callbacks. > - add a new property for virtio-pci for whether or not to migrate > extra state. > - compat the migration for 2.4 and elder machine types > > Cc: Michael S. Tsirkin > Signed-off-by: Jason Wang > --- > hw/virtio/virtio-pci.c | 129 +++++++++++++++++++++++++++++++++++++++++ > hw/virtio/virtio-pci.h | 20 ++++--- > hw/virtio/virtio.c | 57 ++++++++++++++++++ > include/hw/compat.h | 6 +- > include/hw/virtio/virtio-bus.h | 3 + > 5 files changed, 207 insertions(+), 8 deletions(-) > > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > index c024161..a96890b 100644 > --- a/hw/virtio/virtio-pci.c > +++ b/hw/virtio/virtio-pci.c > @@ -86,6 +86,129 @@ static void virtio_pci_save_config(DeviceState *d, QEMUFile *f) > qemu_put_be16(f, vdev->config_vector); > } > > +static void virtio_pci_load_modern_queue_state(VirtIOPCIQueue *vq, > + QEMUFile *f) > +{ > + vq->num = qemu_get_be16(f); > + vq->enabled = qemu_get_be16(f); > + vq->desc[0] = qemu_get_be32(f); > + vq->desc[1] = qemu_get_be32(f); > + vq->avail[0] = qemu_get_be32(f); > + vq->avail[1] = qemu_get_be32(f); > + vq->used[0] = qemu_get_be32(f); > + vq->used[1] = qemu_get_be32(f); > +} > + > +static bool virtio_pci_has_extra_state(DeviceState *d) > +{ > + VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); > + > + return proxy->flags & VIRTIO_PCI_FLAG_MIGRATE_EXTRA; Hm, couldn't you already check whether this is a modern device here? You don't need to save state for a legacy device, do you? > +} > + (...) > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 788b556..dcaf022 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -1056,6 +1056,16 @@ static bool virtio_virtqueue_needed(void *opaque) > return virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1); > } > > +static bool virtio_extra_state_needed(void *opaque) > +{ > + VirtIODevice *vdev = opaque; > + BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); > + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); > + > + return k->has_extra_state && > + k->has_extra_state(qbus->parent); > +} > + > static void put_virtqueue_state(QEMUFile *f, void *pv, size_t size) > { > VirtIODevice *vdev = pv; > @@ -1104,6 +1114,52 @@ static const VMStateDescription vmstate_virtio_virtqueues = { > } > }; > > +static int get_extra_state(QEMUFile *f, void *pv, size_t size) > +{ > + VirtIODevice *vdev = pv; > + BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); > + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); > + int ret = 0; > + > + ret = k->load_extra_state(qbus->parent, f); Should we check for ->load_extra_state() and return failure if it does not exist? > + > + return ret; > +} > + > +static void put_extra_state(QEMUFile *f, void *pv, size_t size) > +{ > + VirtIODevice *vdev = pv; > + BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); > + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); > + > + k->save_extra_state(qbus->parent, f); Maybe add an assert(k->save_extra_state) here, as this means the transport code is buggy? > +} > + > +static VMStateInfo vmstate_info_extra_state = { > + .name = "virtqueue_extra_state", > + .get = get_extra_state, > + .put = put_extra_state, > +}; > + > +static const VMStateDescription vmstate_virtio_modern_state = { Should probably be named "extra_state". > + .name = "virtio/extra_state", > + .version_id = 1, > + .minimum_version_id = 1, > + .needed = &virtio_extra_state_needed, > + .fields = (VMStateField[]) { > + { > + .name = "modern_state", Also here. > + .version_id = 0, > + .field_exists = NULL, > + .size = 0, > + .info = &vmstate_info_extra_state, > + .flags = VMS_SINGLE, > + .offset = 0, > + }, > + VMSTATE_END_OF_LIST() > + } > +}; > + > static const VMStateDescription vmstate_virtio_device_endian = { > .name = "virtio/device_endian", > .version_id = 1,