[PATCH 0/2] iommu: Propagate iova_bitmap_set() errors through read_and_clear_dirty
From: Samarth Narang
Date: Thu Oct 22 2026 - 09:19:39 EST
This is a follow-up series on a6ec38d74c08 ("iommufd/iova_bitmap: Fail
GET_DIRTY_BITMAP when a bitmap page cannot be pinned"), which keeps the
first iova_bitmap_set() error in the iova_bitmap so the ioctl fails. As
Jason suggested, this series propagates the error up the call chain
instead.
Patch 1 makes iova_bitmap_set() and iommu_dirty_bitmap_record() return
an error, and makes the iommupt and io-pgtable-arm dirty walkers stop on
it before clearing the IOPTE. We only clear the dirty bit after it has
been recorded in the user bitmap, which prevents a failed
GET_DIRTY_BITMAP from losing the dirty state of the IOPTEs. This should
also address the case Andrea raised for the -EPROTO path: with this
series, an entry that did not fit stays dirty for the retry.
Patch 2 adds a corresponding selftest. It fails on the current for-next
and passes with patch 1.
Tested on x86_64 in a 2 vCPU QEMU/KVM guest with the iommufd selftest
(mock iommupt domain, CONFIG_DEBUG_GENERIC_PT=y): the new test is the
only change in outcome, with no WARN in dmesg.
Samarth Narang (2):
iommu: Return iova_bitmap_set() errors from read_and_clear_dirty
iommufd/selftest: Test GET_DIRTY_BITMAP with an unpinnable bitmap page
drivers/iommu/generic_pt/iommu_pt.h | 29 +++++++++-----
drivers/iommu/io-pgtable-arm.c | 5 ++-
drivers/iommu/iommufd/iova_bitmap.c | 18 ++++++---
include/linux/iommu.h | 27 ++++++++-----
include/linux/iova_bitmap.h | 9 +++--
tools/testing/selftests/iommu/iommufd.c | 50 +++++++++++++++++++++++++
6 files changed, 110 insertions(+), 28 deletions(-)
base-commit: 04bcf84613346b973a8cc0c59238b6b5bc902688
--
2.53.0