mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
vfio: implement unmap all for DMA unmap callbacks
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: https://lore.kernel.org/qemu-devel/20250507152020.1254632-10-john.levon@nutanix.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
committed by
Cédric Le Goater
parent
5a22b50591
commit
9458d9b4dc
+31
-10
@@ -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)
|
||||
{
|
||||
|
||||
+14
-1
@@ -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) */
|
||||
|
||||
+6
-13
@@ -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)",
|
||||
|
||||
Reference in New Issue
Block a user