Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vfio: selftests: Add DMA mapping tests for 2M and 1G HugeTLB

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>
Link: https://lore.kernel.org/r/20250822212518.4156428-8-dmatlack@google.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Josh Hilke and committed by
Alex Williamson
751f6b5d a0fd0af5

+33 -5
+33 -5
tools/testing/selftests/vfio/vfio_dma_mapping_test.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - #include <fcntl.h> 3 - 2 + #include <stdio.h> 4 3 #include <sys/mman.h> 4 + #include <unistd.h> 5 5 6 + #include <linux/limits.h> 7 + #include <linux/mman.h> 6 8 #include <linux/sizes.h> 7 9 #include <linux/vfio.h> 8 10 ··· 16 14 17 15 FIXTURE(vfio_dma_mapping_test) { 18 16 struct vfio_pci_device *device; 17 + }; 18 + 19 + FIXTURE_VARIANT(vfio_dma_mapping_test) { 20 + u64 size; 21 + int mmap_flags; 22 + }; 23 + 24 + FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, anonymous) { 25 + .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE, 26 + }; 27 + 28 + FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, anonymous_hugetlb_2mb) { 29 + .size = SZ_2M, 30 + .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_2MB, 31 + }; 32 + 33 + FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, anonymous_hugetlb_1gb) { 34 + .size = SZ_1G, 35 + .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_1GB, 19 36 }; 20 37 21 38 FIXTURE_SETUP(vfio_dma_mapping_test) ··· 49 28 50 29 TEST_F(vfio_dma_mapping_test, dma_map_unmap) 51 30 { 52 - const u64 size = SZ_2M; 31 + const u64 size = variant->size ?: getpagesize(); 32 + const int flags = variant->mmap_flags; 53 33 void *mem; 54 34 u64 iova; 55 35 56 - mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); 57 - ASSERT_NE(mem, MAP_FAILED); 36 + mem = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); 37 + 38 + /* Skip the test if there aren't enough HugeTLB pages available. */ 39 + if (flags & MAP_HUGETLB && mem == MAP_FAILED) 40 + SKIP(return, "mmap() failed: %s (%d)\n", strerror(errno), errno); 41 + else 42 + ASSERT_NE(mem, MAP_FAILED); 58 43 59 44 iova = (u64)mem; 60 45 61 46 vfio_pci_dma_map(self->device, iova, size, mem); 62 47 printf("Mapped HVA %p (size 0x%lx) at IOVA 0x%lx\n", mem, size, iova); 48 + 63 49 vfio_pci_dma_unmap(self->device, iova, size); 64 50 65 51 ASSERT_TRUE(!munmap(mem, size));