From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 10/23] virtio: use VRingMemoryRegionCaches for descriptor ring
Date: Fri, 17 Feb 2017 21:54:30 +0200 [thread overview]
Message-ID: <1487361200-29966-11-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1487361200-29966-1-git-send-email-mst@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index b75cb52..d62509d 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -491,25 +491,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;
@@ -586,13 +585,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:
@@ -726,7 +725,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;
@@ -768,15 +767,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");
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)) {
@@ -850,7 +848,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;
--
MST
next prev parent reply other threads:[~2017-02-17 19:54 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-17 19:53 [Qemu-devel] [PULL 00/23] virtio, pci: fixes, features Michael S. Tsirkin
2017-02-17 19:53 ` [Qemu-devel] [PULL 01/23] pci/pcie: don't assume cap id 0 is reserved Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 02/23] virtio: Report real progress in VQ aio poll handler Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 03/23] docs: add document to explain the usage of vNVDIMM Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 04/23] memory: make memory_listener_unregister idempotent Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 05/23] virtio: add virtio_*_phys_cached Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 06/23] virtio: use address_space_map/unmap to access descriptors Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 07/23] exec: make address_space_cache_destroy idempotent Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 08/23] virtio: use MemoryRegionCache to access descriptors Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 09/23] virtio: add MemoryListener to cache ring translations Michael S. Tsirkin
2017-02-17 19:54 ` Michael S. Tsirkin [this message]
2017-02-17 19:54 ` [Qemu-devel] [PULL 11/23] virtio: check for vring setup in virtio_queue_update_used_idx Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 12/23] virtio: use VRingMemoryRegionCaches for avail and used rings Michael S. Tsirkin
2017-02-21 12:57 ` Gerd Hoffmann
2017-02-21 16:25 ` Laszlo Ersek
2017-02-21 17:54 ` Laszlo Ersek
2017-02-22 9:03 ` Paolo Bonzini
2017-02-23 0:32 ` Alex Williamson
2017-02-23 9:33 ` Cédric Le Goater
2017-02-23 9:47 ` Paolo Bonzini
2017-02-23 11:56 ` Cédric Le Goater
2017-02-21 18:08 ` Paolo Bonzini
2017-02-21 19:07 ` Laszlo Ersek
2017-02-21 20:04 ` Gerd Hoffmann
2017-02-17 19:54 ` [Qemu-devel] [PULL 13/23] virtio: Fix no interrupt when not creating msi controller Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 14/23] pcie: simplify pcie_add_capability() Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 15/23] vfio: trace map/unmap for notify as well Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 16/23] vfio: introduce vfio_get_vaddr() Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 17/23] vfio: allow to notify unmap for very large region Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 18/23] intel_iommu: add "caching-mode" option Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 19/23] intel_iommu: simplify irq region translation Michael S. Tsirkin
2017-02-17 19:54 ` [Qemu-devel] [PULL 20/23] intel_iommu: renaming gpa to iova where proper Michael S. Tsirkin
2017-02-17 19:55 ` [Qemu-devel] [PULL 21/23] intel_iommu: convert dbg macros to traces for inv Michael S. Tsirkin
2017-02-17 19:55 ` [Qemu-devel] [PULL 22/23] intel_iommu: convert dbg macros to trace for trans Michael S. Tsirkin
2017-02-17 19:55 ` [Qemu-devel] [PULL 23/23] intel_iommu: vtd_slpt_level_shift check level Michael S. Tsirkin
2017-02-20 11:55 ` [Qemu-devel] [PULL 00/23] virtio, pci: fixes, features Peter Maydell
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=1487361200-29966-11-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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).