[PATCH v2 0/2] iommufd: remove the last use of set_page_dirty_lock()
From: Tal Zussman
Date: Fri Nov 06 2026 - 14:02:08 EST
batch_rw() copies to and from pinned user pages one page at a time and
dirties each with set_page_dirty_lock(). The second patch walks the pfn
batch a folio at a time with memcpy_to_folio() and memcpy_from_folio()
and marks each folio dirty once. It removes the last use of
set_page_dirty_lock() in iommufd.
The issue fixed in the first patch was found while testing the second:
iommufd_fail_nth turned up a dev_iommu leak in iommu_mock_device_add()
under kmemleak. The fix is independent and could go through the iommu
tree on its own.
Tested on x86 under virtme-ng with KASAN and lockdep against the iommufd
mock driver. The selftests and iommufd_fail_nth all pass.
With ftrace timing iopt_pages_rw_slow() through the mock driver on a
non-debug kernel, slow-path writes to THP-backed pages drop from ~1310 to
~930 ns/page (now the same cost as a read), and writes to 4K folios drop
~9%.
---
Changes in v2:
- Add tags (thanks Jason!)
- Allocate the fwspec before dev->iommu, per Jason Gunthorpe.
- Fix the Fixes tag, per Robin Murphy.
- Link to v1: https://patch.msgid.link/20261031-iommufd-folio-dirty-v1-0-2cef66d2d6d1@xxxxxxxxxxxx
---
Tal Zussman (2):
iommu: allocate the fwspec before dev->iommu in iommu_fwspec_init()
iommufd: copy to and from folios in batch_rw()
drivers/iommu/iommu.c | 8 +++++---
drivers/iommu/iommufd/pages.c | 35 ++++++++++++++++++++---------------
2 files changed, 25 insertions(+), 18 deletions(-)
---
base-commit: 04bcf84613346b973a8cc0c59238b6b5bc902688
change-id: 20261015-iommufd-folio-dirty-8abff4281f3a
Best regards,
--
Tal Zussman <tz2294@xxxxxxxxxxxx>