qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Optimize unmap_all with one ioctl()
@ 2025-09-24  7:02 Zhenzhong Duan
  2025-09-24  7:02 ` [PATCH 1/2] vfio/container: Support unmap all in " Zhenzhong Duan
  2025-09-24  7:02 ` [PATCH 2/2] vfio/iommufd: " Zhenzhong Duan
  0 siblings, 2 replies; 11+ messages in thread
From: Zhenzhong Duan @ 2025-09-24  7:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: alex.williamson, clg, eric.auger, joao.m.martins, Zhenzhong Duan

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, made below trick, during emergency
reset in guest, memory region [0xfef00000 - 0xffffffffffffffff] is
deleted, I fake it to be a unmap_all request.

--- a/hw/vfio/listener.c
+++ b/hw/vfio/listener.c
@@ -714,8 +714,10 @@ static void vfio_listener_region_del(MemoryListener *listener,
     if (try_unmap) {
         bool unmap_all = false;

-        if (int128_eq(llsize, int128_2_64())) {
+        if (int128_eq(llsize, int128_2_64()) ||
+            iova == 0xfef00000) {
             unmap_all = true;
+            iova = 0;
             llsize = int128_zero();
         }

The log shows ioctl() succeed on the whole iova space:

vfio_listener_region_del region_del 0xfef00000 - 0xffffffffffffffff
iommufd_backend_unmap_dma  iommufd=10 ioas=5 iova=0x0 size=0xffffffffffffffff (0)

Same result for legacy VFIO.

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.

Thanks
Zhenzhong

Zhenzhong Duan (2):
  vfio/container: Support unmap all in one ioctl()
  vfio/iommufd: Support unmap all in one ioctl()

 hw/vfio/container.c | 33 ++++++++++++++++++++-------------
 hw/vfio/iommufd.c   | 16 ++--------------
 2 files changed, 22 insertions(+), 27 deletions(-)

-- 
2.47.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-10-08 13:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-24  7:02 [PATCH 0/2] Optimize unmap_all with one ioctl() Zhenzhong Duan
2025-09-24  7:02 ` [PATCH 1/2] vfio/container: Support unmap all in " Zhenzhong Duan
2025-09-30 15:26   ` Cédric Le Goater
2025-09-30 22:04     ` John Levon
2025-10-01  6:58       ` Cédric Le Goater
2025-10-08 10:18         ` Duan, Zhenzhong
2025-10-08 13:01           ` Cédric Le Goater
2025-10-08 13:11             ` John Levon
2025-10-08 13:26               ` Cédric Le Goater
2025-10-08 10:17     ` Duan, Zhenzhong
2025-09-24  7:02 ` [PATCH 2/2] vfio/iommufd: " Zhenzhong Duan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).