[PATCH v2 0/3] Optimize unmap_all with one ioctl()

Zhenzhong Duan posted 3 patches 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251009040134.334251-1-zhenzhong.duan@intel.com
Maintainers: Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>
include/hw/vfio/vfio-container-legacy.h |  1 +
hw/vfio/container-legacy.c              | 38 ++++++++++++++-----------
hw/vfio/iommufd.c                       | 15 +---------
hw/vfio/listener.c                      |  1 +
4 files changed, 25 insertions(+), 30 deletions(-)
[PATCH v2 0/3] Optimize unmap_all with one ioctl()
Posted by Zhenzhong Duan 1 month ago
Currently unmap_all is split into two ioctl() with each unmap half of
the whole iova space.

IOMMUFD supports unmap_all ioctl() from beginning, after kernel commit
c19650995374 ("vfio/type1: implement unmap all") added same support
for VFIO type1, the split becomes unnecessary.

So optimize the code to only do one ioctl() to unmap_all for both
backends.

Test:
In order to trigger unmap_all request, I have to fake a unmap_all request
on x86. Maybe it's easy to trigger unmap_all with other arch, e.g., arm smmu,
but for x86, iommu memory region is split by iommu_ir, unmap_all isn't
triggered by default. See
https://github.com/yiliu1765/qemu/commit/7afc7adac8fa601abd978b821c86e90e073d31ba
for details.

Thanks
Zhenzhong

Changelog:
v2:
- check unmap_all_supported instead of ioctl() for every unmap_all (John Levon)
- make assertion a separate patch (Cedric)
- pass VFIOLegacyContainer pointer in vfio_legacy_dma_unmap_one() (Cedric)

Zhenzhong Duan (3):
  vfio/container: Support unmap all in one ioctl()
  vfio/iommufd: Support unmap all in one ioctl()
  vfio/listener: Add an assertion for unmap_all

 include/hw/vfio/vfio-container-legacy.h |  1 +
 hw/vfio/container-legacy.c              | 38 ++++++++++++++-----------
 hw/vfio/iommufd.c                       | 15 +---------
 hw/vfio/listener.c                      |  1 +
 4 files changed, 25 insertions(+), 30 deletions(-)

-- 
2.47.1
Re: [PATCH v2 0/3] Optimize unmap_all with one ioctl()
Posted by Cédric Le Goater 1 month ago
On 10/9/25 06:01, Zhenzhong Duan wrote:
> Currently unmap_all is split into two ioctl() with each unmap half of
> the whole iova space.
> 
> IOMMUFD supports unmap_all ioctl() from beginning, after kernel commit
> c19650995374 ("vfio/type1: implement unmap all") added same support
> for VFIO type1, the split becomes unnecessary.
> 
> So optimize the code to only do one ioctl() to unmap_all for both
> backends.
> 
> Test:
> In order to trigger unmap_all request, I have to fake a unmap_all request
> on x86. Maybe it's easy to trigger unmap_all with other arch, e.g., arm smmu,
> but for x86, iommu memory region is split by iommu_ir, unmap_all isn't
> triggered by default. See
> https://github.com/yiliu1765/qemu/commit/7afc7adac8fa601abd978b821c86e90e073d31ba
> for details.
> 
> Thanks
> Zhenzhong
> 
> Changelog:
> v2:
> - check unmap_all_supported instead of ioctl() for every unmap_all (John Levon)
> - make assertion a separate patch (Cedric)
> - pass VFIOLegacyContainer pointer in vfio_legacy_dma_unmap_one() (Cedric)
> 
> Zhenzhong Duan (3):
>    vfio/container: Support unmap all in one ioctl()
>    vfio/iommufd: Support unmap all in one ioctl()
>    vfio/listener: Add an assertion for unmap_all
> 
>   include/hw/vfio/vfio-container-legacy.h |  1 +
>   hw/vfio/container-legacy.c              | 38 ++++++++++++++-----------
>   hw/vfio/iommufd.c                       | 15 +---------
>   hw/vfio/listener.c                      |  1 +
>   4 files changed, 25 insertions(+), 30 deletions(-)
> 


Applied to vfio-next.

Thanks,

C.
Re: [PATCH v2 0/3] Optimize unmap_all with one ioctl()
Posted by Cédric Le Goater 1 month ago
On 10/9/25 06:01, Zhenzhong Duan wrote:
> Currently unmap_all is split into two ioctl() with each unmap half of
> the whole iova space.
> 
> IOMMUFD supports unmap_all ioctl() from beginning, after kernel commit
> c19650995374 ("vfio/type1: implement unmap all") added same support
> for VFIO type1, the split becomes unnecessary.
> 
> So optimize the code to only do one ioctl() to unmap_all for both
> backends.
> 
> Test:
> In order to trigger unmap_all request, I have to fake a unmap_all request
> on x86. Maybe it's easy to trigger unmap_all with other arch, e.g., arm smmu,
> but for x86, iommu memory region is split by iommu_ir, unmap_all isn't
> triggered by default. See
> https://github.com/yiliu1765/qemu/commit/7afc7adac8fa601abd978b821c86e90e073d31ba
> for details.
> 
> Thanks
> Zhenzhong
> 
> Changelog:
> v2:
> - check unmap_all_supported instead of ioctl() for every unmap_all (John Levon)
> - make assertion a separate patch (Cedric)
> - pass VFIOLegacyContainer pointer in vfio_legacy_dma_unmap_one() (Cedric)
> 
> Zhenzhong Duan (3):
>    vfio/container: Support unmap all in one ioctl()
>    vfio/iommufd: Support unmap all in one ioctl()
>    vfio/listener: Add an assertion for unmap_all
> 
>   include/hw/vfio/vfio-container-legacy.h |  1 +
>   hw/vfio/container-legacy.c              | 38 ++++++++++++++-----------
>   hw/vfio/iommufd.c                       | 15 +---------
>   hw/vfio/listener.c                      |  1 +
>   4 files changed, 25 insertions(+), 30 deletions(-)
> 


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.