[PATCH 02/26] vfio/container: pass listener_begin/commit callbacks

John Levon posted 26 patches 5 months, 4 weeks ago
Only 23 patches received!
[PATCH 02/26] vfio/container: pass listener_begin/commit callbacks
Posted by John Levon 5 months, 4 weeks ago
The vfio-user container will later need to hook into these callbacks;
set up vfio to use them, and optionally pass them through to the
container.

Signed-off-by: John Levon <john.levon@nutanix.com>
---
 hw/vfio/common.c                      | 22 ++++++++++++++++++++++
 include/hw/vfio/vfio-container-base.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 8eb2ed50dd..a18af7a94f 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -563,6 +563,26 @@ static bool vfio_get_section_iova_range(VFIOContainerBase *bcontainer,
     return true;
 }
 
+static void vfio_listener_begin(MemoryListener *listener)
+{
+    VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
+                                                 listener);
+
+    if (bcontainer->ops->listener_begin) {
+        (bcontainer->ops->listener_begin)(bcontainer);
+    }
+}
+
+static void vfio_listener_commit(MemoryListener *listener)
+{
+    VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
+                                                 listener);
+
+    if (bcontainer->ops->listener_commit) {
+        (bcontainer->ops->listener_commit)(bcontainer);
+    }
+}
+
 static void vfio_listener_region_add(MemoryListener *listener,
                                      MemoryRegionSection *section)
 {
@@ -1382,6 +1402,8 @@ static void vfio_listener_log_sync(MemoryListener *listener,
 
 const MemoryListener vfio_memory_listener = {
     .name = "vfio",
+    .begin = vfio_listener_begin,
+    .commit = vfio_listener_commit,
     .region_add = vfio_listener_region_add,
     .region_del = vfio_listener_region_del,
     .log_global_start = vfio_listener_log_global_start,
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
index 129e742643..e9b59c179e 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -111,6 +111,8 @@ struct VFIOIOMMUClass {
 
     /* basic feature */
     bool (*setup)(VFIOContainerBase *bcontainer, Error **errp);
+    void (*listener_begin)(VFIOContainerBase *bcontainer);
+    void (*listener_commit)(VFIOContainerBase *bcontainer);
     int (*dma_map)(const VFIOContainerBase *bcontainer,
                    hwaddr iova, ram_addr_t size,
                    void *vaddr, bool readonly, MemoryRegion *mrp);
-- 
2.34.1