qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 7/8] virtio: use VRingMemoryRegionCaches for descriptor ring
Date: Tue, 24 Jan 2017 19:04:19 +0100	[thread overview]
Message-ID: <20170124180420.12430-8-pbonzini@redhat.com> (raw)
In-Reply-To: <20170124180420.12430-1-pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/virtio/virtio.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 548a3c7..b664b6e 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -487,25 +487,24 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
     VirtIODevice *vdev = vq->vdev;
     unsigned int max, idx;
     unsigned int total_bufs, in_total, out_total;
-    MemoryRegionCache vring_desc_cache;
+    VRingMemoryRegionCaches *caches;
     MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
     int64_t len = 0;
     int rc;
 
+    rcu_read_lock();
     idx = vq->last_avail_idx;
     total_bufs = in_total = out_total = 0;
 
     max = vq->vring.num;
-    len = address_space_cache_init(&vring_desc_cache, vdev->dma_as,
-                                   vq->vring.desc, max * sizeof(VRingDesc),
-                                   false);
-    if (len < max * sizeof(VRingDesc)) {
+    caches = atomic_rcu_read(&vq->vring.caches);
+    if (caches->desc.len < max * sizeof(VRingDesc)) {
         virtio_error(vdev, "Cannot map descriptor ring");
         goto err;
     }
 
     while ((rc = virtqueue_num_heads(vq, idx)) > 0) {
-        MemoryRegionCache *desc_cache = &vring_desc_cache;
+        MemoryRegionCache *desc_cache = &caches->desc;
         unsigned int num_bufs;
         VRingDesc desc;
         unsigned int i;
@@ -582,13 +581,13 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
 
 done:
     address_space_cache_destroy(&indirect_desc_cache);
-    address_space_cache_destroy(&vring_desc_cache);
     if (in_bytes) {
         *in_bytes = in_total;
     }
     if (out_bytes) {
         *out_bytes = out_total;
     }
+    rcu_read_unlock();
     return;
 
 err:
@@ -722,7 +721,7 @@ static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_nu
 void *virtqueue_pop(VirtQueue *vq, size_t sz)
 {
     unsigned int i, head, max;
-    MemoryRegionCache vring_desc_cache;
+    VRingMemoryRegionCaches *caches;
     MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
     MemoryRegionCache *desc_cache;
     int64_t len;
@@ -764,15 +763,14 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
 
     i = head;
 
-    len = address_space_cache_init(&vring_desc_cache, vdev->dma_as,
-                                   vq->vring.desc, max * sizeof(VRingDesc),
-                                   false);
-    if (len < max * sizeof(VRingDesc)) {
+    rcu_read_lock();
+    caches = atomic_rcu_read(&vq->vring.caches);
+    if (caches->desc.len < max * sizeof(VRingDesc)) {
         virtio_error(vdev, "Cannot map descriptor ring");
-        return NULL;
+        goto done;
     }
 
-    desc_cache = &vring_desc_cache;
+    desc_cache = &caches->desc;
     vring_desc_read(vdev, &desc, desc_cache, i);
     if (desc.flags & VRING_DESC_F_INDIRECT) {
         if (desc.len % sizeof(VRingDesc)) {
@@ -846,7 +844,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
     trace_virtqueue_pop(vq, elem, elem->in_num, elem->out_num);
 done:
     address_space_cache_destroy(&indirect_desc_cache);
-    address_space_cache_destroy(&vring_desc_cache);
+    rcu_read_unlock();
 
     return elem;
 
-- 
2.9.3

  parent reply	other threads:[~2017-01-24 18:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24 18:04 [Qemu-devel] [PATCH v2 0/8] virtio: use MemoryRegionCache for descriptors and rings Paolo Bonzini
2017-01-24 18:04 ` [Qemu-devel] [PATCH 1/8] virtio: make virtio_should_notify static Paolo Bonzini
2017-01-24 18:04 ` [Qemu-devel] [PATCH 2/8] virtio: add virtio_*_phys_cached Paolo Bonzini
2017-01-24 18:04 ` [Qemu-devel] [PATCH 3/8] virtio: use address_space_map/unmap to access descriptors Paolo Bonzini
2017-01-25 13:22   ` Stefan Hajnoczi
2017-01-25 14:04     ` Paolo Bonzini
2017-01-26 17:25       ` Stefan Hajnoczi
2017-01-24 18:04 ` [Qemu-devel] [PATCH 4/8] exec: make address_space_cache_destroy idempotent Paolo Bonzini
2017-01-25 13:23   ` Stefan Hajnoczi
2017-01-24 18:04 ` [Qemu-devel] [PATCH 5/8] virtio: use MemoryRegionCache to access descriptors Paolo Bonzini
2017-01-25 13:24   ` Stefan Hajnoczi
2017-01-24 18:04 ` [Qemu-devel] [PATCH 6/8] virtio: add MemoryListener to cache ring translations Paolo Bonzini
2017-01-25 13:25   ` Stefan Hajnoczi
2017-01-24 18:04 ` Paolo Bonzini [this message]
2017-01-25 13:26   ` [Qemu-devel] [PATCH 7/8] virtio: use VRingMemoryRegionCaches for descriptor ring Stefan Hajnoczi
2017-01-24 18:04 ` [Qemu-devel] [PATCH 8/8] virtio: use VRingMemoryRegionCaches for avail and used rings Paolo Bonzini
2017-01-25 13:27   ` Stefan Hajnoczi
2017-01-24 18:26 ` [Qemu-devel] [PATCH v2 0/8] virtio: use MemoryRegionCache for descriptors and rings no-reply
2017-01-24 19:46   ` 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=20170124180420.12430-8-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).