From: David Matlack <dmatlack@google.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Aaron Lewis <aaronlewis@google.com>,
Adhemerval Zanella <adhemerval.zanella@linaro.org>,
Adithya Jayachandran <ajayachandra@nvidia.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Dan Williams <dan.j.williams@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
David Matlack <dmatlack@google.com>,
dmaengine@vger.kernel.org, Jason Gunthorpe <jgg@nvidia.com>,
Joel Granados <joel.granados@kernel.org>,
Josh Hilke <jrhilke@google.com>,
Kevin Tian <kevin.tian@intel.com>,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Saeed Mahameed <saeedm@nvidia.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <shuah@kernel.org>,
Vinicius Costa Gomes <vinicius.gomes@intel.com>,
Vipin Sharma <vipinsh@google.com>,
"Yury Norov [NVIDIA]" <yury.norov@gmail.com>,
Shuah Khan <skhan@linuxfoundation.org>
Subject: [PATCH v2 07/30] vfio: selftests: Add DMA mapping tests for 2M and 1G HugeTLB
Date: Fri, 22 Aug 2025 21:24:54 +0000 [thread overview]
Message-ID: <20250822212518.4156428-8-dmatlack@google.com> (raw)
In-Reply-To: <20250822212518.4156428-1-dmatlack@google.com>
From: Josh Hilke <jrhilke@google.com>
Add test coverage of mapping 2M and 1G HugeTLB to vfio_dma_mapping_test
using a fixture variant. If there isn't enough HugeTLB memory available
for the test, just skip them.
Signed-off-by: Josh Hilke <jrhilke@google.com>
[switch from command line option to fixture variant]
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Matlack <dmatlack@google.com>
---
.../selftests/vfio/vfio_dma_mapping_test.c | 38 ++++++++++++++++---
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
index b56cebbf97eb..8f8e6e9e8197 100644
--- a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
+++ b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-only
-#include <fcntl.h>
-
+#include <stdio.h>
#include <sys/mman.h>
+#include <unistd.h>
+#include <linux/limits.h>
+#include <linux/mman.h>
#include <linux/sizes.h>
#include <linux/vfio.h>
@@ -16,6 +18,25 @@ FIXTURE(vfio_dma_mapping_test) {
struct vfio_pci_device *device;
};
+FIXTURE_VARIANT(vfio_dma_mapping_test) {
+ u64 size;
+ int mmap_flags;
+};
+
+FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, anonymous) {
+ .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE,
+};
+
+FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, anonymous_hugetlb_2mb) {
+ .size = SZ_2M,
+ .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_2MB,
+};
+
+FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, anonymous_hugetlb_1gb) {
+ .size = SZ_1G,
+ .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_1GB,
+};
+
FIXTURE_SETUP(vfio_dma_mapping_test)
{
self->device = vfio_pci_device_init(device_bdf, VFIO_TYPE1_IOMMU);
@@ -28,17 +49,24 @@ FIXTURE_TEARDOWN(vfio_dma_mapping_test)
TEST_F(vfio_dma_mapping_test, dma_map_unmap)
{
- const u64 size = SZ_2M;
+ const u64 size = variant->size ?: getpagesize();
+ const int flags = variant->mmap_flags;
void *mem;
u64 iova;
- mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- ASSERT_NE(mem, MAP_FAILED);
+ mem = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
+
+ /* Skip the test if there aren't enough HugeTLB pages available. */
+ if (flags & MAP_HUGETLB && mem == MAP_FAILED)
+ SKIP(return, "mmap() failed: %s (%d)\n", strerror(errno), errno);
+ else
+ ASSERT_NE(mem, MAP_FAILED);
iova = (u64)mem;
vfio_pci_dma_map(self->device, iova, size, mem);
printf("Mapped HVA %p (size 0x%lx) at IOVA 0x%lx\n", mem, size, iova);
+
vfio_pci_dma_unmap(self->device, iova, size);
ASSERT_TRUE(!munmap(mem, size));
--
2.51.0.rc2.233.g662b1ed5c5-goog
next prev parent reply other threads:[~2025-08-22 21:26 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 21:24 [PATCH v2 00/30] vfio: Introduce selftests for VFIO David Matlack
2025-08-22 21:24 ` [PATCH v2 01/30] selftests: Create tools/testing/selftests/vfio David Matlack
2025-08-22 21:24 ` [PATCH v2 02/30] vfio: selftests: Add a helper library for VFIO selftests David Matlack
2025-08-22 21:24 ` [PATCH v2 03/30] vfio: selftests: Introduce vfio_pci_device_test David Matlack
2025-08-22 21:24 ` [PATCH v2 04/30] vfio: selftests: Test basic VFIO and IOMMUFD integration David Matlack
2025-08-22 21:24 ` [PATCH v2 05/30] vfio: selftests: Move vfio dma mapping test to their own file David Matlack
2025-08-22 21:24 ` [PATCH v2 06/30] vfio: selftests: Add test to reset vfio device David Matlack
2025-08-22 21:24 ` David Matlack [this message]
2025-08-22 21:24 ` [PATCH v2 08/30] vfio: selftests: Validate 2M/1G HugeTLB are mapped as 2M/1G in IOMMU David Matlack
2025-08-22 21:24 ` [PATCH v2 09/30] vfio: selftests: Keep track of DMA regions mapped into the device David Matlack
2025-08-22 21:24 ` [PATCH v2 10/30] vfio: selftests: Enable asserting MSI eventfds not firing David Matlack
2025-08-22 21:24 ` [PATCH v2 11/30] vfio: selftests: Add a helper for matching vendor+device IDs David Matlack
2025-08-22 21:24 ` [PATCH v2 12/30] vfio: selftests: Add driver framework David Matlack
2025-08-22 21:25 ` [PATCH v2 13/30] vfio: sefltests: Add vfio_pci_driver_test David Matlack
2025-08-22 21:25 ` [PATCH v2 14/30] tools headers: Add stub definition for __iomem David Matlack
2025-08-22 21:25 ` [PATCH v2 15/30] tools headers: Import asm-generic MMIO helpers David Matlack
2025-08-22 21:25 ` [PATCH v2 16/30] tools headers: Import x86 MMIO helper overrides David Matlack
2025-08-22 21:25 ` [PATCH v2 17/30] tools headers: Add symlink to linux/pci_ids.h David Matlack
2025-08-22 21:25 ` [PATCH v2 18/30] dmaengine: ioat: Move system_has_dca_enabled() to dma.h David Matlack
2025-08-22 21:25 ` [PATCH v2 19/30] vfio: selftests: Add driver for Intel CBDMA David Matlack
2025-08-22 21:25 ` [PATCH v2 20/30] tools headers: Import iosubmit_cmds512() David Matlack
2025-08-22 21:25 ` [PATCH v2 21/30] dmaengine: idxd: Allow registers.h to be included from tools/ David Matlack
2025-08-22 21:25 ` [PATCH v2 22/30] vfio: selftests: Add driver for Intel DSA David Matlack
2025-08-22 21:25 ` [PATCH v2 23/30] vfio: selftests: Move helper to get cdev path to libvfio David Matlack
2025-08-22 21:25 ` [PATCH v2 24/30] vfio: selftests: Encapsulate IOMMU mode David Matlack
2025-08-22 21:25 ` [PATCH v2 25/30] vfio: selftests: Replicate tests across all iommu_modes David Matlack
2025-08-22 21:25 ` [PATCH v2 26/30] vfio: selftests: Add vfio_type1v2_mode David Matlack
2025-08-22 21:25 ` [PATCH v2 27/30] vfio: selftests: Add iommufd_compat_type1{,v2} modes David Matlack
2025-08-22 21:25 ` [PATCH v2 28/30] vfio: selftests: Add iommufd mode David Matlack
2025-08-22 21:25 ` [PATCH v2 29/30] vfio: selftests: Make iommufd the default iommu_mode David Matlack
2025-08-22 21:25 ` [PATCH v2 30/30] vfio: selftests: Add a script to help with running VFIO selftests David Matlack
2025-08-27 18:55 ` [PATCH v2 00/30] vfio: Introduce selftests for VFIO Alex Williamson
2025-08-27 20:20 ` David Matlack
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=20250822212518.4156428-8-dmatlack@google.com \
--to=dmatlack@google.com \
--cc=aaronlewis@google.com \
--cc=acme@redhat.com \
--cc=adhemerval.zanella@linaro.org \
--cc=ajayachandra@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=jgg@nvidia.com \
--cc=joel.granados@kernel.org \
--cc=jrhilke@google.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=pbonzini@redhat.com \
--cc=saeedm@nvidia.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=vinicius.gomes@intel.com \
--cc=vipinsh@google.com \
--cc=yury.norov@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).