vfio: selftests: update DMA mapping tests to use queried IOVA ranges
Subsystems (4)
v2 cover vfio: selftests: update DMA mapping tests to use queried IOVA ranges
Not all IOMMUs support the same virtual address width as the processor, for instance older Intel consumer platforms only support 39-bits of IOMMU address space. On such platforms, using the virtual address as the IOVA and mappings at the top of the address space both fail.
VFIO and IOMMUFD have facilities for retrieving valid IOVA ranges, VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE and IOMMU_IOAS_IOVA_RANGES, respectively. These provide compatible arrays of ranges from which we can construct a simple allocator and record the maximum supported IOVA address.
Use this new allocator in place of reusing the virtual address, and incorporate the maximum supported IOVA into the limit testing. This latter change doesn't test quite the same absolute end-of-address space behavior but still seems to have some value. Testing for overflow is skipped when a reduced address space is supported as the desired errno is not generated.
This series is based on Alex Williamson's "Incorporate IOVA range info"
[1] along with feedback from the discussion in David Matlack's "Skip vfio_dma_map_limit_test if mapping returns -EINVAL" [2].
Given David's plans to split IOMMU concerns from devices as described in [3], this series' home for struct iova_allocator and IOVA range helpers are likely to be short lived, since they reside in vfio_pci_device.c. I assume that the rework can move this functionality to a more appropriate location next to other IOMMU-focused code, once such a place exists.
[1] https://lore.kernel.org/all/[email protected]/#t
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
To: Alex Williamson <[email protected]>
To: David Matlack <[email protected]>
To: Shuah Khan <[email protected]>
To: Jason Gunthorpe <[email protected]>
Changes in v2:
- Fix various nits
- calloc() where appropriate
- Update overflow test to run regardless of iova range constraints
- Change iova_allocator_init() to return an allocated struct
- Unfold iova_allocator_alloc()
- Fix iova allocator initial state bug
- Update vfio_pci_driver_test to use iova allocator
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Alex Mastro (4):
vfio: selftests: add iova range query helpers
vfio: selftests: fix map limit tests to use last available iova
vfio: selftests: add iova allocator
vfio: selftests: replace iova=vaddr with allocated iovas
.../testing/selftests/vfio/lib/include/vfio_util.h | 19 +- tools/testing/selftests/vfio/lib/vfio_pci_device.c | 241 ++++++++++++++++++++- .../testing/selftests/vfio/vfio_dma_mapping_test.c | 20 +- .../testing/selftests/vfio/vfio_pci_driver_test.c | 12 +- 4 files changed, 283 insertions(+), 9 deletions(-)
---
base-commit: 0ed3a30fd996cb0cac872432cf25185fda7e5316
change-id: 20251110-iova-ranges-1c09549fbf63
Best regards,
Signature · 1 line
Alex Mastro <[email protected]>
PATCH v2 1/4 vfio: selftests: add iova range query helpers
VFIO selftests need to map IOVAs from legally accessible ranges, which could vary between hardware. Tests in vfio_dma_mapping_test.c are making excessively strong assumptions about which IOVAs can be mapped.
Add vfio_iommu_iova_ranges(), which queries IOVA ranges from the IOMMUFD or VFIO container associated with the device. The queried ranges are normalized to IOMMUFD's iommu_iova_range representation so that handling of IOVA ranges up the stack can be implementation-agnostic. iommu_iova_range and vfio_iova_range are equivalent, so bias to using the new interface's struct.
Query IOMMUFD's ranges with IOMMU_IOAS_IOVA_RANGES. Query VFIO container's ranges with VFIO_IOMMU_GET_INFO and VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE.
The underlying vfio_iommu_type1_info buffer-related functionality has been kept generic so the same helpers can be used to query other capability chain information, if needed.
--- .../testing/selftests/vfio/lib/include/vfio_util.h | 8 +- tools/testing/selftests/vfio/lib/vfio_pci_device.c | 167 +++++++++++++++++++++ 2 files changed, 174 insertions(+), 1 deletion(-)
tools/testing/selftests/vfio/lib/include/vfio_util.h +7 -1
@@ -4,9 +4,12 @@#include <fcntl.h> #include <string.h> -#include <linux/vfio.h> + +#include <uapi/linux/types.h> +#include <linux/iommufd.h> #include <linux/list.h> #include <linux/pci_regs.h> +#include <linux/vfio.h> #include "../../../kselftest.h"
@@ -206,6 +209,9 @@ struct vfio_pci_device *vfio_pci_device_init(const char *bdf, const char *iommu_void vfio_pci_device_cleanup (struct vfio_pci_device *device);void vfio_pci_device_reset (struct vfio_pci_device *device); +struct iommu_iova_range *vfio_pci_iova_ranges (struct vfio_pci_device *device, +u32 *nranges); +int __vfio_pci_dma_map (struct vfio_pci_device *device,struct vfio_dma_region *region); int __vfio_pci_dma_unmap(struct vfio_pci_device *device,
tools/testing/selftests/vfio/lib/vfio_pci_device.c +167 -0
173 lines not on this page · raw message
Signature · 1 line
2.47.3
Alex Williamson
maintainerRe: [PATCH v2 1/4] vfio: selftests: add iova range query helpers
Quoted 13 lines · On Tue, 11 Nov 2025 06:52:02 -0800 Alex Mastro <[email protected]> wrote:
tools/testing/selftests/vfio/lib/vfio_pci_device.c +5
-0@@ -29,6 +29,173 @@ VFIO_ASSERT_EQ(__ret, 0, "ioctl(%s, %s, %s) returned %d\n", #_fd, #_op, #_arg, __ret); \ }while (0 ) +static struct vfio_info_cap_header *next_cap_hdr(void *buf, size_t bufsz, +size_t *cap_offset) +{ +struct vfio_info_cap_header *hdr; +
tools/testing/selftests/vfio/lib/vfio_pci_device.c line 46
Quoted 10 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c +10
-0+if (!*cap_offset) +return NULL ; + +VFIO_ASSERT_LT (*cap_offset, bufsz); +VFIO_ASSERT_GE (bufsz - *cap_offset,sizeof (*hdr)); + + hdr = (struct vfio_info_cap_header *)((u8 *)buf + *cap_offset); + +if (hdr->next) +VFIO_ASSERT_GT (hdr->next, *cap_offset);
This might be implementation, but I don't think it's a requirement. The vfio capability chains are based on PCI capabilities, which have no ordering requirement. Thanks,
Alex
Quoted 5 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c +5
-0+ + *cap_offset = hdr->next; + +return hdr; +}
Re: [PATCH v2 1/4] vfio: selftests: add iova range query helpers
Quoted 21 lines · Alex Williamson
Quoted 19 lines · On Tue, 11 Nov 2025 06:52:02 -0800 Alex Mastro <[email protected]> wrote:
tools/testing/selftests/vfio/lib/vfio_pci_device.c +11
-0@@ -29,6 +29,173 @@ VFIO_ASSERT_EQ(__ret, 0, "ioctl(%s, %s, %s) returned %d\n", #_fd, #_op, #_arg, __ret); \ }while (0 ) +static struct vfio_info_cap_header *next_cap_hdr(void *buf, size_t bufsz, +size_t *cap_offset) +{ +struct vfio_info_cap_header *hdr; + +if (!*cap_offset) +return NULL ; + +VFIO_ASSERT_LT (*cap_offset, bufsz); +VFIO_ASSERT_GE (bufsz - *cap_offset,sizeof (*hdr)); +
Quoted 8 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c line 46
Quoted 4 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c +4
-0+ hdr = (struct vfio_info_cap_header *)((u8 *)buf + *cap_offset); + +if (hdr->next) +VFIO_ASSERT_GT (hdr->next, *cap_offset);This might be implementation, but I don't think it's a requirement. The vfio capability chains are based on PCI capabilities, which have no ordering requirement. Thanks,
My main interest was to enforce that the chain doesn't contain a cycle, and checking for monotonically increasing cap offset was the simplest way I could think of to guarantee such.
If there isn't such a check, and kernel vends a malformed cycle-containing chain, chain traversal would infinite loop.
Given the location of this test code coupled to the kernel tree, do you think such assumptions about implementation still reach too far? If yes, I can either remove this check, or try to make cycle detection more relaxed about offsets potentially going backwards.
Quoted 7 lines
Alex
Quoted 5 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c +5
-0+ + *cap_offset = hdr->next; + +return hdr; +}
Alex Williamson
maintainerRe: [PATCH v2 1/4] vfio: selftests: add iova range query helpers
Quoted 35 lines · On Tue, 11 Nov 2025 09:35:31 -0800 Alex Mastro <[email protected]> wrote:
Quoted 21 lines · Alex Williamson
Quoted 19 lines · On Tue, 11 Nov 2025 06:52:02 -0800 Alex Mastro <[email protected]> wrote:
tools/testing/selftests/vfio/lib/vfio_pci_device.c +11
-0@@ -29,6 +29,173 @@ VFIO_ASSERT_EQ(__ret, 0, "ioctl(%s, %s, %s) returned %d\n", #_fd, #_op, #_arg, __ret); \ }while (0 ) +static struct vfio_info_cap_header *next_cap_hdr(void *buf, size_t bufsz, +size_t *cap_offset) +{ +struct vfio_info_cap_header *hdr; + +if (!*cap_offset) +return NULL ; + +VFIO_ASSERT_LT (*cap_offset, bufsz); +VFIO_ASSERT_GE (bufsz - *cap_offset,sizeof (*hdr)); +Quoted 8 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c line 46
Quoted 4 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c +4
-0+ hdr = (struct vfio_info_cap_header *)((u8 *)buf + *cap_offset); + +if (hdr->next) +VFIO_ASSERT_GT (hdr->next, *cap_offset);This might be implementation, but I don't think it's a requirement. The vfio capability chains are based on PCI capabilities, which have no ordering requirement. Thanks,
My main interest was to enforce that the chain doesn't contain a cycle, and checking for monotonically increasing cap offset was the simplest way I could think of to guarantee such.
Quoted 7 lines
If there isn't such a check, and kernel vends a malformed cycle-containing chain, chain traversal would infinite loop.
Given the location of this test code coupled to the kernel tree, do you think such assumptions about implementation still reach too far? If yes, I can either remove this check, or try to make cycle detection more relaxed about offsets potentially going backwards.
I've seen cycle detection in PCI config space implemented as just a depth/ttl counter. Max cycles is roughly (buffer-size/header-size). I think that would be sufficient if we want to include that sanity testing. Thanks,
Alex
Re: [PATCH v2 1/4] vfio: selftests: add iova range query helpers
Quoted 46 lines · Alex Williamson
Quoted 35 lines · On Tue, 11 Nov 2025 09:35:31 -0800 Alex Mastro <[email protected]> wrote:
Quoted 21 lines · Alex Williamson
Quoted 19 lines · On Tue, 11 Nov 2025 06:52:02 -0800 Alex Mastro <[email protected]> wrote:
tools/testing/selftests/vfio/lib/vfio_pci_device.c +11
-0@@ -29,6 +29,173 @@ VFIO_ASSERT_EQ(__ret, 0, "ioctl(%s, %s, %s) returned %d\n", #_fd, #_op, #_arg, __ret); \ }while (0 ) +static struct vfio_info_cap_header *next_cap_hdr(void *buf, size_t bufsz, +size_t *cap_offset) +{ +struct vfio_info_cap_header *hdr; + +if (!*cap_offset) +return NULL ; + +VFIO_ASSERT_LT (*cap_offset, bufsz); +VFIO_ASSERT_GE (bufsz - *cap_offset,sizeof (*hdr)); +Quoted 8 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c line 46
Quoted 4 lines
tools/testing/selftests/vfio/lib/vfio_pci_device.c +4
-0+ hdr = (struct vfio_info_cap_header *)((u8 *)buf + *cap_offset); + +if (hdr->next) +VFIO_ASSERT_GT (hdr->next, *cap_offset);This might be implementation, but I don't think it's a requirement. The vfio capability chains are based on PCI capabilities, which have no ordering requirement. Thanks,
My main interest was to enforce that the chain doesn't contain a cycle, and checking for monotonically increasing cap offset was the simplest way I could think of to guarantee such.
Quoted 7 lines
If there isn't such a check, and kernel vends a malformed cycle-containing chain, chain traversal would infinite loop.
Given the location of this test code coupled to the kernel tree, do you think such assumptions about implementation still reach too far? If yes, I can either remove this check, or try to make cycle detection more relaxed about offsets potentially going backwards.
Quoted 4 lines
I've seen cycle detection in PCI config space implemented as just a depth/ttl counter. Max cycles is roughly (buffer-size/header-size). I think that would be sufficient if we want to include that sanity testing. Thanks,
Thanks, that's a good suggestion -- will take this in v3.
Quoted 2 lines
Alex
PATCH v2 2/4 vfio: selftests: fix map limit tests to use last available iova
In reply to Alex MastroUse the newly available vfio_pci_iova_ranges() to determine the last legal IOVA, and use this as the basis for vfio_dma_map_limit_test tests.
--- tools/testing/selftests/vfio/vfio_dma_mapping_test.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
tools/testing/selftests/vfio/vfio_dma_mapping_test.c +13 -2
@@ -3,6 +3,8 @@#include <sys/mman.h> #include <unistd.h> +#include <uapi/linux/types.h> +#include <linux/iommufd.h> #include <linux/limits.h> #include <linux/mman.h> #include <linux/sizes.h>
@@ -219,7 +221,10 @@ FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES();FIXTURE_SETUP (vfio_dma_map_limit_test) {struct vfio_dma_region *region = &self->region; +struct iommu_iova_range *ranges;u64 region_size =getpagesize (); +iova_t last_iova; +u32 nranges;/* * Over-allocate mmap by double the size to provide enough backing vaddr
@@ -232,8 +237,13 @@ FIXTURE_SETUP(vfio_dma_map_limit_test) MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);ASSERT_NE (region->vaddr,MAP_FAILED ); -/* One page prior to the end of address space */ - region->iova = ~(iova_t )0 & ~(region_size -1 ); + ranges =vfio_pci_iova_ranges (self->device, &nranges); +VFIO_ASSERT_NOT_NULL (ranges); + last_iova = ranges[nranges -1 ].last; +free (ranges); + +/* One page prior to the last iova */ + region->iova = last_iova & ~(region_size -1 ); region->size = region_size; }
@@ -276,6 +286,7 @@ TEST_F(vfio_dma_map_limit_test, overflow)struct vfio_dma_region *region = &self->region;int rc; + region->iova = ~(iova_t )0 & ~(region->size -1 ); region->size = self->mmap_size; rc =__vfio_pci_dma_map (self->device, region);
Signature · 1 line
2.47.3
PATCH v2 3/4 vfio: selftests: add iova allocator
In reply to Alex MastroAdd struct iova_allocator, which gives tests a convenient way to generate legally-accessible IOVAs to map. This allocator traverses the sorted available IOVA ranges linearly, requires power-of-two size allocations, and does not support freeing iova allocations. The assumption is that tests are not IOVA space-bounded, and will not need to recycle IOVAs.
This is based on Alex Williamson's patch series for adding an IOVA allocator [1].
[1] https://lore.kernel.org/all/[email protected]/
---
The unfolded code uses David's range_offset suggestion because it makes assignment of the updated state simpler when crossing a range boundary.
No more ALIGN(). The insight is that the initial check for sufficient space (pre-alignment) requires computing
last = iova + size - 1
which is already half of what ALIGN() does. Just masking is left.
---
--- .../testing/selftests/vfio/lib/include/vfio_util.h | 11 ++++ tools/testing/selftests/vfio/lib/vfio_pci_device.c | 74 +++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-)
tools/testing/selftests/vfio/lib/include/vfio_util.h +11 -0
@@ -188,6 +188,13 @@ struct vfio_pci_device {struct vfio_pci_driver driver; }; +struct iova_allocator { +struct iommu_iova_range *ranges; +u32 nranges; +u32 range_idx; +u64 range_offset; +}; +/* * Return the BDF string of the device that the test should use. *
@@ -212,6 +219,10 @@ void vfio_pci_device_reset(struct vfio_pci_device *device);struct iommu_iova_range *vfio_pci_iova_ranges (struct vfio_pci_device *device,u32 *nranges); +struct iova_allocator *iova_allocator_init (struct vfio_pci_device *device); +void iova_allocator_cleanup (struct iova_allocator *allocator); +iova_t iova_allocator_alloc (struct iova_allocator *allocator,size_t size); +int __vfio_pci_dma_map (struct vfio_pci_device *device,struct vfio_dma_region *region); int __vfio_pci_dma_unmap(struct vfio_pci_device *device,
tools/testing/selftests/vfio/lib/vfio_pci_device.c +73 -1
90 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v2 4/4 vfio: selftests: replace iova=vaddr with allocated iovas
In reply to Alex Mastrovfio_dma_mapping_test and vfio_pci_driver_test currently use iova=vaddr as part of DMA mapping operations. The assumption that these IOVAs are legal has held up on all the hardware we've tested so far, but is not guaranteed. Make the tests more robust by using iova_allocator to vend IOVAs, which queries legally accessible IOVAs from the underlying IOMMUFD or VFIO container.
--- tools/testing/selftests/vfio/vfio_dma_mapping_test.c | 5 ++++- tools/testing/selftests/vfio/vfio_pci_driver_test.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-)
tools/testing/selftests/vfio/vfio_dma_mapping_test.c +4 -1
@@ -95,6 +95,7 @@ static int iommu_mapping_get(const char *bdf, u64 iova,FIXTURE (vfio_dma_mapping_test) {struct vfio_pci_device *device; +struct iova_allocator *iova_allocator; };FIXTURE_VARIANT (vfio_dma_mapping_test) {
@@ -119,10 +120,12 @@ FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(anonymous_hugetlb_1gb, SZ_1G, MAP_HUGETLB |FIXTURE_SETUP (vfio_dma_mapping_test) { self->device =vfio_pci_device_init (device_bdf, variant->iommu_mode); + self->iova_allocator =iova_allocator_init (self->device); }FIXTURE_TEARDOWN (vfio_dma_mapping_test) { +iova_allocator_cleanup (self->iova_allocator);vfio_pci_device_cleanup (self->device); }
@@ -144,7 +147,7 @@ TEST_F(vfio_dma_mapping_test, dma_map_unmap)else ASSERT_NE (region.vaddr,MAP_FAILED ); - region.iova = (u64 )region.vaddr; + region.iova =iova_allocator_alloc (self->iova_allocator, size); region.size = size;vfio_pci_dma_map (self->device, ®ion);
tools/testing/selftests/vfio/vfio_pci_driver_test.c +8 -4
@@ -19,6 +19,7 @@ static const char *device_bdf; }while (0 ) static void region_setup(struct vfio_pci_device *device, +struct iova_allocator *iova_allocator,struct vfio_dma_region *region,u64 size) {const int flags =MAP_SHARED |MAP_ANONYMOUS ;
@@ -29,7 +30,7 @@ static void region_setup(struct vfio_pci_device *device,VFIO_ASSERT_NE (vaddr,MAP_FAILED ); region->vaddr = vaddr; - region->iova = (u64 )vaddr; + region->iova =iova_allocator_alloc (iova_allocator, size); region->size = size;vfio_pci_dma_map (device, region);
@@ -44,6 +45,7 @@ static void region_teardown(struct vfio_pci_device *device,FIXTURE (vfio_pci_driver_test) {struct vfio_pci_device *device; +struct iova_allocator *iova_allocator;struct vfio_dma_region memcpy_region;void *vaddr;int msi_fd;
@@ -72,14 +74,15 @@ FIXTURE_SETUP(vfio_pci_driver_test)struct vfio_pci_driver *driver; self->device =vfio_pci_device_init (device_bdf, variant->iommu_mode); + self->iova_allocator =iova_allocator_init (self->device); driver = &self->device->driver; -region_setup (self->device, &self->memcpy_region,SZ_1G ); -region_setup (self->device, &driver->region,SZ_2M ); +region_setup (self->device, self->iova_allocator, &self->memcpy_region,SZ_1G ); +region_setup (self->device, self->iova_allocator, &driver->region,SZ_2M );/* Any IOVA that doesn't overlap memcpy_region and driver->region. */ - self->unmapped_iova =8UL *SZ_1G ; + self->unmapped_iova =iova_allocator_alloc (self->iova_allocator,SZ_1G );vfio_pci_driver_init (self->device); self->msi_fd = self->device->msi_eventfds[driver->msi];
@@ -108,6 +111,7 @@ FIXTURE_TEARDOWN(vfio_pci_driver_test)region_teardown (self->device, &self->memcpy_region);region_teardown (self->device, &driver->region); +iova_allocator_cleanup (self->iova_allocator);vfio_pci_device_cleanup (self->device); }
Signature · 1 line
2.47.3
Alex Williamson
maintainerRe: [PATCH v2 4/4] vfio: selftests: replace iova=vaddr with allocated iovas
Quoted 6 lines · On Tue, 11 Nov 2025 06:52:05 -0800 Alex Mastro <[email protected]> wrote:
vfio_dma_mapping_testandvfio_pci_driver_testcurrently use iova=vaddr as part of DMA mapping operations. The assumption that these IOVAs are legal has held up on all the hardware we've tested so far, but is not guaranteed. Make the tests more robust by usingiova_allocatorto vend IOVAs, which queries legally accessible IOVAs from the underlying IOMMUFD or VFIO container.
I've reported hardware that it doesn't work on, QEMU emulates such hardware. The commit message suggests this is more of a theoretical problem. Thanks,
Alex
Re: [PATCH v2 4/4] vfio: selftests: replace iova=vaddr with allocated iovas
Quoted 10 lines · Alex Williamson
Quoted 6 lines · On Tue, 11 Nov 2025 06:52:05 -0800 Alex Mastro <[email protected]> wrote:
vfio_dma_mapping_testandvfio_pci_driver_testcurrently use iova=vaddr as part of DMA mapping operations. The assumption that these IOVAs are legal has held up on all the hardware we've tested so far, but is not guaranteed. Make the tests more robust by usingiova_allocatorto vend IOVAs, which queries legally accessible IOVAs from the underlying IOMMUFD or VFIO container.
Quoted 3 lines
I've reported hardware that it doesn't work on, QEMU emulates such hardware. The commit message suggests this is more of a theoretical problem. Thanks,
Agree that it's misleading. I'll update the commit message to describe the things you described earlier.
Alex Williamson
maintainerQuoted 42 lines · On Tue, 11 Nov 2025 06:52:01 -0800 Alex Mastro <[email protected]> wrote:
Not all IOMMUs support the same virtual address width as the processor, for instance older Intel consumer platforms only support 39-bits of IOMMU address space. On such platforms, using the virtual address as the IOVA and mappings at the top of the address space both fail.
VFIO and IOMMUFD have facilities for retrieving valid IOVA ranges,
VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGEandIOMMU_IOAS_IOVA_RANGES, respectively. These provide compatible arrays of ranges from which we can construct a simple allocator and record the maximum supported IOVA address.Use this new allocator in place of reusing the virtual address, and incorporate the maximum supported IOVA into the limit testing. This latter change doesn't test quite the same absolute end-of-address space behavior but still seems to have some value. Testing for overflow is skipped when a reduced address space is supported as the desired errno is not generated.
This series is based on Alex Williamson's "Incorporate IOVA range info"
[1] along with feedback from the discussion in David Matlack's "Skipvfio_dma_map_limit_testif mapping returns-EINVAL" [2].Given David's plans to split IOMMU concerns from devices as described in [3], this series' home for
struct iova_allocatorand IOVA range helpers are likely to be short lived, since they reside invfio_pci_device.c. I assume that the rework can move this functionality to a more appropriate location next to other IOMMU-focused code, once such a place exists.[1] https://lore.kernel.org/all/[email protected]/#t
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/To: Alex Williamson <[email protected]>
To: David Matlack <[email protected]>
To: Shuah Khan <[email protected]>
To: Jason Gunthorpe <[email protected]>Signed-off-by Alex Mastro <[email protected]>
Quoted 9 lines
Changes in v2:
- Fix various nits
-calloc()where appropriate
- Update overflow test to run regardless of iova range constraints
- Changeiova_allocator_init()to return an allocated struct
- Unfoldiova_allocator_alloc()
- Fix iova allocator initial state bug
- Updatevfio_pci_driver_testto use iova allocator
- Link to v1: https://lore.kernel.org/r/[email protected]
Minor comments, but otherwise LGTM and passes testing on a Kaby Lake system with limited IOMMU address width. Thanks,
Alex
Quoted 33 lines · Alex Mastro
Not all IOMMUs support the same virtual address width as the processor, for instance older Intel consumer platforms only support 39-bits of IOMMU address space. On such platforms, using the virtual address as the IOVA and mappings at the top of the address space both fail.
VFIO and IOMMUFD have facilities for retrieving valid IOVA ranges,
VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGEandIOMMU_IOAS_IOVA_RANGES, respectively. These provide compatible arrays of ranges from which we can construct a simple allocator and record the maximum supported IOVA address.Use this new allocator in place of reusing the virtual address, and incorporate the maximum supported IOVA into the limit testing. This latter change doesn't test quite the same absolute end-of-address space behavior but still seems to have some value. Testing for overflow is skipped when a reduced address space is supported as the desired errno is not generated.
This series is based on Alex Williamson's "Incorporate IOVA range info"
[1] along with feedback from the discussion in David Matlack's "Skipvfio_dma_map_limit_testif mapping returns-EINVAL" [2].Given David's plans to split IOMMU concerns from devices as described in [3], this series' home for
struct iova_allocatorand IOVA range helpers are likely to be short lived, since they reside invfio_pci_device.c. I assume that the rework can move this functionality to a more appropriate location next to other IOMMU-focused code, once such a place exists.[1] https://lore.kernel.org/all/[email protected]/#t
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
To: Alex Williamson <[email protected]>
To: David Matlack <[email protected]>
To: Shuah Khan <[email protected]>
To: Jason Gunthorpe <[email protected]>Signed-off-by Alex Mastro <[email protected]>
LGTM. And I confirmed this fixes vfio_dma_mapping_test on HW that does not support IOVA 0xffffffffffffffff. Thanks!
Quoted 43 lines · David Matlack
Quoted 33 lines · Alex Mastro
Not all IOMMUs support the same virtual address width as the processor, for instance older Intel consumer platforms only support 39-bits of IOMMU address space. On such platforms, using the virtual address as the IOVA and mappings at the top of the address space both fail.
VFIO and IOMMUFD have facilities for retrieving valid IOVA ranges,
VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGEandIOMMU_IOAS_IOVA_RANGES, respectively. These provide compatible arrays of ranges from which we can construct a simple allocator and record the maximum supported IOVA address.Use this new allocator in place of reusing the virtual address, and incorporate the maximum supported IOVA into the limit testing. This latter change doesn't test quite the same absolute end-of-address space behavior but still seems to have some value. Testing for overflow is skipped when a reduced address space is supported as the desired errno is not generated.
This series is based on Alex Williamson's "Incorporate IOVA range info"
[1] along with feedback from the discussion in David Matlack's "Skipvfio_dma_map_limit_testif mapping returns-EINVAL" [2].Given David's plans to split IOMMU concerns from devices as described in [3], this series' home for
struct iova_allocatorand IOVA range helpers are likely to be short lived, since they reside invfio_pci_device.c. I assume that the rework can move this functionality to a more appropriate location next to other IOMMU-focused code, once such a place exists.[1] https://lore.kernel.org/all/[email protected]/#t
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/Quoted 8 lines
To: Alex Williamson <[email protected]>
To: David Matlack <[email protected]>
To: Shuah Khan <[email protected]>
To: Jason Gunthorpe <[email protected]>Signed-off-by Alex Mastro <[email protected]>
Quoted 5 lines
LGTM. And I confirmed this fixes
vfio_dma_mapping_teston HW that does not support IOVA0xffffffffffffffff. Thanks!Reviewed-by David Matlack <[email protected]>Tested-by David Matlack <[email protected]>
Thanks David!