From: Yi Lai <yi1.lai@intel.com>
To: yi1.lai@intel.com, Alex Williamson <alex@shazbot.org>,
David Matlack <dmatlack@google.com>,
Shuah Khan <shuah@kernel.org>,
Baolu Lu <baolu.lu@linux.intel.com>,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] vfio: selftests: Align __iommu_unmap() check with iommufd compat mode
Date: Fri, 20 Mar 2026 12:03:22 +0800 [thread overview]
Message-ID: <20260320040322.487429-3-yi1.lai@intel.com> (raw)
In-Reply-To: <20260320040322.487429-1-yi1.lai@intel.com>
When __iommu_map() fails (as expected for MMIO in iommufd modes), the
test proceeds to call __iommu_unmap() for cleanup.
The behavior of unmapping a non-existent range differs between iommufd
native and compat modes:
- Native iommufd returns -ENOENT (failure).
- Compat iommufd returns 0 (success), mimicking legacy VFIO behavior.
The previous code asserted that __iommu_unmap() always fails, which
caused test failures in compat mode. Fix this by checking the return
value based on the iommufd mode.
Signed-off-by: Yi Lai <yi1.lai@intel.com>
---
.../testing/selftests/vfio/vfio_dma_mapping_mmio_test.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
index 4f7ecdca0215..e6a2b2ff91f0 100644
--- a/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
+++ b/tools/testing/selftests/vfio/vfio_dma_mapping_mmio_test.c
@@ -101,7 +101,14 @@ static void do_mmio_map_test(struct iommu *iommu,
iommu_unmap(iommu, ®ion);
} else {
VFIO_ASSERT_NE(__iommu_map(iommu, ®ion), 0);
- VFIO_ASSERT_NE(__iommu_unmap(iommu, ®ion, NULL), 0);
+ /*
+ * Native IOMMUFD returns -ENOENT and Compat IOMMUFD returns 0
+ * for unmapping a non-existent range.
+ */
+ if (!strcmp(iommu->mode->name, MODE_IOMMUFD))
+ VFIO_ASSERT_NE(__iommu_unmap(iommu, ®ion, NULL), 0);
+ else
+ VFIO_ASSERT_EQ(__iommu_unmap(iommu, ®ion, NULL), 0);
}
}
--
2.43.0
next prev parent reply other threads:[~2026-03-20 4:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 4:03 [PATCH 0/2] vfio: selftests: Fix MMIO test failures in iommufd compat mode Yi Lai
2026-03-20 4:03 ` [PATCH 1/2] vfio: selftests: Fix iommufd compat mode __iommu_unmap() crash Yi Lai
2026-03-20 4:03 ` Yi Lai [this message]
2026-03-20 17:43 ` [PATCH 0/2] vfio: selftests: Fix MMIO test failures in iommufd compat mode David Matlack
2026-03-23 0:37 ` Lai, Yi
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=20260320040322.487429-3-yi1.lai@intel.com \
--to=yi1.lai@intel.com \
--cc=alex@shazbot.org \
--cc=baolu.lu@linux.intel.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@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