[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC] virtio: add virtqueue_fill_partial
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH RFC] virtio: add virtqueue_fill_partial |
Date: |
Mon, 27 Apr 2015 16:24:31 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
On 27/04/2015 16:18, Michael S. Tsirkin wrote:
> +/*
> + * Some devices dirty guest memory but don't want to tell guest about it. In
> + * that case, use virtqueue_fill_partial: host_len is >= the amount of guest
> + * memory actually written, guest_len is how much we guarantee to guest.
> + * If you know exactly how much was written, use virtqueue_fill instead.
"If you never leave holes unwritten in the iov, use virtqueue_fill
instead. If the guest is not relying on iov boundaries, it should never
be necessary to use this function."
The API looks okay though.
Paolo
> + */
> +void virtqueue_fill_partial(VirtQueue *vq, const VirtQueueElement *elem,
> + unsigned int host_len, unsigned int guest_len,
> + unsigned int idx)
> {
> unsigned int offset;
> int i;
>
> - trace_virtqueue_fill(vq, elem, len, idx);
> + assert(host_len >= guest_len);
> +
> + trace_virtqueue_fill(vq, elem, guest_len, idx);
>
> offset = 0;
> for (i = 0; i < elem->in_num; i++) {
> - size_t size = MIN(len - offset, elem->in_sg[i].iov_len);
> + size_t size = MIN(host_len - offset, elem->in_sg[i].iov_len);
>
> cpu_physical_memory_unmap(elem->in_sg[i].iov_base,
> elem->in_sg[i].iov_len,
> @@ -269,7 +278,13 @@ void virtqueue_fill(VirtQueue *vq, const
> VirtQueueElement *elem,
>
> /* Get a pointer to the next entry in the used ring. */
> vring_used_ring_id(vq, idx, elem->index);
> - vring_used_ring_len(vq, idx, len);
> + vring_used_ring_len(vq, idx, guest_len);
> +}
> +