Received: from eggs.gnu.org ([2001:4830:134:3::10]:50012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXQXB-0001lk-GA for qemu-devel@nongnu.org; Thu, 03 Sep 2015 05:10:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXQX8-0004Sp-3v for qemu-devel@nongnu.org; Thu, 03 Sep 2015 05:10:17 -0400 Received: from e06smtp07.uk.ibm.com ([195.75.94.103]:54902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXQX7-0004Rw-Rd for qemu-devel@nongnu.org; Thu, 03 Sep 2015 05:10:14 -0400 Received: from /spool/local by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 3 Sep 2015 10:10:11 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id AC6E017D8059 for ; Thu, 3 Sep 2015 10:11:51 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t839A8CX32506090 for ; Thu, 3 Sep 2015 09:10:08 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t838A8OV018743 for ; Thu, 3 Sep 2015 02:10:09 -0600 Date: Thu, 3 Sep 2015 11:10:06 +0200 From: Cornelia Huck Message-ID: <20150903111006.24257f19.cornelia.huck@de.ibm.com> In-Reply-To: <20150903102344.3c903794@bahia.local> References: <1441207429-23221-1-git-send-email-pmorel@linux.vnet.ibm.com> <20150902175055.78b06a5b.cornelia.huck@de.ibm.com> <20150902195725.0363617c@bahia.local> <20150903102344.3c903794@bahia.local> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] virtio: right size for virtio_queue_get_avail_size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Greg Kurz Cc: Pierre Morel , qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com On Thu, 3 Sep 2015 10:23:44 +0200 Greg Kurz wrote: > On Wed, 2 Sep 2015 19:57:25 +0200 > Greg Kurz wrote: > > > On Wed, 2 Sep 2015 17:50:55 +0200 > > Cornelia Huck wrote: > > > > > On Wed, 2 Sep 2015 17:23:49 +0200 > > > Pierre Morel wrote: > > > > > > > Being working on dataplane I notice something strange: > > > > > > > > virtio_queue_get_avail_size() used a 64bit size index > > > > for the calculation of the available ring size. > > > > > > > > It is quite strange but it did work with the old calculation > > > > of the avail ring, at most with performance penalty, > > > > and I wonder where I missed something. > > > > > > > > This patch let use a 16bit size as defined in virtio_ring.h > > > > > > > > Signed-off-by: Pierre Morel > > > > --- > > > > hw/virtio/virtio.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > > > > index 788b556..5c856eb 100644 > > > > --- a/hw/virtio/virtio.c > > > > +++ b/hw/virtio/virtio.c > > > > @@ -1460,7 +1460,7 @@ hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, int n) > > > > hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n) > > > > { > > > > return offsetof(VRingAvail, ring) + > > > > - sizeof(uint64_t) * vdev->vq[n].vring.num; > > > > + sizeof(uint16_t) * vdev->vq[n].vring.num; > > > > } > > > > > > > > hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n) > > > > > > I'm wondering about the semantics of the _size() functions. Naively I > > > would expect (size of buffer) * (number of buffers). I think at least > > > > Looking at where these functions are called, it really looks like they are > > expected to return the size of the memory region to be mapped. Since we have: > > > > Acutally no... they are also used to compute the address of used_event_idx > and avail_event_idx. > > > typedef struct VRingAvail > > { > > uint16_t flags; > > uint16_t idx; > > uint16_t ring[0]; > > } VRingAvail; > > > > Pierre's patch looks valid. But while we're here, why not introducing > > something like: > > > > #define member_size(type, member) sizeof(((type *)0)->member) > > > > It would consolidate the _size functions and the types they are referring to: > > > > - sizeof(uint64_t) * vdev->vq[n].vring.num; > > + member_size(VRingAvail, vring[0]) * vdev->vq[n].vring.num; > > > > > vhost expects the {used,avail} indices in there as well? The > > > s390-virtio code seems not to expect the indices to be contained in the > > > size, though... > > > > > > Sorry I missed the real question... should these _size functions return > the actual size + sizeof(uint16_t) ? > > Indeed, I could verify the the s390-virtio code uses the _size functions > to compute the address of used_event_idx and avail_event_idx... > The vhost code only uses the _size functions to map memory... and > doesn't add sizeof(uint16_t)... which looks like a bug. Yes, this probably worked by chance because (a) the avail size is too big anyway and (b) the used size added the offset value... and probably nobody cares much about s390-virtio reset, but that might explain some headscratchers we were seeing very occasionally.