All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Narayana Murty N <nnmlinux@linux.ibm.com>
Cc: alex@shazbot.org, shuah@kernel.org, amastro@fb.com,
	rananta@google.com, kvm@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	vaibhav@linux.ibm.com, sbhat@linux.ibm.com,
	harshpb@linux.ibm.com
Subject: Re: [RFC PATCH 4/6] selftests/vfio: Exercise sPAPR DDW path for hugepage DMA mappings
Date: Mon, 6 Jul 2026 22:33:07 +0000	[thread overview]
Message-ID: <akwtI2ixuRBHYCyy@google.com> (raw)
In-Reply-To: <20260703032806.40946-5-nnmlinux@linux.ibm.com>

On 2026-07-02 11:28 PM, Narayana Murty N wrote:
> Prepare the DMA window before IOVA allocation in the DMA mapping tests.
> 
> Anonymous mappings use the default sPAPR DMA window. HugeTLB mappings force
> a DDW with the requested page size, allowing the test to exercise DDW
> creation, mapping, unmapping, and cleanup.
> 
> Skip gracefully when hugepage allocation fails or when the platform does
> not support the requested DDW characteristics. Also skip unmap-all when
> the backend cannot pair it with the sPAPR memory unregister flow.
> 
> Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
> ---
>  .../selftests/vfio/vfio_dma_mapping_test.c    | 22 +++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
> index 7d0de8c79de1..4411fdbd56da 100644
> --- a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
> +++ b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
> @@ -1,5 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0-only
>  #include <stdio.h>
> +#include <string.h>
>  #include <sys/mman.h>
>  #include <unistd.h>
>  
> @@ -119,8 +120,19 @@ FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(anonymous_hugetlb_1gb, SZ_1G, MAP_HUGETLB |
>  
>  FIXTURE_SETUP(vfio_dma_mapping_test)
>  {
> +	const u64 page_size = variant->size ?: getpagesize();
> +	const bool force_dynamic = !!variant->size;

This is kind of arbitrary right? Should we add explicit variants for
dynamic/default windows (see below). But we need some way to skip the dynamic
window tests on non-spapr iommus...

diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
index cd2d3276a46c..b54c529ebedb 100644
--- a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
+++ b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
@@ -103,15 +103,21 @@ FIXTURE_VARIANT(vfio_dma_mapping_test) {
        const char *iommu_mode;
        u64 size;
        int mmap_flags;
+       bool dynamic_window;
 };

-#define FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode, _name, _size, _mmap_flags) \
-FIXTURE_VARIANT_ADD(vfio_dma_mapping_test, _iommu_mode ## _ ## _name) {               \
-       .iommu_mode = #_iommu_mode,                                            \
-       .size = (_size),                                                       \
-       .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE | (_mmap_flags),             \
+#define __FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode, _name, _size, _mmap_flags, _dynamic_window) \
+FIXTURE_VARIANT_ADD(vfio_dma_mapping_test,_iommu_mode ## _ ## _name) {   \
+       .iommu_mode = #_iommu_mode,                                                               \
+       .size = (_size),                                                                          \
+       .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE | (_mmap_flags),                                \
+       .dynamic_window = _dynamic_window,                                                        \
 }

+#define FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode, _name, _size, _mmap_flags)  \
+__FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode, _name, _size, _mmap_flags, false); \
+__FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode, _name ## _dynamic_window, _size, _mmap_flags, true) \
+
 FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(anonymous, 0, 0);
 FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(anonymous_hugetlb_2mb, SZ_2M, MAP_HUGETLB | MAP_HUGE_2MB);
 FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(anonymous_hugetlb_1gb, SZ_1G, MAP_HUGETLB | MAP_HUGE_1GB);
@@ -121,14 +127,13 @@ FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(anonymous_hugetlb_1gb, SZ_1G, MAP_HUGETLB |
 FIXTURE_SETUP(vfio_dma_mapping_test)
 {
        const u64 page_size = variant->size ?: getpagesize();
-       const bool force_dynamic = !!variant->size;
        int ret;

        self->iommu = iommu_init(variant->iommu_mode);
        self->device = vfio_pci_device_init(device_bdf, self->iommu);

        ret = iommu_prepare_dma_window(self->iommu, page_size, page_size,
-                                      force_dynamic);
+                                      variant->dynamic_window);
        if (ret)
                SKIP(return, "DMA window unavailable: %s (%d)\n",
                     strerror(-ret), -ret);

> +	int ret;
> +
>  	self->iommu = iommu_init(variant->iommu_mode);
>  	self->device = vfio_pci_device_init(device_bdf, self->iommu);
> +
> +	ret = iommu_prepare_dma_window(self->iommu, page_size, page_size,
> +				       force_dynamic);
> +	if (ret)
> +		SKIP(return, "DMA window unavailable: %s (%d)\n",
> +		     strerror(-ret), -ret);
> +
>  	self->iova_allocator = iova_allocator_init(self->iommu);
>  }
>  
> @@ -227,6 +239,7 @@ FIXTURE_SETUP(vfio_dma_map_limit_test)
>  	u64 region_size = getpagesize();
>  	iova_t last_iova;
>  	u32 nranges;
> +	int ret;
>  
>  	/*
>  	 * Over-allocate mmap by double the size to provide enough backing vaddr
> @@ -236,6 +249,13 @@ FIXTURE_SETUP(vfio_dma_map_limit_test)
>  
>  	self->iommu = iommu_init(variant->iommu_mode);
>  	self->device = vfio_pci_device_init(device_bdf, self->iommu);
> +
> +	ret = iommu_prepare_dma_window(self->iommu, region_size, region_size,
> +				       false);
> +	if (ret)
> +		SKIP(return, "DMA window unavailable: %s (%d)\n",
> +		     strerror(-ret), -ret);
> +
>  	region->vaddr = mmap(NULL, self->mmap_size, PROT_READ | PROT_WRITE,
>  			     MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
>  	ASSERT_NE(region->vaddr, MAP_FAILED);
> @@ -277,6 +297,8 @@ TEST_F(vfio_dma_map_limit_test, unmap_all)
>  	u64 unmapped;
>  	int rc;
>  
> +	if (!iommu_supports_unmap_all(self->iommu))
> +		SKIP(return, "IOMMU backend does not support unmap-all\n");
>  	iommu_map(self->iommu, region);
>  	ASSERT_EQ(region->iova, to_iova(self->device, region->vaddr));
>  
> -- 
> 2.51.1
> 

  parent reply	other threads:[~2026-07-06 22:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03  3:28 [RFC PATCH 0/6] selftests/vfio: Add sPAPR TCE v2 coverage Narayana Murty N
2026-07-03  3:28 ` [RFC PATCH 1/6] selftests/vfio: allow selecting IOMMU backend from environment Narayana Murty N
2026-07-03  8:06   ` sashiko-bot
2026-07-06 21:49   ` David Matlack
2026-07-03  3:28 ` [RFC PATCH 2/6] selftests/vfio: add sPAPR TCE v2 IOMMU mode Narayana Murty N
2026-07-03  8:09   ` sashiko-bot
2026-07-03  3:28 ` [RFC PATCH 3/6] selftests/vfio: add sPAPR TCE v2 DMA window helpers Narayana Murty N
2026-07-03  8:05   ` sashiko-bot
2026-07-06 22:04   ` David Matlack
2026-07-06 22:17   ` David Matlack
2026-07-03  3:28 ` [RFC PATCH 4/6] selftests/vfio: Exercise sPAPR DDW path for hugepage DMA mappings Narayana Murty N
2026-07-03  8:11   ` sashiko-bot
2026-07-06 22:33   ` David Matlack [this message]
2026-07-06 22:41     ` David Matlack
2026-07-03  3:28 ` [RFC PATCH 5/6] selftests/vfio: Accept sPAPR errno for DMA range overflow Narayana Murty N
2026-07-03  8:08   ` sashiko-bot
2026-07-06 22:47   ` David Matlack
2026-07-03  3:28 ` [RFC PATCH 6/6] selftests/vfio: Enable VFIO selftests on ppc64 and ppc64le Narayana Murty N
2026-07-03  8:14   ` sashiko-bot
2026-07-03  8:28 ` [RFC PATCH 0/6] selftests/vfio: Add sPAPR TCE v2 coverage Harsh Prateek Bora
2026-07-06 22:55 ` 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=akwtI2ixuRBHYCyy@google.com \
    --to=dmatlack@google.com \
    --cc=alex@shazbot.org \
    --cc=amastro@fb.com \
    --cc=harshpb@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=nnmlinux@linux.ibm.com \
    --cc=rananta@google.com \
    --cc=sbhat@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=vaibhav@linux.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.