From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: qemu-devel@nongnu.org
Cc: xen-devel@lists.xensource.com, mst@redhat.com,
jasowang@redhat.com,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH 1/4] introduce virtqueue_unmap_sg
Date: Tue, 25 Nov 2014 14:43:20 +0000 [thread overview]
Message-ID: <1416926603-12397-1-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1411251436080.2675@kaball.uk.xensource.com>
Introduce a function to unmap an sg previously mapped with
virtqueue_map_sg.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
CC: jasowang@redhat.com
CC: wency@cn.fujitsu.com
CC: mst@redhat.com
CC: pbonzini@redhat.com
---
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;
+ }
+}
+
int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
{
unsigned int i, head, max;
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 3e54e90..2325053 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -173,6 +173,8 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
size_t num_sg, int is_write);
+void virtqueue_unmap_sg(const struct iovec *sg, size_t num_sg,
+ int is_write, unsigned int len);
int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
unsigned int out_bytes);
--
1.7.10.4
next prev parent reply other threads:[~2014-11-25 14:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 14:42 [Qemu-devel] [PATCH 0/4] virtio-net: do not leak cpu mappings Stefano Stabellini
2014-11-25 14:43 ` Stefano Stabellini [this message]
2014-11-25 15:05 ` [Qemu-devel] [PATCH 1/4] introduce virtqueue_unmap_sg Peter Maydell
2014-11-25 15:28 ` Stefano Stabellini
2014-11-25 14:43 ` [Qemu-devel] [PATCH 2/4] use virtqueue_unmap_sg in virtqueue_fill Stefano Stabellini
2014-11-25 14:43 ` [Qemu-devel] [PATCH 3/4] move virtqueue_unmap_sg calls from virtqueue_fill to virtqueue_push Stefano Stabellini
2014-11-25 14:43 ` [Qemu-devel] [PATCH 4/4] virtio-net: do not leak cpu mappings Stefano Stabellini
2014-11-25 15:28 ` [Qemu-devel] [Xen-devel] [PATCH 0/4] " Fabio Fantoni
2014-11-25 17:09 ` Wei Liu
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=1416926603-12397-1-git-send-email-stefano.stabellini@eu.citrix.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=xen-devel@lists.xensource.com \
/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).