From: Peng Hao <flyingpenghao@gmail.com>
To: jgg@ziepe.ca, kevin.tian@intel.com
Cc: iommu@lists.linux.dev
Subject: [PATCH 1/2] iommufd: Move pinned_vm with the pages in IOMMU_IOAS_CHANGE_PROCESS
Date: Mon, 30 Nov 2026 19:32:31 +0800 [thread overview]
Message-ID: <20261130113232.10091-1-flyingpeng@tencent.com> (raw)
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
next reply other threads:[~2026-11-30 11:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 11:32 Peng Hao [this message]
2026-11-30 11:32 ` [PATCH 2/2] iommufd/selftest: Select IOMMU_IOPF Peng Hao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130113232.10091-1-flyingpeng@tencent.com \
--to=flyingpenghao@gmail.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.