[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/28] vfio: implement unmap all for DMA unmap callbacks
From: |
Cédric Le Goater |
Subject: |
[PULL 23/28] vfio: implement unmap all for DMA unmap callbacks |
Date: |
Fri, 9 May 2025 15:13:12 +0200 |
From: John Levon <john.levon@nutanix.com>
Handle unmap_all in the DMA unmap handlers rather than in the caller.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link:
20250507152020.1254632-10-john.levon@nutanix.com">https://lore.kernel.org/qemu-devel/20250507152020.1254632-10-john.levon@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio/container.c | 41 +++++++++++++++++++++++++++++++----------
hw/vfio/iommufd.c | 15 ++++++++++++++-
hw/vfio/listener.c | 19 ++++++-------------
3 files changed, 51 insertions(+), 24 deletions(-)
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index
d5f4e66f1c4146c2eb6a2ce209c74c4d391c27ce..a9f0dbaec4c8d83450048d9bc53b34d859731ebb
100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -119,12 +119,9 @@ unmap_exit:
return ret;
}
-/*
- * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86
- */
-static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
- hwaddr iova, ram_addr_t size,
- IOMMUTLBEntry *iotlb, bool unmap_all)
+static int vfio_legacy_dma_unmap_one(const VFIOContainerBase *bcontainer,
+ hwaddr iova, ram_addr_t size,
+ IOMMUTLBEntry *iotlb)
{
const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
bcontainer);
@@ -138,10 +135,6 @@ 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) {
@@ -185,6 +178,34 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
*bcontainer,
return 0;
}
+/*
+ * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86
+ */
+static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
+ hwaddr iova, ram_addr_t size,
+ IOMMUTLBEntry *iotlb, bool unmap_all)
+{
+ int ret;
+
+ if (unmap_all) {
+ /* The unmap ioctl doesn't accept a full 64-bit span. */
+ Int128 llsize = int128_rshift(int128_2_64(), 1);
+
+ ret = vfio_legacy_dma_unmap_one(bcontainer, 0, int128_get64(llsize),
+ iotlb);
+
+ if (ret == 0) {
+ ret = vfio_legacy_dma_unmap_one(bcontainer, int128_get64(llsize),
+ int128_get64(llsize), iotlb);
+ }
+
+ } else {
+ ret = vfio_legacy_dma_unmap_one(bcontainer, iova, size, iotlb);
+ }
+
+ return ret;
+}
+
static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr
iova,
ram_addr_t size, void *vaddr, bool readonly)
{
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index
6b2764c044135b95c199b5df2f864156817fb6fc..af1c7ab10a090a2a4a2913231fc50903be9fb0f1
100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -51,8 +51,21 @@ static int iommufd_cdev_unmap(const VFIOContainerBase
*bcontainer,
const VFIOIOMMUFDContainer *container =
container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
+ /* unmap in halves */
if (unmap_all) {
- return -ENOTSUP;
+ Int128 llsize = int128_rshift(int128_2_64(), 1);
+ int ret;
+
+ ret = iommufd_backend_unmap_dma(container->be, container->ioas_id,
+ 0, int128_get64(llsize));
+
+ if (ret == 0) {
+ ret = iommufd_backend_unmap_dma(container->be, container->ioas_id,
+ int128_get64(llsize),
+ int128_get64(llsize));
+ }
+
+ return ret;
}
/* TODO: Handle dma_unmap_bitmap with iotlb args (migration) */
diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
index
c5183700dbd859c9a66083f2cb6f74a75a01cc66..e7ade7d62ec81c9228e096ba4818a8dd09f54bd3
100644
--- a/hw/vfio/listener.c
+++ b/hw/vfio/listener.c
@@ -634,21 +634,14 @@ static void vfio_listener_region_del(MemoryListener
*listener,
}
if (try_unmap) {
+ bool unmap_all = false;
+
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_container_dma_unmap(bcontainer, iova,
- int128_get64(llsize), NULL, false);
- if (ret) {
- error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", "
- "0x%"HWADDR_PRIx") = %d (%s)",
- bcontainer, iova, int128_get64(llsize), ret,
- strerror(-ret));
- }
- iova += int128_get64(llsize);
+ unmap_all = true;
+ llsize = int128_zero();
}
- ret = vfio_container_dma_unmap(bcontainer, iova,
- int128_get64(llsize), NULL, false);
+ ret = vfio_container_dma_unmap(bcontainer, iova, int128_get64(llsize),
+ NULL, unmap_all);
if (ret) {
error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", "
"0x%"HWADDR_PRIx") = %d (%s)",
--
2.49.0
- [PULL 06/28] vfio/igd: Detect IGD device by OpRegion, (continued)
- [PULL 06/28] vfio/igd: Detect IGD device by OpRegion, Cédric Le Goater, 2025/05/09
- [PULL 08/28] vfio/igd: Check OpRegion support on GVT-g mdev, Cédric Le Goater, 2025/05/09
- [PULL 09/28] vfio/igd: Enable OpRegion by default, Cédric Le Goater, 2025/05/09
- [PULL 10/28] vfio/igd: Allow overriding GMS with 0xf0 to 0xfe on Gen9+, Cédric Le Goater, 2025/05/09
- [PULL 11/28] vfio/igd: Only emulate GGC register when x-igd-gms is set, Cédric Le Goater, 2025/05/09
- [PULL 13/28] linux-header: update-linux-header script changes, Cédric Le Goater, 2025/05/09
- [PULL 12/28] vfio/igd: Remove generation limitation for IGD passthrough, Cédric Le Goater, 2025/05/09
- [PULL 14/28] linux-headers: Update to Linux v6.15-rc3, Cédric Le Goater, 2025/05/09
- [PULL 16/28] vfio: add vfio_device_unprepare(), Cédric Le Goater, 2025/05/09
- [PULL 19/28] vfio: consistently handle return value for helpers, Cédric Le Goater, 2025/05/09
- [PULL 23/28] vfio: implement unmap all for DMA unmap callbacks,
Cédric Le Goater <=
- [PULL 15/28] vfio: add vfio_device_prepare(), Cédric Le Goater, 2025/05/09
- [PULL 21/28] vfio: add vfio_pci_config_space_read/write(), Cédric Le Goater, 2025/05/09
- [PULL 22/28] vfio: add unmap_all flag to DMA unmap callback, Cédric Le Goater, 2025/05/09
- [PULL 24/28] vfio: add device IO ops vector, Cédric Le Goater, 2025/05/09
- [PULL 26/28] vfio: add read/write to device IO ops vector, Cédric Le Goater, 2025/05/09
- [PULL 28/28] vfio/container: pass listener_begin/commit callbacks, Cédric Le Goater, 2025/05/09
- [PULL 27/28] vfio: add vfio-pci-base class, Cédric Le Goater, 2025/05/09
- [PULL 25/28] vfio: add region info cache, Cédric Le Goater, 2025/05/09
- [PULL 20/28] vfio: add strread/writeerror(), Cédric Le Goater, 2025/05/09
- [PULL 17/28] vfio: add vfio_attach_device_by_iommu_type(), Cédric Le Goater, 2025/05/09