From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51426 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7Y9Z-0000k6-Jm for qemu-devel@nongnu.org; Sun, 17 Oct 2010 14:40:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7Xzj-0006Yf-OM for qemu-devel@nongnu.org; Sun, 17 Oct 2010 14:30:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7Xzj-0006YZ-IF for qemu-devel@nongnu.org; Sun, 17 Oct 2010 14:30:07 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9HIU5GT031527 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 17 Oct 2010 14:30:06 -0400 Received: from redhat.com (vpn2-8-167.ams2.redhat.com [10.36.8.167]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o9HIU4Qj020477 for ; Sun, 17 Oct 2010 14:30:05 -0400 Date: Sun, 17 Oct 2010 20:23:49 +0200 From: "Michael S. Tsirkin" Message-ID: <20101017182348.GA12339@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] virtio: sanity-check available index List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Checking available index upon load instead of only when vm is running makes is easier to debug failures. Signed-off-by: Michael S. Tsirkin --- hw/virtio.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/hw/virtio.c b/hw/virtio.c index c8a0fc6..a2a657e 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -681,6 +681,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) uint32_t features; uint32_t supported_features = vdev->binding->get_features(vdev->binding_opaque); + uint16_t num_heads; if (vdev->binding->load_config) { ret = vdev->binding->load_config(vdev->binding_opaque, f); @@ -713,6 +714,16 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) if (vdev->vq[i].pa) { virtqueue_init(&vdev->vq[i]); } + num_heads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx; + /* Check it isn't doing very strange things with descriptor numbers. */ + if (num_heads > vdev->vq[i].vring.num) { + fprintf(stderr, "VQ %d size 0x%x Guest index 0x%x " + "inconsistent with Host index 0x%x: delta 0x%x\n", + i, vdev->vq[i].vring.num, + vring_avail_idx(&vdev->vq[i]), + vdev->vq[i].last_avail_idx, num_heads); + return -1; + } if (vdev->binding->load_queue) { ret = vdev->binding->load_queue(vdev->binding_opaque, i, f); if (ret) -- 1.7.3-rc1