From: Alex Williamson <alex@shazbot.org>
To: Alex Mastro <amastro@fb.com>
Cc: David Matlack <dmatlack@google.com>,
Shuah Khan <shuah@kernel.org>, <kvm@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Jason Gunthorpe <jgg@ziepe.ca>
Subject: Re: [PATCH 2/4] vfio: selftests: fix map limit tests to use last available iova
Date: Mon, 10 Nov 2025 14:31:52 -0700 [thread overview]
Message-ID: <20251110143152.5af498f4.alex@shazbot.org> (raw)
In-Reply-To: <20251110-iova-ranges-v1-2-4d441cf5bf6d@fb.com>
On Mon, 10 Nov 2025 13:10:42 -0800
Alex Mastro <amastro@fb.com> wrote:
> Use 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.
>
> Fixes: de8d1f2fd5a5 ("vfio: selftests: add end of address space DMA map/unmap tests")
> Signed-off-by: Alex Mastro <amastro@fb.com>
> ---
> tools/testing/selftests/vfio/vfio_dma_mapping_test.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
> index 4f1ea79a200c..37c2a342df8d 100644
> --- a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
> +++ b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
> @@ -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;
> + size_t 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;
Building on the imposed requirement of ordered ranges. Thanks,
Alex
> + free(ranges);
> +
> + /* One page prior to the last iova */
> + region->iova = last_iova & ~(region_size - 1);
> region->size = region_size;
> }
>
> @@ -276,6 +286,9 @@ TEST_F(vfio_dma_map_limit_test, overflow)
> struct vfio_dma_region *region = &self->region;
> int rc;
>
> + if (region->iova != (~(iova_t)0 & ~(region->size - 1)))
> + SKIP(return, "IOMMU address space insufficient for overflow test");
> +
> region->size = self->mmap_size;
>
> rc = __vfio_pci_dma_map(self->device, region);
>
next prev parent reply other threads:[~2025-11-10 21:32 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 21:10 [PATCH 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges Alex Mastro
2025-11-10 21:10 ` [PATCH 1/4] vfio: selftests: add iova range query helpers Alex Mastro
2025-11-10 21:31 ` Alex Williamson
2025-11-10 22:35 ` Alex Mastro
2025-11-10 22:03 ` David Matlack
2025-11-10 22:32 ` Alex Mastro
2025-11-10 23:02 ` David Matlack
2025-11-10 23:08 ` Alex Mastro
2025-11-10 21:10 ` [PATCH 2/4] vfio: selftests: fix map limit tests to use last available iova Alex Mastro
2025-11-10 21:31 ` Alex Williamson [this message]
2025-11-10 22:38 ` Alex Mastro
2025-11-11 0:09 ` David Matlack
2025-11-10 21:10 ` [PATCH 3/4] vfio: selftests: add iova allocator Alex Mastro
2025-11-10 21:31 ` Alex Williamson
2025-11-10 22:37 ` Alex Mastro
2025-11-10 22:54 ` David Matlack
2025-11-10 23:14 ` Alex Mastro
2025-11-10 21:10 ` [PATCH 4/4] vfio: selftests: update vfio_dma_mapping_test to allocate iovas Alex Mastro
2025-11-10 21:31 ` Alex Williamson
2025-11-10 22:36 ` Alex Mastro
2025-11-10 23:06 ` [PATCH 0/4] vfio: selftests: update DMA mapping tests to use queried IOVA ranges 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=20251110143152.5af498f4.alex@shazbot.org \
--to=alex@shazbot.org \
--cc=amastro@fb.com \
--cc=dmatlack@google.com \
--cc=jgg@ziepe.ca \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/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