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: Move vfio dma mapping test to their own file

Move the dma_map_unmap test from vfio_pci_device_test to a new test:
vfio_dma_mapping_test. We are going to add more complex dma mapping
tests, so it makes sense to separate this from the vfio pci device
test which is more of a sanity check for vfio pci functionality.

Signed-off-by: Josh Hilke <jrhilke@google.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20250822212518.4156428-6-dmatlack@google.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Josh Hilke and committed by
Alex Williamson
b477e7bc 790588f0

+52 -18
+1
tools/testing/selftests/vfio/Makefile
··· 1 1 CFLAGS = $(KHDR_INCLUDES) 2 + TEST_GEN_PROGS += vfio_dma_mapping_test 2 3 TEST_GEN_PROGS += vfio_iommufd_setup_test 3 4 TEST_GEN_PROGS += vfio_pci_device_test 4 5 include ../lib.mk
+51
tools/testing/selftests/vfio/vfio_dma_mapping_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + #include <fcntl.h> 3 + 4 + #include <sys/mman.h> 5 + 6 + #include <linux/sizes.h> 7 + #include <linux/vfio.h> 8 + 9 + #include <vfio_util.h> 10 + 11 + #include "../kselftest_harness.h" 12 + 13 + static const char *device_bdf; 14 + 15 + FIXTURE(vfio_dma_mapping_test) { 16 + struct vfio_pci_device *device; 17 + }; 18 + 19 + FIXTURE_SETUP(vfio_dma_mapping_test) 20 + { 21 + self->device = vfio_pci_device_init(device_bdf, VFIO_TYPE1_IOMMU); 22 + } 23 + 24 + FIXTURE_TEARDOWN(vfio_dma_mapping_test) 25 + { 26 + vfio_pci_device_cleanup(self->device); 27 + } 28 + 29 + TEST_F(vfio_dma_mapping_test, dma_map_unmap) 30 + { 31 + const u64 size = SZ_2M; 32 + void *mem; 33 + u64 iova; 34 + 35 + mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); 36 + ASSERT_NE(mem, MAP_FAILED); 37 + 38 + iova = (u64)mem; 39 + 40 + vfio_pci_dma_map(self->device, iova, size, mem); 41 + printf("Mapped HVA %p (size 0x%lx) at IOVA 0x%lx\n", mem, size, iova); 42 + vfio_pci_dma_unmap(self->device, iova, size); 43 + 44 + ASSERT_TRUE(!munmap(mem, size)); 45 + } 46 + 47 + int main(int argc, char *argv[]) 48 + { 49 + device_bdf = vfio_selftests_get_bdf(&argc, argv); 50 + return test_harness_run(argc, argv); 51 + }
-18
tools/testing/selftests/vfio/vfio_pci_device_test.c
··· 36 36 vfio_pci_device_cleanup(self->device); 37 37 } 38 38 39 - TEST_F(vfio_pci_device_test, dma_map_unmap) 40 - { 41 - const u64 size = SZ_2M; 42 - void *mem; 43 - u64 iova; 44 - 45 - mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); 46 - ASSERT_NE(mem, MAP_FAILED); 47 - 48 - iova = (u64)mem; 49 - 50 - vfio_pci_dma_map(self->device, iova, size, mem); 51 - printf("Mapped HVA %p (size 0x%lx) at IOVA 0x%lx\n", mem, size, iova); 52 - vfio_pci_dma_unmap(self->device, iova, size); 53 - 54 - ASSERT_TRUE(!munmap(mem, SZ_2M)); 55 - } 56 - 57 39 #define read_pci_id_from_sysfs(_file) ({ \ 58 40 char __sysfs_path[PATH_MAX]; \ 59 41 char __buf[32]; \