mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fred Griffoul <griffoul@gmail.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>
Cc: Robin Murphy <robin.murphy@arm.com>,
	Shuah Khan <shuah@kernel.org>,
	Mostafa Saleh <smostafa@google.com>,
	Guanghui Feng <guanghuifeng@linux.alibaba.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, nh-open-source@amazon.com
Subject: [PATCH 0/3] iommupt: Unmap and return the PFNs in one walk
Date: Wed, 11 Nov 2026 18:59:28 +0000	[thread overview]
Message-ID: <20261111185931.94882-1-griffoul@gmail.com> (raw)

From: Fred Griffoul <fgriffo@amazon.co.uk>

When iommufd unmaps an area, it must unpin the user pages, but it keeps
no list of their PFNs. It reads each one back from the IOMMU domain
with iommu_iova_to_phys(), one CPU page at a time, then walks the page
table again in iommu_unmap(). With 4 KiB pages, a 1 GiB IOPTE costs
262144 lookups before the unmap starts.

This series lets the iommupt unmap walk report the physical range of
each IOPTE as it removes it, so iommufd unmaps and collects the PFNs
in one walk. The walk also steps over holes, where iommu_unmap() stops
at the first one.

Patch 1 adds iommu_unmap_sparse(), patch 2 uses it in
iopt_area_unpin_domain(), and patch 3 adds a selftest for the areas
that keep the per-page read-back.

An earlier series [1] proposed iova_to_phys_length() so that iommufd
can read the PFNs back one IOPTE at a time instead of one page at a
time. The unmap is still a second walk there. This series collects
the PFNs in the unmap walk itself.

The series applies to iommu/next. I wrote parts of the code and the
changelogs with Kiro, an AI coding assistant using Claude models, and
used it to run the tests. I reviewed and tested all of it.

[1] https://lore.kernel.org/linux-iommu/20260603151804.1963871-1-guanghuifeng@linux.alibaba.com/

Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>

Fred Griffoul (3):
  iommupt: Add iommu_unmap_sparse()
  iommufd: Use iommu_unmap_sparse() to unpin domain pages
  iommufd/selftest: Unmap areas that start inside a CPU page

 drivers/iommu/generic_pt/iommu_pt.h       |  61 ++++++++-
 drivers/iommu/generic_pt/kunit_iommu_pt.h | 144 ++++++++++++++++++++++
 drivers/iommu/iommu-debug-pagealloc.c     |  13 ++
 drivers/iommu/iommu-priv.h                |  24 ++++
 drivers/iommu/iommu.c                     |  76 ++++++++++++
 drivers/iommu/iommufd/pages.c             |  98 ++++++++++++++-
 include/linux/generic_pt/iommu.h          |  24 ++++
 include/linux/iommu.h                     |  22 ++++
 tools/testing/selftests/iommu/iommufd.c   |  30 +++++
 9 files changed, 486 insertions(+), 6 deletions(-)


base-commit: 2cf4be57b301ed2d7af82e70cff5dfd96894d8de
-- 
2.47.3


             reply	other threads:[~2026-11-11 18:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 18:59 Fred Griffoul [this message]
2026-11-11 18:59 ` [PATCH 1/3] iommupt: Add iommu_unmap_sparse() Fred Griffoul
2026-11-11 18:59 ` [PATCH 2/3] iommufd: Use iommu_unmap_sparse() to unpin domain pages Fred Griffoul
2026-11-11 18:59 ` [PATCH 3/3] iommufd/selftest: Unmap areas that start inside a CPU page Fred Griffoul

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=20261111185931.94882-1-griffoul@gmail.com \
    --to=griffoul@gmail.com \
    --cc=guanghuifeng@linux.alibaba.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=nh-open-source@amazon.com \
    --cc=robin.murphy@arm.com \
    --cc=shuah@kernel.org \
    --cc=smostafa@google.com \
    --cc=will@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®