All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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.