From: Rusty Russell <rusty@rustcorp.com.au>
To: QEMU Developers <qemu-devel@nongnu.org>,
"Michael S. Tsirkin" <mst@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Subject: [Qemu-devel] [PATCH 1/2] virtio: make it clear that "len" for a used descriptor is len written.
Date: Wed, 11 Mar 2015 16:29:31 +1030 [thread overview]
Message-ID: <1426053572-21326-2-git-send-email-rusty@rustcorp.com.au> (raw)
In-Reply-To: <1426053572-21326-1-git-send-email-rusty@rustcorp.com.au>
And enforce this with a check that it's <= the writable length.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
hw/virtio/virtio.c | 19 ++++++++++++-------
include/hw/virtio/virtio.h | 4 ++--
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 882a31b..c944113 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -243,16 +243,21 @@ int virtio_queue_empty(VirtQueue *vq)
}
void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
- unsigned int len, unsigned int idx)
+ unsigned int len_written, unsigned int idx)
{
- unsigned int offset;
+ unsigned int offset, tot_wlen;
int i;
- trace_virtqueue_fill(vq, elem, len, idx);
+ trace_virtqueue_fill(vq, elem, len_written, idx);
+
+ for (tot_wlen = i = 0; i < elem->in_num; i++) {
+ tot_wlen += elem->in_sg[i].iov_len;
+ }
+ assert(len_written <= tot_wlen);
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(len_written - offset, elem->in_sg[i].iov_len);
cpu_physical_memory_unmap(elem->in_sg[i].iov_base,
elem->in_sg[i].iov_len,
@@ -270,7 +275,7 @@ 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, len_written);
}
void virtqueue_flush(VirtQueue *vq, unsigned int count)
@@ -288,9 +293,9 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count)
}
void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
- unsigned int len)
+ unsigned int len_written)
{
- virtqueue_fill(vq, elem, len, 0);
+ virtqueue_fill(vq, elem, len_written, 0);
virtqueue_flush(vq, 1);
}
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index df09993..153374f 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -191,10 +191,10 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
void virtio_del_queue(VirtIODevice *vdev, int n);
void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
- unsigned int len);
+ unsigned int len_written);
void virtqueue_flush(VirtQueue *vq, unsigned int count);
void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
- unsigned int len, unsigned int idx);
+ unsigned int len_written, unsigned int idx);
void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
size_t num_sg, int is_write);
--
2.1.0
next prev parent reply other threads:[~2015-03-11 6:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-11 5:59 [Qemu-devel] [PATCH 0/2] virtio len fixes for qemu Rusty Russell
2015-03-11 5:59 ` Rusty Russell [this message]
2015-03-11 5:59 ` [Qemu-devel] [PATCH 2/2] virtio-blk: fix length calculations for write operations Rusty Russell
2015-03-11 6:48 ` Michael S. Tsirkin
2015-03-11 11:34 ` Rusty Russell
2015-03-11 6:19 ` [Qemu-devel] [PATCH 0/2] virtio len fixes for qemu Michael S. Tsirkin
2015-03-11 6:47 ` Fam Zheng
2015-03-11 6:50 ` Michael S. Tsirkin
2015-03-11 11:36 ` Rusty Russell
2015-03-11 12:39 ` Michael S. Tsirkin
2015-03-12 1:04 ` Rusty Russell
2015-03-12 6:35 ` Michael S. Tsirkin
2015-03-13 1:17 ` Rusty Russell
2015-03-13 13:49 ` Michael S. Tsirkin
2015-03-16 3:14 ` Rusty Russell
2015-03-16 5:03 ` Michael S. Tsirkin
2015-03-16 15:37 ` Cornelia Huck
2015-03-20 0:59 ` Rusty Russell
2015-03-18 12:32 ` Michael S. Tsirkin
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=1426053572-21326-2-git-send-email-rusty@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.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).