Received: from eggs.gnu.org ([2001:4830:134:3::10]:43139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmOUm-0007MD-CF for qemu-devel@nongnu.org; Tue, 20 Sep 2016 13:06:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmOUi-0007Ma-4x for qemu-devel@nongnu.org; Tue, 20 Sep 2016 13:06:11 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54183 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmOUh-0007MK-Vu for qemu-devel@nongnu.org; Tue, 20 Sep 2016 13:06:08 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8KH3YZr126685 for ; Tue, 20 Sep 2016 13:06:07 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 25jtw2s5xs-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 20 Sep 2016 13:06:07 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Sep 2016 13:06:07 -0400 From: Michael Roth Date: Tue, 20 Sep 2016 12:05:27 -0500 In-Reply-To: <1474391141-16623-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1474391141-16623-1-git-send-email-mdroth@linux.vnet.ibm.com> Message-Id: <1474391141-16623-12-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 11/25] virtio: zero vq->inuse in virtio_reset() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Stefan Hajnoczi , "Michael S. Tsirkin" From: Stefan Hajnoczi vq->inuse must be zeroed upon device reset like most other virtqueue fields. In theory, virtio_reset() just needs assert(vq->inuse == 0) since devices must clean up in-flight requests during reset (requests cannot not be leaked!). In practice, it is difficult to achieve vq->inuse == 0 across reset because balloon, blk, 9p, etc implement various different strategies for cleaning up requests. Most devices call g_free(elem) directly without telling virtio.c that the VirtQueueElement is cleaned up. Therefore vq->inuse is not decremented during reset. This patch zeroes vq->inuse and trusts that devices are not leaking VirtQueueElements across reset. I will send a follow-up series that refactors request life-cycle across all devices and converts vq->inuse = 0 into assert(vq->inuse == 0) but this more invasive approach is not appropriate for stable trees. Signed-off-by: Stefan Hajnoczi Cc: qemu-stable Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Ladi Prosek (cherry picked from commit 4b7f91ed0270a371e1933efa21ba600b6da23ab9) Signed-off-by: Michael Roth --- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5fbaaaa..519bb03 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -816,6 +816,7 @@ void virtio_reset(void *opaque) vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; + vdev->vq[i].inuse = 0; } } -- 1.9.1