mirror of https://github.com/xemu-project/xemu.git
virtio: use VRingMemoryRegionCaches for descriptor ring
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>
This commit is contained in:
parent
c611c76417
commit
991976f751
|
@ -491,25 +491,24 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
|
||||||
VirtIODevice *vdev = vq->vdev;
|
VirtIODevice *vdev = vq->vdev;
|
||||||
unsigned int max, idx;
|
unsigned int max, idx;
|
||||||
unsigned int total_bufs, in_total, out_total;
|
unsigned int total_bufs, in_total, out_total;
|
||||||
MemoryRegionCache vring_desc_cache;
|
VRingMemoryRegionCaches *caches;
|
||||||
MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
|
MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
|
||||||
int64_t len = 0;
|
int64_t len = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
rcu_read_lock();
|
||||||
idx = vq->last_avail_idx;
|
idx = vq->last_avail_idx;
|
||||||
total_bufs = in_total = out_total = 0;
|
total_bufs = in_total = out_total = 0;
|
||||||
|
|
||||||
max = vq->vring.num;
|
max = vq->vring.num;
|
||||||
len = address_space_cache_init(&vring_desc_cache, vdev->dma_as,
|
caches = atomic_rcu_read(&vq->vring.caches);
|
||||||
vq->vring.desc, max * sizeof(VRingDesc),
|
if (caches->desc.len < max * sizeof(VRingDesc)) {
|
||||||
false);
|
|
||||||
if (len < max * sizeof(VRingDesc)) {
|
|
||||||
virtio_error(vdev, "Cannot map descriptor ring");
|
virtio_error(vdev, "Cannot map descriptor ring");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((rc = virtqueue_num_heads(vq, idx)) > 0) {
|
while ((rc = virtqueue_num_heads(vq, idx)) > 0) {
|
||||||
MemoryRegionCache *desc_cache = &vring_desc_cache;
|
MemoryRegionCache *desc_cache = &caches->desc;
|
||||||
unsigned int num_bufs;
|
unsigned int num_bufs;
|
||||||
VRingDesc desc;
|
VRingDesc desc;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -586,13 +585,13 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
|
||||||
|
|
||||||
done:
|
done:
|
||||||
address_space_cache_destroy(&indirect_desc_cache);
|
address_space_cache_destroy(&indirect_desc_cache);
|
||||||
address_space_cache_destroy(&vring_desc_cache);
|
|
||||||
if (in_bytes) {
|
if (in_bytes) {
|
||||||
*in_bytes = in_total;
|
*in_bytes = in_total;
|
||||||
}
|
}
|
||||||
if (out_bytes) {
|
if (out_bytes) {
|
||||||
*out_bytes = out_total;
|
*out_bytes = out_total;
|
||||||
}
|
}
|
||||||
|
rcu_read_unlock();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err:
|
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)
|
void *virtqueue_pop(VirtQueue *vq, size_t sz)
|
||||||
{
|
{
|
||||||
unsigned int i, head, max;
|
unsigned int i, head, max;
|
||||||
MemoryRegionCache vring_desc_cache;
|
VRingMemoryRegionCaches *caches;
|
||||||
MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
|
MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
|
||||||
MemoryRegionCache *desc_cache;
|
MemoryRegionCache *desc_cache;
|
||||||
int64_t len;
|
int64_t len;
|
||||||
|
@ -768,15 +767,14 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
|
||||||
|
|
||||||
i = head;
|
i = head;
|
||||||
|
|
||||||
len = address_space_cache_init(&vring_desc_cache, vdev->dma_as,
|
rcu_read_lock();
|
||||||
vq->vring.desc, max * sizeof(VRingDesc),
|
caches = atomic_rcu_read(&vq->vring.caches);
|
||||||
false);
|
if (caches->desc.len < max * sizeof(VRingDesc)) {
|
||||||
if (len < max * sizeof(VRingDesc)) {
|
|
||||||
virtio_error(vdev, "Cannot map descriptor ring");
|
virtio_error(vdev, "Cannot map descriptor ring");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc_cache = &vring_desc_cache;
|
desc_cache = &caches->desc;
|
||||||
vring_desc_read(vdev, &desc, desc_cache, i);
|
vring_desc_read(vdev, &desc, desc_cache, i);
|
||||||
if (desc.flags & VRING_DESC_F_INDIRECT) {
|
if (desc.flags & VRING_DESC_F_INDIRECT) {
|
||||||
if (desc.len % sizeof(VRingDesc)) {
|
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);
|
trace_virtqueue_pop(vq, elem, elem->in_num, elem->out_num);
|
||||||
done:
|
done:
|
||||||
address_space_cache_destroy(&indirect_desc_cache);
|
address_space_cache_destroy(&indirect_desc_cache);
|
||||||
address_space_cache_destroy(&vring_desc_cache);
|
rcu_read_unlock();
|
||||||
|
|
||||||
return elem;
|
return elem;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue