[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 24/40] vdpa: factor out vhost_vdpa_dma_batch_end
From: |
Si-Wei Liu |
Subject: |
[PATCH 24/40] vdpa: factor out vhost_vdpa_dma_batch_end |
Date: |
Thu, 7 Dec 2023 09:39:37 -0800 |
Refactoring only. No functional change.
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
---
hw/virtio/trace-events | 2 +-
hw/virtio/vhost-vdpa.c | 30 ++++++++++++++++++------------
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index b0239b8..3411a07 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -33,7 +33,7 @@ vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p"
vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid,
uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type)
"vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64"
size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8
vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid,
uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type:
%"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8
vhost_vdpa_map_batch_begin(void *v, int fd, uint32_t msg_type, uint8_t type)
"vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
-vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type)
"vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
+vhost_vdpa_dma_batch_end(void *v, int fd, uint32_t msg_type, uint8_t type)
"vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t
offset_as, uint64_t offset_page) "vdpa_shared: %p region %s
offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void
*vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p
read-only: %d"
vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t
offset_as, uint64_t offset_page) "vdpa_shared: %p region %s
offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index a6c6fe5..999a97a 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -198,19 +198,11 @@ static void
vhost_vdpa_dma_batch_begin_once(VhostVDPAShared *s)
}
}
-static void vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s)
+static bool vhost_vdpa_dma_batch_end(VhostVDPAShared *s)
{
struct vhost_msg_v2 msg = {};
int fd = s->device_fd;
- if (!(s->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) {
- return;
- }
-
- if (!s->iotlb_batch_begin_sent) {
- return;
- }
-
msg.type = VHOST_IOTLB_MSG_V2;
msg.iotlb.type = VHOST_IOTLB_BATCH_END;
@@ -220,16 +212,30 @@ static void vhost_vdpa_dma_batch_end_once(VhostVDPAShared
*s)
*new_msg = msg;
g_async_queue_push(s->map_queue, new_msg);
- return;
+ return false;
}
- trace_vhost_vdpa_listener_commit(s, fd, msg.type, msg.iotlb.type);
+ trace_vhost_vdpa_dma_batch_end(s, fd, msg.type, msg.iotlb.type);
if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
error_report("failed to write, fd=%d, errno=%d (%s)",
fd, errno, strerror(errno));
}
+ return true;
+}
+
+static void vhost_vdpa_dma_batch_end_once(VhostVDPAShared *s)
+{
+ if (!(s->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) {
+ return;
+ }
+
+ if (!s->iotlb_batch_begin_sent) {
+ return;
+ }
- s->iotlb_batch_begin_sent = false;
+ if (vhost_vdpa_dma_batch_end(s)) {
+ s->iotlb_batch_begin_sent = false;
+ }
}
static void vhost_vdpa_listener_commit(MemoryListener *listener)
--
1.8.3.1
- [PATCH 18/40] vdpa: unregister listener on last dev cleanup, (continued)
- [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, 2023/12/07
- [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 <=
- [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
- [PATCH 29/40] vdpa: expose API vhost_vdpa_dma_batch_once, Si-Wei Liu, 2023/12/07
- [PATCH 31/40] vdpa: batch map and unmap around cvq svq start/stop, Si-Wei Liu, 2023/12/07