[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aQEOhyYQKW4unEfZ@devgpu012.nha5.facebook.com>
Date: Tue, 28 Oct 2025 11:42:15 -0700
From: Alex Mastro <amastro@...com>
To: Jason Gunthorpe <jgg@...pe.ca>
CC: Alex Williamson <alex.williamson@...hat.com>,
Alejandro Jimenez
<alejandro.j.jimenez@...cle.com>,
David Matlack <dmatlack@...gle.com>, <kvm@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 0/3] vfio: handle DMA map/unmap up to the addressable
limit
On Mon, Oct 27, 2025 at 10:39:04AM -0300, Jason Gunthorpe wrote:
> On Sat, Oct 25, 2025 at 11:11:49AM -0700, Alex Mastro wrote:
> > Alex and Jason, during my testing, I found that the behavior of range-based
> > (!VFIO_DMA_UNMAP_FLAG_ALL) VFIO_IOMMU_UNMAP_DMA differs slightly when using
> > /dev/iommu as the container.
> >
> > iommufd treats range-based unmap where there are no hits in the range as an
> > error, and the ioctl fails with ENOENT.
>
> > vfio_iommu_type1.c treats this as a success and reports zero bytes unmapped in
> > vfio_iommu_type1_dma_unmap.size.
>
> Oh, weird...
>
> What do you think about this:
>
> diff --git a/drivers/iommu/iommufd/io_pagetable.c b/drivers/iommu/iommufd/io_pagetable.c
> index c0360c450880b8..1124f68ec9020d 100644
> --- a/drivers/iommu/iommufd/io_pagetable.c
> +++ b/drivers/iommu/iommufd/io_pagetable.c
> @@ -707,7 +707,8 @@ static int iopt_unmap_iova_range(struct io_pagetable *iopt, unsigned long start,
> struct iopt_area *area;
> unsigned long unmapped_bytes = 0;
> unsigned int tries = 0;
> - int rc = -ENOENT;
> + /* If there are no mapped entries then success */
> + int rc = 0;
>
> /*
> * The domains_rwsem must be held in read mode any time any area->pages
> diff --git a/drivers/iommu/iommufd/ioas.c b/drivers/iommu/iommufd/ioas.c
> index 1542c5fd10a85c..ef5e56672dea56 100644
> --- a/drivers/iommu/iommufd/ioas.c
> +++ b/drivers/iommu/iommufd/ioas.c
> @@ -367,6 +367,8 @@ int iommufd_ioas_unmap(struct iommufd_ucmd *ucmd)
> &unmapped);
> if (rc)
> goto out_put;
> + if (!unmapped)
> + rc = -ENOENT;
> }
>
> cmd->length = unmapped;
Seems reasonable to me. The only affected callers are
drivers/iommu/iommufd/ioas.c
366: rc = iopt_unmap_iova(&ioas->iopt, cmd->iova, cmd->length,
drivers/iommu/iommufd/vfio_compat.c
244: rc = iopt_unmap_iova(&ioas->iopt, unmap.iova, unmap.size,
So your proposal should get vfio_compat.c into good shape.
I think these locations need more scrutiny after your change
diff --git a/drivers/iommu/iommufd/io_pagetable.c b/drivers/iommu/iommufd/io_pagetable.c
index c0360c450880..e271696f726f 100644
--- a/drivers/iommu/iommufd/io_pagetable.c
+++ b/drivers/iommu/iommufd/io_pagetable.c
@@ -777,6 +777,7 @@ static int iopt_unmap_iova_range(struct io_pagetable *iopt, unsigned long start,
down_write(&iopt->iova_rwsem);
}
+ // redundant?
if (unmapped_bytes)
rc = 0;
@@ -818,6 +819,7 @@ int iopt_unmap_all(struct io_pagetable *iopt, unsigned long *unmapped)
int rc;
rc = iopt_unmap_iova_range(iopt, 0, ULONG_MAX, unmapped);
+ // intent still holds?
/* If the IOVAs are empty then unmap all succeeds */
if (rc == -ENOENT)
return 0;
Powered by blists - more mailing lists