Re: [PATCH v4 06/10] vfio: selftests: Allow drivers to specify required region size

[email protected]
Newsgroups org.kernel.vger.kvm
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The DMA region sizes provided by the driver ops are not page-aligned, causing the IOMMU mapping ioctls to fail with -EINVAL and crashing the selftests.
--

--- Patch [6]: [PATCH v4 06/10] vfio: selftests: Allow drivers to specify required region size ---
commit 4f2bbead708ec429c301f599e1115b9b6e4e3c22
Author: Jason Gunthorpe <[email protected]>

vfio: selftests: Allow drivers to specify required region size

This patch adds a region_size field to struct vfio_pci_driver_ops, allowing
drivers to declare their needed DMA-mapped region size. It replaces the
hardcoded SZ_2M value with the exact sizes of the drivers' state structures.

> diff --git a/tools/testing/selftests/vfio/vfio_pci_driver_test.c b/tools/testing/selftests/vfio/vfio_pci_driver_test.c
> index 761bf117d624f..2bd949aafd731 100644
> --- a/tools/testing/selftests/vfio/vfio_pci_driver_test.c
> +++ b/tools/testing/selftests/vfio/vfio_pci_driver_test.c
[ ... ]
> @@ -87,7 +87,8 @@ FIXTURE_SETUP(vfio_pci_driver_test)
>  	driver = &self->device->driver;
>  
>  	region_setup(self->iommu, self->iova_allocator, &self->memcpy_region, SZ_1G);
> -	region_setup(self->iommu, self->iova_allocator, &driver->region, SZ_2M);
> +	region_setup(self->iommu, self->iova_allocator, &driver->region,
> +		     driver->region.size);

[Severity: Medium]
Since the drivers populate region_size with the exact struct size (such as
sizeof(struct dsa_state) or sizeof(struct igb)), will this cause IOMMU
mapping ioctls to fail?

IOMMU mapping ioctls generally require the requested DMA mapping length to be
an exact multiple of the minimum IOMMU page size. Passing this unaligned
size to region_setup() sets the region size to the unaligned value.

When iommu_map() later issues the VFIO_IOMMU_MAP_DMA or IOMMU_IOAS_MAP
ioctl, could the kernel reject the unaligned size with -EINVAL and crash
the test suite?

Does region_size need to be page-aligned before being used for DMA mappings?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.