From patchwork Wed Dec 12 10:51:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 205478 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CB87A2C00A3 for ; Wed, 12 Dec 2012 21:48:17 +1100 (EST) Received: from localhost ([::1]:41160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TijrL-000463-SS for incoming@patchwork.ozlabs.org; Wed, 12 Dec 2012 05:48:15 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tijr7-00045h-NB for qemu-devel@nongnu.org; Wed, 12 Dec 2012 05:48:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tijqz-0007Hf-NO for qemu-devel@nongnu.org; Wed, 12 Dec 2012 05:48:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tijqz-0007HK-8A for qemu-devel@nongnu.org; Wed, 12 Dec 2012 05:47:53 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBCAlpYC012789 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 12 Dec 2012 05:47:52 -0500 Received: from redhat.com (vpn1-6-172.ams2.redhat.com [10.36.6.172]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id qBCAlmrX029050; Wed, 12 Dec 2012 05:47:48 -0500 Date: Wed, 12 Dec 2012 12:51:01 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, Rusty Russell Message-ID: <20121212105101.GA6461@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Anthony Liguori , Avi Kivity , Stefan Hajnoczi , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCHv2] virtio: verify that all outstanding buffers are flushed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add sanity check to address the following concern: During migration, all we pass the index of the request; the rest can be re-read from the ring. This is not generally enough if any available requests are outstanding. Imagine a ring of size 4. Below A means available U means used. A 1 A 2 U 2 A 2 U 2 A 2 U 2 A 2 U 2 At this point available ring has wrapped around, the only way to know head 1 is outstanding is because backend has stored this info somewhere. The reason we manage to migrate without tracking this in migration state is because we flush outstanding requests before migration. This flush is device-specific though, let's add a safeguard in virtio core to ensure it's done properly. Signed-off-by: Michael S. Tsirkin --- Changes from v1: v1 was against the wrong tree, it didn't build against qemu.git hw/virtio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/virtio.c b/hw/virtio.c index f40a8c5..6227642 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -788,6 +788,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) if (vdev->vq[i].vring.num == 0) break; + assert(!vdev->vq[i].inuse); + qemu_put_be32(f, vdev->vq[i].vring.num); qemu_put_be64(f, vdev->vq[i].pa); qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);