qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH RFC 04/11] virtio_ring: implement endian reversa


From: Cornelia Huck
Subject: Re: [Qemu-devel] [PATCH RFC 04/11] virtio_ring: implement endian reversal based on VERSION_1 feature.
Date: Wed, 22 Oct 2014 16:28:34 +0200

On Wed, 22 Oct 2014 17:02:26 +0300
"Michael S. Tsirkin" <address@hidden> wrote:

> On Tue, Oct 07, 2014 at 04:39:45PM +0200, Cornelia Huck wrote:
> > From: Rusty Russell <address@hidden>
> > 
> > [Cornelia Huck: we don't need the vq->vring.num -> vq->ring_mask change]
> > Signed-off-by: Rusty Russell <address@hidden>
> > Signed-off-by: Cornelia Huck <address@hidden>
> > ---
> >  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;
> >  }
> >  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]