From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ymjxf-0003MX-EV for qemu-devel@nongnu.org; Mon, 27 Apr 2015 10:24:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ymjxc-00074h-29 for qemu-devel@nongnu.org; Mon, 27 Apr 2015 10:24:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ymjxb-00074Z-Q2 for qemu-devel@nongnu.org; Mon, 27 Apr 2015 10:24:35 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3REOZBg030983 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 27 Apr 2015 10:24:35 -0400 Message-ID: <553E469F.1000605@redhat.com> Date: Mon, 27 Apr 2015 16:24:31 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1430144304-13514-1-git-send-email-mst@redhat.com> In-Reply-To: <1430144304-13514-1-git-send-email-mst@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH RFC] virtio: add virtqueue_fill_partial List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , qemu-devel@nongnu.org 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); > +} > +