From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgwuB-0001H2-55 for qemu-devel@nongnu.org; Wed, 22 Oct 2014 10:28:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xgwu3-0005Xy-4q for qemu-devel@nongnu.org; Wed, 22 Oct 2014 10:28:51 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:47622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgwu2-0005XY-Sx for qemu-devel@nongnu.org; Wed, 22 Oct 2014 10:28:43 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Oct 2014 15:28:39 +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 5EF112190045 for ; Wed, 22 Oct 2014 15:28:13 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id s9MESbRY8061330 for ; Wed, 22 Oct 2014 14:28:37 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 s9MESaSv003996 for ; Wed, 22 Oct 2014 08:28:37 -0600 Date: Wed, 22 Oct 2014 16:28:34 +0200 From: Cornelia Huck Message-ID: <20141022162834.17f39f0d.cornelia.huck@de.ibm.com> In-Reply-To: <20141022140226.GA12171@redhat.com> References: <1412692792-12325-1-git-send-email-cornelia.huck@de.ibm.com> <1412692792-12325-5-git-send-email-cornelia.huck@de.ibm.com> <20141022140226.GA12171@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH RFC 04/11] virtio_ring: implement endian reversal based on VERSION_1 feature. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: thuth@linux.vnet.ibm.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org On Wed, 22 Oct 2014 17:02:26 +0300 "Michael S. Tsirkin" wrote: > On Tue, Oct 07, 2014 at 04:39:45PM +0200, Cornelia Huck wrote: > > From: Rusty Russell > > > > [Cornelia Huck: we don't need the vq->vring.num -> vq->ring_mask change] > > Signed-off-by: Rusty Russell > > Signed-off-by: Cornelia Huck > > --- > > drivers/virtio/virtio_ring.c | 195 ++++++++++++++++++++++++++++++------------ > > 1 file changed, 138 insertions(+), 57 deletions(-) > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > index 1cfb5ba..350c39b 100644 > > --- a/drivers/virtio/virtio_ring.c > > +++ b/drivers/virtio/virtio_ring.c > > @@ -145,42 +145,54 @@ static inline int vring_add_indirect(struct vring_virtqueue *vq, > > i = 0; > > for (n = 0; n < out_sgs; n++) { > > for (sg = sgs[n]; sg; sg = next(sg, &total_out)) { > > - desc[i].flags = VRING_DESC_F_NEXT; > > - desc[i].addr = sg_phys(sg); > > - desc[i].len = sg->length; > > - desc[i].next = i+1; > > + desc[i].flags = cpu_to_virtio16(vq->vq.vdev, > > + VRING_DESC_F_NEXT); > > + desc[i].addr = cpu_to_virtio64(vq->vq.vdev, > > + sg_phys(sg)); > > + desc[i].len = cpu_to_virtio32(vq->vq.vdev, > > + sg->length); > > + desc[i].next = cpu_to_virtio16(vq->vq.vdev, > > + i+1); > > i++; > > } > > } > > for (; n < (out_sgs + in_sgs); n++) { > > for (sg = sgs[n]; sg; sg = next(sg, &total_in)) { > > - desc[i].flags = VRING_DESC_F_NEXT|VRING_DESC_F_WRITE; > > - desc[i].addr = sg_phys(sg); > > - desc[i].len = sg->length; > > - desc[i].next = i+1; > > + desc[i].flags = cpu_to_virtio16(vq->vq.vdev, > > + VRING_DESC_F_NEXT| > > + VRING_DESC_F_WRITE); > > + desc[i].addr = cpu_to_virtio64(vq->vq.vdev, > > + sg_phys(sg)); > > + desc[i].len = cpu_to_virtio32(vq->vq.vdev, > > + sg->length); > > + desc[i].next = cpu_to_virtio16(vq->vq.vdev, i+1); > > i++; > > } > > } > > - BUG_ON(i != total_sg); > > > > /* Last one doesn't continue. */ > > - desc[i-1].flags &= ~VRING_DESC_F_NEXT; > > + desc[i-1].flags &= ~cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT); > > desc[i-1].next = 0; > > > > - /* We're about to use a buffer */ > > - vq->vq.num_free--; > > - > > /* Use a single buffer which doesn't continue */ > > head = vq->free_head; > > - vq->vring.desc[head].flags = VRING_DESC_F_INDIRECT; > > - vq->vring.desc[head].addr = virt_to_phys(desc); > > + vq->vring.desc[head].flags = > > + cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_INDIRECT); > > + vq->vring.desc[head].addr = > > + cpu_to_virtio64(vq->vq.vdev, virt_to_phys(desc)); > > /* kmemleak gives a false positive, as it's hidden by virt_to_phys */ > > kmemleak_ignore(desc); > > - vq->vring.desc[head].len = i * sizeof(struct vring_desc); > > + vq->vring.desc[head].len = > > + cpu_to_virtio32(vq->vq.vdev, i * sizeof(struct vring_desc)); > > > > - /* Update free pointer */ > > + BUG_ON(i != total_sg); > > + > > Why move the BUG_ON here? > I think I'll move it back ... IIRC this was in the original patch I applied - but you're right, the statement can stay in the old place. > > > + /* Update free pointer (we store this in native endian) */ > > vq->free_head = vq->vring.desc[head].next; > > > > + /* We've just used a buffer */ > > + vq->vq.num_free--; > > + > > return head; > > } > >