qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: thuth@linux.vnet.ibm.com, qemu-devel@nongnu.org,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org
Subject: Re: [Qemu-devel] [PATCH RFC 04/11] virtio_ring: implement endian reversal based on VERSION_1 feature.
Date: Wed, 22 Oct 2014 17:37:11 +0300	[thread overview]
Message-ID: <20141022143711.GB14260@redhat.com> (raw)
In-Reply-To: <20141022162834.17f39f0d.cornelia.huck@de.ibm.com>

On Wed, Oct 22, 2014 at 04:28:34PM +0200, Cornelia Huck wrote:
> On Wed, 22 Oct 2014 17:02:26 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Tue, Oct 07, 2014 at 04:39:45PM +0200, Cornelia Huck wrote:
> > > From: Rusty Russell <rusty@rustcorp.com.au>
> > > 
> > > [Cornelia Huck: we don't need the vq->vring.num -> vq->ring_mask change]
> > > Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> > > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > > ---
> > >  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.

I think I'll do it more gradually: mechanically add accessors
everywhere as a 1st step. Split long lines and other cleanup
as a second step.

> > 
> > > +	/* 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;
> > >  }
> > >  

  reply	other threads:[~2014-10-22 14:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 14:39 [Qemu-devel] [PATCH RFC 00/11] linux: towards virtio-1 guest support Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 01/11] virtio: use u32, not bitmap for struct virtio_device's features Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 02/11] virtio: add support for 64 bit features Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 03/11] virtio: endianess conversion helpers Cornelia Huck
2014-10-22  9:04   ` Michael S. Tsirkin
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 04/11] virtio_ring: implement endian reversal based on VERSION_1 feature Cornelia Huck
2014-10-22 14:02   ` Michael S. Tsirkin
2014-10-22 14:28     ` Cornelia Huck
2014-10-22 14:37       ` Michael S. Tsirkin [this message]
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 05/11] virtio_config: endian conversion for v1.0 Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 06/11] virtio: allow transports to get avail/used addresses Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 07/11] virtio_net: use v1.0 endian Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 08/11] virtio_blk: use virtio " Cornelia Huck
2014-10-13  5:58   ` Rusty Russell
2014-10-13 10:42     ` Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 09/11] KVM: s390: Set virtio-ccw transport revision Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 10/11] KVM: s390: virtio-ccw revision 1 SET_VQ Cornelia Huck
2014-10-07 14:39 ` [Qemu-devel] [PATCH RFC 11/11] KVM: s390: enable virtio-ccw revision 1 Cornelia Huck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141022143711.GB14260@redhat.com \
    --to=mst@redhat.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@linux.vnet.ibm.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).