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 3/3] iommufd/selftest: Unmap areas that start inside a CPU page
Date: Wed, 11 Nov 2026 18:59:31 +0000	[thread overview]
Message-ID: <20261111185931.94882-4-griffoul@gmail.com> (raw)
In-Reply-To: <20261111185931.94882-1-griffoul@gmail.com>

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

On iommupt domains, iopt_area_unpin_domain() unmaps and collects PFNs
in one walk, which needs IOPTEs that line up with CPU pages. The mock
domain maps 2 KiB per IOPTE, so IOMMU_IOAS_MAP_FIXED_IOVA can place a
user address with a 2 KiB offset at a CPU page aligned IOVA. Such an
area must take the per-page read-back instead, or one of its pages
stays pinned.

Map a buffer at each MOCK_PAGE_SIZE offset in its first CPU page,
unmap it, and check that no page is left pinned.

Signed-off-by: Fred Griffoul <fgriffo@amazon.co.uk>
---
 tools/testing/selftests/iommu/iommufd.c | 30 +++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index ca2b35e9d443a..14c8a12a3bc17 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -1890,6 +1890,36 @@ TEST_F(iommufd_mock_domain, all_aligns)
 		close(mfd);
 }
 
+/*
+ * Map memory that starts inside a CPU page at a CPU page aligned IOVA, which
+ * the mock domain's MOCK_PAGE_SIZE IOPTEs allow, then unmap it and check that
+ * every page is unpinned.
+ */
+TEST_F(iommufd_mock_domain, fixed_iova_offsets)
+{
+	size_t buf_size = self->mmap_buf_size;
+	size_t length = buf_size - PAGE_SIZE;
+	unsigned int start;
+	uint8_t *buf;
+
+	if (variant->file)
+		SKIP(return, "Skipping file variant, the test maps anonymous memory");
+
+	buf = mmap(0, buf_size, PROT_READ | PROT_WRITE, self->mmap_flags, -1,
+		   0);
+	ASSERT_NE(MAP_FAILED, buf);
+	check_refs(buf, buf_size, 0);
+
+	for (start = 0; start < PAGE_SIZE; start += MOCK_PAGE_SIZE) {
+		test_ioctl_ioas_map_fixed(buf + start, length,
+					  MOCK_APERTURE_START);
+		check_mock_iova(buf + start, MOCK_APERTURE_START, length);
+		test_ioctl_ioas_unmap(MOCK_APERTURE_START, length);
+		check_refs(buf, buf_size, 0);
+	}
+	ASSERT_EQ(0, munmap(buf, buf_size));
+}
+
 TEST_F(iommufd_mock_domain, all_aligns_copy)
 {
 	size_t test_step = variant->hugepages ? self->mmap_buf_size / 16 :
-- 
2.47.3


      parent 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 [PATCH 0/3] iommupt: Unmap and return the PFNs in one walk Fred Griffoul
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 ` Fred Griffoul [this message]

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-4-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®