Received: from eggs.gnu.org ([2001:4830:134:3::10]:43166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bYtRo-0007vF-9k for qemu-devel@nongnu.org; Sun, 14 Aug 2016 07:19:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bYtRk-0006dd-2y for qemu-devel@nongnu.org; Sun, 14 Aug 2016 07:19:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bYtRj-0006dL-TB for qemu-devel@nongnu.org; Sun, 14 Aug 2016 07:19:15 -0400 Date: Sun, 14 Aug 2016 19:12:10 +0800 From: Fam Zheng Message-ID: <20160814111210.GA4160@al.usersys.redhat.com> References: <1471015978-1123-1-git-send-email-stefanha@redhat.com> <1471015978-1123-2-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1471015978-1123-2-git-send-email-stefanha@redhat.com> Subject: Re: [Qemu-devel] [PATCH for-2.7 1/4] virtio: recalculate vq->inuse after migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, gaudenz@debian.org, "Michael S. Tsirkin" , Luiz Capitulino On Fri, 08/12 16:32, Stefan Hajnoczi wrote: > The vq->inuse field is not migrated. Many devices don't hold > VirtQueueElements across migration so it doesn't matter that vq->inuse > starts at 0 on the destination QEMU. > > At least virtio-serial, virtio-blk, and virtio-balloon migrate while > holding VirtQueueElements. For these devices we need to recalculate > vq->inuse upon load so the value is correct. > > Signed-off-by: Stefan Hajnoczi > --- > hw/virtio/virtio.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 15ee3a7..4df8274 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -1648,6 +1648,20 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) > } > vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]); > vdev->vq[i].shadow_avail_idx = vring_avail_idx(&vdev->vq[i]); > + > + /* Some devices migrate VirtQueueElements that have been popped > + * from the avail ring but not yet returned to the used ring. > + */ > + vdev->vq[i].inuse = vdev->vq[i].last_avail_idx - > + vdev->vq[i].used_idx; > + if (vdev->vq[i].inuse > vdev->vq[i].vring.num) { > + error_report("VQ %d size 0x%x < last_avail_idx 0x%x - " > + "used_idx 0x%x" .-----------^ I believe a comma is missing here / Fam > + i, vdev->vq[i].vring.num, > + vdev->vq[i].last_avail_idx, > + vdev->vq[i].used_idx); > + return -1; > + } > } > } > > -- > 2.7.4 > >