* [PATCH 1/2] iommufd: Move pinned_vm with the pages in IOMMU_IOAS_CHANGE_PROCESS
@ 2026-11-30 11:32 Peng Hao
2026-11-30 11:32 ` [PATCH 2/2] iommufd/selftest: Select IOMMU_IOPF Peng Hao
0 siblings, 1 reply; 2+ messages in thread
From: Peng Hao @ 2026-11-30 11:32 UTC (permalink / raw)
To: jgg, kevin.tian; +Cc: iommu
iopt_pages_update_pinned() adjusts pages->source_mm->pinned_vm for every
accounting mode, including IOPT_PAGES_ACCOUNT_NONE, which is the mode
used when the mapping process has CAP_IPC_LOCK. Only the RLIMIT_MEMLOCK
charge is skipped for that mode.
IOMMU_IOAS_CHANGE_PROCESS does not take that into account.
need_charge_update() returns false for IOPT_PAGES_ACCOUNT_NONE, so the
pinned pages are neither added to the new mm nor removed from the old
one, yet change_mm() still switches pages->source_mm to the new mm. The
old mm keeps the pages in pinned_vm forever, and when the new process
later unmaps them, they are subtracted from an mm that never had them.
With CONFIG_IOMMUFD_TEST, a process that keeps CAP_IPC_LOCK maps 16
pages of a memfd with IOMMU_IOAS_MAP_FILE, forks, and the child issues
IOMMU_IOAS_CHANGE_PROCESS and then IOMMU_IOAS_UNMAP:
after map: parent VmPin 64 kB
after CHANGE_PROCESS: parent VmPin 64 kB, child VmPin 0 kB
after child unmap: parent VmPin 64 kB, child VmPin 9223372036854775807 kB
and the parent still shows 64 kB after closing the iommufd.
The change_process selftest doesn't catch this because its fixture drops
CAP_IPC_LOCK, so the account_none variant actually runs in
IOPT_PAGES_ACCOUNT_USER mode.
Treat IOPT_PAGES_ACCOUNT_NONE like IOPT_PAGES_ACCOUNT_MM: the pinned
count needs to move whenever the mm changes. charge_current() and the
uncharge already handle this mode by only updating pinned_vm.
Fixes: 829ed626499c ("iommufd: Add IOMMU_IOAS_CHANGE_PROCESS")
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
drivers/iommu/iommufd/ioas.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/iommufd/ioas.c b/drivers/iommu/iommufd/ioas.c
index 8fb5271a9506..b873128fd48b 100644
--- a/drivers/iommu/iommufd/ioas.c
+++ b/drivers/iommu/iommufd/ioas.c
@@ -479,8 +479,8 @@ static bool need_charge_update(struct iopt_pages *pages)
{
switch (pages->account_mode) {
case IOPT_PAGES_ACCOUNT_NONE:
- return false;
case IOPT_PAGES_ACCOUNT_MM:
+ /* Both modes account in mm->pinned_vm. */
return pages->source_mm != current->mm;
case IOPT_PAGES_ACCOUNT_USER:
/*
--
2.43.7
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH 2/2] iommufd/selftest: Select IOMMU_IOPF
2026-11-30 11:32 [PATCH 1/2] iommufd: Move pinned_vm with the pages in IOMMU_IOAS_CHANGE_PROCESS Peng Hao
@ 2026-11-30 11:32 ` Peng Hao
0 siblings, 0 replies; 2+ messages in thread
From: Peng Hao @ 2026-11-30 11:32 UTC (permalink / raw)
To: jgg, kevin.tian; +Cc: iommu
The mock device supports I/O page faults, and the selftests attach it
to hw_pagetables allocated with IOMMU_HWPT_FAULT_ID_VALID. That needs a
mock iopf queue, which iommufd_test_init() gets from iopf_queue_alloc().
IOMMU_IOPF is a hidden symbol that only real IOMMU drivers select, so
IOMMUFD_TEST can be enabled without it, e.g. on arm64 without
ARM_SMMU_V3_SVA. Then iopf_queue_alloc() is the stub that returns NULL,
mock_dev_enable_iopf() fails with -ENODEV, and every test that attaches
the mock device to a fault-capable hwpt fails:
iommufd.c:697:alloc_hwpt_nested:Expected 0 (0) == _test_cmd_mock_domain_replace(self->fd, self->stdev_id, iopf_hwpt_id, NULL) (-1)
iommufd.c:2946:viommu_alloc_nested_iopf:Expected 0 (0) == _test_cmd_mock_domain_replace(self->fd, self->stdev_id, iopf_hwpt_id, NULL) (-1)
iommufd.c:3589:pasid_attach:Expected 0 (0) == _test_cmd_pasid_attach(self->fd, self->stdev_id, pasid, iopf_hwpt_id) (-1)
Select IOMMU_IOPF, like DMA_SHARED_BUFFER is selected for the dmabuf
tests.
Fixes: ddee19971081 ("iommufd/selftest: Add IOPF support for mock device")
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
drivers/iommu/iommufd/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iommu/iommufd/Kconfig b/drivers/iommu/iommufd/Kconfig
index 6c3bea83631b..29273d696dbb 100644
--- a/drivers/iommu/iommufd/Kconfig
+++ b/drivers/iommu/iommufd/Kconfig
@@ -56,6 +56,7 @@ config IOMMUFD_TEST
depends on IOMMU_PT_AMDV1=y || IOMMUFD=IOMMU_PT_AMDV1
select DMA_SHARED_BUFFER
select IOMMUFD_DRIVER
+ select IOMMU_IOPF
default n
help
This is dangerous, do not enable unless running
--
2.43.7
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 11:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 11:32 [PATCH 1/2] iommufd: Move pinned_vm with the pages in IOMMU_IOAS_CHANGE_PROCESS Peng Hao
2026-11-30 11:32 ` [PATCH 2/2] iommufd/selftest: Select IOMMU_IOPF Peng Hao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.