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

Re: [Xen-devel] [Qemu-devel] [PATCH 1/4] introduce virtqueue_unmap_sg



On Tue, 25 Nov 2014, Peter Maydell wrote:
> On 25 November 2014 at 14:43, Stefano Stabellini
> <stefano.stabellini@xxxxxxxxxxxxx> wrote:
> > Introduce a function to unmap an sg previously mapped with
> > virtqueue_map_sg.
> >
> > Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
> > CC: jasowang@xxxxxxxxxx
> > CC: wency@xxxxxxxxxxxxxx
> > CC: mst@xxxxxxxxxx
> > CC: pbonzini@xxxxxxxxxx
> > ---
> >  hw/virtio/virtio.c         |   22 ++++++++++++++++++++++
> >  include/hw/virtio/virtio.h |    2 ++
> >  2 files changed, 24 insertions(+)
> >
> > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> > index 3e4b70c..2621ae6 100644
> > --- a/hw/virtio/virtio.c
> > +++ b/hw/virtio/virtio.c
> > @@ -446,6 +446,28 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
> >      }
> >  }
> >
> > +void virtqueue_unmap_sg(const struct iovec *sg, size_t num_sg,
> > +                        int is_write, unsigned int len)
> > +{
> > +    unsigned int i;
> > +    unsigned int offset;
> > +
> > +    if (num_sg > VIRTQUEUE_MAX_SIZE) {
> > +        error_report("virtio: unmap attempt out of bounds: %zd > %d",
> > +                     num_sg, VIRTQUEUE_MAX_SIZE);
> > +        exit(1);
> > +    }
> > +
> > +    offset = 0;
> > +    for (i = 0; i < num_sg; i++) {
> > +        size_t size = MIN(len - offset, sg[i].iov_len);
> > +
> > +        cpu_physical_memory_unmap(sg[i].iov_base, sg[i].iov_len, is_write, 
> > size);
> > +
> > +        offset += size;
> > +    }
> > +}
> 
> It seems rather odd that "size" and the iov_len fields in
> the iovec are size_t but 'len' and 'offset' are only
> unsigned int...

The code is taken from virtqueue_fill but that's a good point.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.