Received: from eggs.gnu.org ([2001:4830:134:3::10]:55899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhuWR-0007YA-FE for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:17:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhuWN-0008J7-Hz for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:17:23 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46933 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhuWN-0008I4-CE for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:17:19 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u888DISY069715 for ; Thu, 8 Sep 2016 04:17:18 -0400 Received: from e06smtp09.uk.ibm.com (e06smtp09.uk.ibm.com [195.75.94.105]) by mx0b-001b2d01.pphosted.com with ESMTP id 25ataxvvvk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 08 Sep 2016 04:17:18 -0400 Received: from localhost by e06smtp09.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Sep 2016 09:17:16 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id AE7FF2190063 for ; Thu, 8 Sep 2016 09:16:35 +0100 (BST) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u888HDhg26017856 for ; Thu, 8 Sep 2016 08:17:13 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u888HDrk027897 for ; Thu, 8 Sep 2016 02:17:13 -0600 Date: Thu, 8 Sep 2016 10:17:12 +0200 From: Cornelia Huck In-Reply-To: <1473263485-17084-1-git-send-email-stefanha@redhat.com> References: <1473263485-17084-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: <20160908101712.285389f7.cornelia.huck@de.ibm.com> Subject: Re: [Qemu-devel] [PATCH] virtio: zero vq->inuse in virtio_reset() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, lprosek@redhat.com, "Michael S. Tsirkin" On Wed, 7 Sep 2016 11:51:25 -0400 Stefan Hajnoczi wrote: > 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 > --- > hw/virtio/virtio.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 74c085c..e8a13a5 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -822,6 +822,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; > } > } > This looks sane as a minimal change, and survives my smoketests. Reviewed-by: Cornelia Huck