diff mbox series

[v1,18/24] vfio-user: add dma_unmap_all

Message ID d6c0241519fb3249ce69be9393ffad54671807c5.1667542066.git.john.g.johnson@oracle.com (mailing list archive)
State New, archived
Headers show
Series vfio-user client | expand

Commit Message

John Johnson Nov. 8, 2022, 11:13 p.m. UTC
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 hw/vfio/common.c              | 45 ++++++++++++++++++++++++++++++++++---------
 hw/vfio/user.c                | 24 +++++++++++++++++++++++
 include/hw/vfio/vfio-common.h |  3 +++
 3 files changed, 63 insertions(+), 9 deletions(-)

Comments

John Levon Dec. 9, 2022, 5:58 p.m. UTC | #1
On Tue, Nov 08, 2022 at 03:13:40PM -0800, John Johnson wrote:

> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---

> +static int vfio_user_io_dirty_bitmap(VFIOContainer *container,
> +                        struct vfio_iommu_type1_dirty_bitmap *bitmap,
> +                        struct vfio_iommu_type1_dirty_bitmap_get *range)
> +{
> +
> +    /* vfio-user doesn't support migration */
> +    return -EINVAL;
> +}

... and dirty_bitmap callback?

regards
john
diff mbox series

Patch

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index fe6eddd..cd64ec2 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -507,6 +507,14 @@  static int vfio_dma_unmap(VFIOContainer *container,
     return CONT_DMA_UNMAP(container, &unmap, NULL);
 }
 
+/*
+ * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86
+ */
+static int vfio_dma_unmap_all(VFIOContainer *container)
+{
+    return CONT_DMA_UNMAP_ALL(container, VFIO_DMA_UNMAP_FLAG_ALL);
+}
+
 static int vfio_dma_map(VFIOContainer *container, MemoryRegion *mr, hwaddr iova,
                         ram_addr_t size, void *vaddr, bool readonly)
 {
@@ -1256,17 +1264,10 @@  static void vfio_listener_region_del(MemoryListener *listener,
 
     if (try_unmap) {
         if (int128_eq(llsize, int128_2_64())) {
-            /* The unmap ioctl doesn't accept a full 64-bit span. */
-            llsize = int128_rshift(llsize, 1);
+            ret = vfio_dma_unmap_all(container);
+        } else {
             ret = vfio_dma_unmap(container, iova, int128_get64(llsize), NULL);
-            if (ret) {
-                error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "
-                             "0x%"HWADDR_PRIx") = %d (%m)",
-                             container, iova, int128_get64(llsize), ret);
-            }
-            iova += int128_get64(llsize);
         }
-        ret = vfio_dma_unmap(container, iova, int128_get64(llsize), NULL);
         if (ret) {
             error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "
                          "0x%"HWADDR_PRIx") = %d (%m)",
@@ -3057,6 +3058,31 @@  static int vfio_io_dma_unmap(VFIOContainer *container,
     return 0;
 }
 
+static int vfio_io_dma_unmap_all(VFIOContainer *container, uint32_t flags)
+{
+    struct vfio_iommu_type1_dma_unmap unmap = {
+        .argsz = sizeof(unmap),
+        .flags = 0,
+        .size = 0x8000000000000000,
+    };
+    int ret;
+
+    /* The unmap ioctl doesn't accept a full 64-bit span. */
+    unmap.iova = 0;
+    ret = ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap);
+    if (ret) {
+        return -errno;
+    }
+
+    unmap.iova += unmap.size;
+    ret = ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap);
+    if (ret) {
+        return -errno;
+    }
+
+    return 0;
+}
+
 static int vfio_io_dirty_bitmap(VFIOContainer *container,
                                 struct vfio_iommu_type1_dirty_bitmap *bitmap,
                                 struct vfio_iommu_type1_dirty_bitmap_get *range)
@@ -3076,6 +3102,7 @@  static void vfio_io_wait_commit(VFIOContainer *container)
 VFIOContIO vfio_cont_io_ioctl = {
     .dma_map = vfio_io_dma_map,
     .dma_unmap = vfio_io_dma_unmap,
+    .dma_unmap_all = vfio_io_dma_unmap_all,
     .dirty_bitmap = vfio_io_dirty_bitmap,
     .wait_commit = vfio_io_wait_commit,
 };
diff --git a/hw/vfio/user.c b/hw/vfio/user.c
index 1fd37cc..d62fe05 100644
--- a/hw/vfio/user.c
+++ b/hw/vfio/user.c
@@ -1646,6 +1646,28 @@  static int vfio_user_io_dma_unmap(VFIOContainer *container,
                                container->async_ops);
 }
 
+static int vfio_user_io_dma_unmap_all(VFIOContainer *container, uint32_t flags)
+{
+    struct vfio_iommu_type1_dma_unmap unmap = {
+        .argsz = sizeof(unmap),
+        .flags = flags | VFIO_DMA_UNMAP_FLAG_ALL,
+        .iova = 0,
+        .size = 0,
+    };
+
+    return vfio_user_dma_unmap(container->proxy, &unmap, NULL,
+                               container->async_ops);
+}
+
+static int vfio_user_io_dirty_bitmap(VFIOContainer *container,
+                        struct vfio_iommu_type1_dirty_bitmap *bitmap,
+                        struct vfio_iommu_type1_dirty_bitmap_get *range)
+{
+
+    /* vfio-user doesn't support migration */
+    return -EINVAL;
+}
+
 static void vfio_user_io_wait_commit(VFIOContainer *container)
 {
     vfio_user_wait_reqs(container->proxy);
@@ -1654,5 +1676,7 @@  static void vfio_user_io_wait_commit(VFIOContainer *container)
 VFIOContIO vfio_cont_io_sock = {
     .dma_map = vfio_user_io_dma_map,
     .dma_unmap = vfio_user_io_dma_unmap,
+    .dma_unmap_all = vfio_user_io_dma_unmap_all,
+    .dirty_bitmap = vfio_user_io_dirty_bitmap,
     .wait_commit = vfio_user_io_wait_commit,
 };
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 413dafc..d7e3f51 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -206,6 +206,7 @@  struct VFIOContIO {
     int (*dma_unmap)(VFIOContainer *container,
                      struct vfio_iommu_type1_dma_unmap *unmap,
                      struct vfio_bitmap *bitmap);
+    int (*dma_unmap_all)(VFIOContainer *container, uint32_t flags);
     int (*dirty_bitmap)(VFIOContainer *container,
                         struct vfio_iommu_type1_dirty_bitmap *bitmap,
                         struct vfio_iommu_type1_dirty_bitmap_get *range);
@@ -216,6 +217,8 @@  struct VFIOContIO {
     ((cont)->io_ops->dma_map((cont), (mr), (map)))
 #define CONT_DMA_UNMAP(cont, unmap, bitmap) \
     ((cont)->io_ops->dma_unmap((cont), (unmap), (bitmap)))
+#define CONT_DMA_UNMAP_ALL(cont, flags) \
+    ((cont)->io_ops->dma_unmap_all((cont), (flags)))
 #define CONT_DIRTY_BITMAP(cont, bitmap, range) \
     ((cont)->io_ops->dirty_bitmap((cont), (bitmap), (range)))
 #define CONT_WAIT_COMMIT(cont) ((cont)->io_ops->wait_commit(cont))