[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 19/40] vdpa: should avoid map flushing with persistent iotlb
From: |
Si-Wei Liu |
Subject: |
[PATCH 19/40] vdpa: should avoid map flushing with persistent iotlb |
Date: |
Thu, 7 Dec 2023 09:39:32 -0800 |
Today memory listener is unregistered in vhost_vdpa_reset_status
unconditionally, due to which all the maps will be flushed away
from the iotlb. However, map flush is not always needed, and
doing it from performance hot path may have innegligible latency
impact that affects VM reboot time or brown out period during
live migration.
Leverage the IOTLB_PERSIST backend featuae, which ensures durable
iotlb maps and not disappearing even across reset. When it is
supported, we may conditionally keep the maps for cases where the
guest memory mapping doesn't change. Prepare a function so that
the next patch will be able to use it to keep the maps.
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
---
hw/virtio/trace-events | 1 +
hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index 77905d1..9725d44 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -66,6 +66,7 @@ vhost_vdpa_set_owner(void *dev) "dev: %p"
vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t
avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr:
0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64
vhost_vdpa_get_iova_range(void *dev, uint64_t first, uint64_t last) "dev: %p
first: 0x%"PRIx64" last: 0x%"PRIx64
vhost_vdpa_set_config_call(void *dev, int fd)"dev: %p fd: %d"
+vhost_vdpa_maybe_flush_map(void *dev, bool reg, bool flush, bool persist)
"dev: %p registered: %d flush_map: %d iotlb_persistent: %d"
# virtio.c
virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned
out_num) "elem %p size %zd in_num %u out_num %u"
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index ea2dfc8..31e0a55 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -1471,6 +1471,26 @@ out_stop:
return ok ? 0 : -1;
}
+static void vhost_vdpa_maybe_flush_map(struct vhost_dev *dev)
+{
+ struct vhost_vdpa *v = dev->opaque;
+
+ trace_vhost_vdpa_maybe_flush_map(dev, v->shared->listener_registered,
+ v->shared->flush_map,
+ !!(dev->backend_cap &
+ BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST)));
+
+ if (!v->shared->listener_registered) {
+ return;
+ }
+
+ if (!(dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST)) ||
+ v->shared->flush_map) {
+ memory_listener_unregister(&v->shared->listener);
+ v->shared->listener_registered = false;
+ }
+}
+
static void vhost_vdpa_reset_status(struct vhost_dev *dev)
{
struct vhost_vdpa *v = dev->opaque;
--
1.8.3.1
- Re: [PATCH 11/40] vdpa: factor out vhost_vdpa_last_dev, (continued)
- [PATCH 17/40] vdpa: judge if map can be kept across reset, Si-Wei Liu, 2023/12/07
- [PATCH 18/40] vdpa: unregister listener on last dev cleanup, Si-Wei Liu, 2023/12/07
- [PATCH 08/40] vdpa: add back vhost_vdpa_net_first_nc_vdpa, Si-Wei Liu, 2023/12/07
- [PATCH 22/40] vdpa: factor out vhost_vdpa_map_batch_begin, Si-Wei Liu, 2023/12/07
- [PATCH 25/40] vdpa: add asid to dma_batch_once API, Si-Wei Liu, 2023/12/07
- [PATCH 19/40] vdpa: should avoid map flushing with persistent iotlb,
Si-Wei Liu <=
- [PATCH 21/40] vdpa: vhost_vdpa_dma_batch_end_once rename, Si-Wei Liu, 2023/12/07
- [PATCH 16/40] vdpa: indicate SVQ switching via flag, Si-Wei Liu, 2023/12/07
- [PATCH 24/40] vdpa: factor out vhost_vdpa_dma_batch_end, Si-Wei Liu, 2023/12/07
- [PATCH 26/40] vdpa: return int for dma_batch_once API, Si-Wei Liu, 2023/12/07
- [PATCH 27/40] vdpa: add asid to all dma_batch call sites, Si-Wei Liu, 2023/12/07
- [PATCH 20/40] vdpa: avoid mapping flush across reset, Si-Wei Liu, 2023/12/07
- [PATCH 23/40] vdpa: vhost_vdpa_dma_batch_begin_once rename, Si-Wei Liu, 2023/12/07
- [PATCH 28/40] vdpa: support iotlb_batch_asid, Si-Wei Liu, 2023/12/07
- [PATCH 30/40] vdpa: batch map/unmap op per svq pair basis, Si-Wei Liu, 2023/12/07