On 4/30/25 21:39, John Levon wrote:
We'll use this parameter shortly; this just adds the plumbing.

I am not sure the 'unmap_all' name reflects what the dma_unmap()
handler does.


Signed-off-by: John Levon <john.le...@nutanix.com>
---
  hw/vfio/container-base.c              | 4 ++--
  hw/vfio/container.c                   | 8 ++++++--
  hw/vfio/iommufd.c                     | 6 +++++-
  hw/vfio/listener.c                    | 8 ++++----
  include/hw/vfio/vfio-container-base.h | 4 ++--
  5 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
index 09340fd97a..3ff473a45c 100644
--- a/hw/vfio/container-base.c
+++ b/hw/vfio/container-base.c
@@ -85,12 +85,12 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer,
int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
                               hwaddr iova, ram_addr_t size,
-                             IOMMUTLBEntry *iotlb)
+                             IOMMUTLBEntry *iotlb, bool unmap_all)
  {
      VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
g_assert(vioc->dma_unmap);
-    return vioc->dma_unmap(bcontainer, iova, size, iotlb);
+    return vioc->dma_unmap(bcontainer, iova, size, iotlb, unmap_all);
  }
bool vfio_container_add_section_window(VFIOContainerBase *bcontainer,
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 1dfdc312bd..766ba5a275 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -124,7 +124,7 @@ unmap_exit:
   */
  static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
                                   hwaddr iova, ram_addr_t size,
-                                 IOMMUTLBEntry *iotlb)
+                                 IOMMUTLBEntry *iotlb, bool unmap_all)
  {
      const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
                                                    bcontainer);
@@ -138,6 +138,10 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase 
*bcontainer,
      int ret;
      Error *local_err = NULL;
+ if (unmap_all) {
+        return -ENOTSUP;
+    }
+
      if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) {
          if (!vfio_container_devices_dirty_tracking_is_supported(bcontainer) &&
              bcontainer->dirty_pages_supported) {
@@ -205,7 +209,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase 
*bcontainer, hwaddr iova,
       */
      if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) == 0 ||
          (errno == EBUSY &&
-         vfio_legacy_dma_unmap(bcontainer, iova, size, NULL) == 0 &&
+         vfio_legacy_dma_unmap(bcontainer, iova, size, NULL, false) == 0 &&
           ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) == 0)) {
          return 0;
      }
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 62ecb758f1..6b2764c044 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -46,11 +46,15 @@ static int iommufd_cdev_map(const VFIOContainerBase 
*bcontainer, hwaddr iova,
static int iommufd_cdev_unmap(const VFIOContainerBase *bcontainer,
                                hwaddr iova, ram_addr_t size,
-                              IOMMUTLBEntry *iotlb)
+                              IOMMUTLBEntry *iotlb, bool unmap_all)
  {
      const VFIOIOMMUFDContainer *container =
          container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
+ if (unmap_all) {
+        return -ENOTSUP;
+    }
+
      /* TODO: Handle dma_unmap_bitmap with iotlb args (migration) */
      return iommufd_backend_unmap_dma(container->be,
                                       container->ioas_id, iova, size);
diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
index 6f77e18a7a..c5183700db 100644
--- a/hw/vfio/listener.c
+++ b/hw/vfio/listener.c
@@ -172,7 +172,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, 
IOMMUTLBEntry *iotlb)
          }
      } else {
          ret = vfio_container_dma_unmap(bcontainer, iova,
-                                       iotlb->addr_mask + 1, iotlb);
+                                       iotlb->addr_mask + 1, iotlb, false);
          if (ret) {
              error_setg(&local_err,
                         "vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", "
@@ -201,7 +201,7 @@ static void 
vfio_ram_discard_notify_discard(RamDiscardListener *rdl,
      int ret;
/* Unmap with a single call. */
-    ret = vfio_container_dma_unmap(bcontainer, iova, size , NULL);
+    ret = vfio_container_dma_unmap(bcontainer, iova, size , NULL, false);
      if (ret) {
          error_report("%s: vfio_container_dma_unmap() failed: %s", __func__,
                       strerror(-ret));
@@ -638,7 +638,7 @@ static void vfio_listener_region_del(MemoryListener 
*listener,
              /* The unmap ioctl doesn't accept a full 64-bit span. */
              llsize = int128_rshift(llsize, 1);
              ret = vfio_container_dma_unmap(bcontainer, iova,
-                                           int128_get64(llsize), NULL);
+                                           int128_get64(llsize), NULL, false);
              if (ret) {
                  error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", "
                               "0x%"HWADDR_PRIx") = %d (%s)",
@@ -648,7 +648,7 @@ static void vfio_listener_region_del(MemoryListener 
*listener,
              iova += int128_get64(llsize);
          }
          ret = vfio_container_dma_unmap(bcontainer, iova,
-                                       int128_get64(llsize), NULL);
+                                       int128_get64(llsize), NULL, false);
          if (ret) {
              error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", "
                           "0x%"HWADDR_PRIx") = %d (%s)",
diff --git a/include/hw/vfio/vfio-container-base.h 
b/include/hw/vfio/vfio-container-base.h
index 5527e02722..92cee54d11 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -81,7 +81,7 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer,
                             void *vaddr, bool readonly);
  int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
                               hwaddr iova, ram_addr_t size,
-                             IOMMUTLBEntry *iotlb);
+                             IOMMUTLBEntry *iotlb, bool unmap_all);
  bool vfio_container_add_section_window(VFIOContainerBase *bcontainer,
                                         MemoryRegionSection *section,
                                         Error **errp);
@@ -122,7 +122,7 @@ struct VFIOIOMMUClass {
                     void *vaddr, bool readonly);
      int (*dma_unmap)(const VFIOContainerBase *bcontainer,
                       hwaddr iova, ram_addr_t size,
-                     IOMMUTLBEntry *iotlb);
+                     IOMMUTLBEntry *iotlb, bool unmap_all);
      bool (*attach_device)(const char *name, VFIODevice *vbasedev,
                            AddressSpace *as, Error **errp);
      void (*detach_device)(VFIODevice *vbasedev);

Please add documentation to dma_unmap().

Thanks,

C.



Reply via email to