@@ -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,
};
@@ -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,
};
@@ -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))