Skip to content

iommupt: Unmap and return the PFNs in one walk

Fred Griffoul linux-iommu linux-kselftest lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3iommupt: Add iommu_unmap_sparse()drivers/iommu/generic_pt/iommu_pt.h drivers/iommu/generic_pt/kunit_iommu_pt.h drivers/iommu/iommu-debug-pagealloc.c +4 more+363 -10 replies
2/3iommufd: Use iommu_unmap_sparse() to unpin domain pagesdrivers/iommu/iommufd/pages.c+93 -50 replies
3/3iommufd/selftest: Unmap areas that start inside a CPU pagetools/testing/selftests/iommu/iommufd.c+30 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] iommupt: Unmap and return the PFNs in one walk

From: Fred Griffoul <[email protected]>

When iommufd unmaps an area, it must unpin the user pages, but it keeps no list of their PFNs. It reads each one back from the IOMMU domain with iommu_iova_to_phys(), one CPU page at a time, then walks the page table again in iommu_unmap(). With 4 KiB pages, a 1 GiB IOPTE costs 262144 lookups before the unmap starts.

This series lets the iommupt unmap walk report the physical range of each IOPTE as it removes it, so iommufd unmaps and collects the PFNs in one walk. The walk also steps over holes, where iommu_unmap() stops at the first one.

Patch 1 adds iommu_unmap_sparse(), patch 2 uses it in iopt_area_unpin_domain(), and patch 3 adds a selftest for the areas that keep the per-page read-back.

An earlier series [1] proposed iova_to_phys_length() so that iommufd can read the PFNs back one IOPTE at a time instead of one page at a time. The unmap is still a second walk there. This series collects the PFNs in the unmap walk itself.

The series applies to iommu/next. I wrote parts of the code and the changelogs with Kiro, an AI coding assistant using Claude models, and used it to run the tests. I reviewed and tested all of it.

[1] https://lore.kernel.org/linux-iommu/[email protected]/

Fred Griffoul (3):
iommupt: Add iommu_unmap_sparse()
iommufd: Use iommu_unmap_sparse() to unpin domain pages iommufd/selftest: Unmap areas that start inside a CPU page

 drivers/iommu/generic_pt/iommu_pt.h       |  61 ++++++++-
 drivers/iommu/generic_pt/kunit_iommu_pt.h | 144 ++++++++++++++++++++++
 drivers/iommu/iommu-debug-pagealloc.c     |  13 ++
 drivers/iommu/iommu-priv.h                |  24 ++++
 drivers/iommu/iommu.c                     |  76 ++++++++++++
 drivers/iommu/iommufd/pages.c             |  98 ++++++++++++++-
 include/linux/generic_pt/iommu.h          |  24 ++++
 include/linux/iommu.h                     |  22 ++++
 tools/testing/selftests/iommu/iommufd.c   |  30 +++++
 9 files changed, 486 insertions(+), 6 deletions(-)

base-commit: 2cf4be57b301ed2d7af82e70cff5dfd96894d8de

Signature · 1 line
2.47.3