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 3/6] selftests/vfio: add sPAPR TCE v2 DMA window helpers
Date: Mon, 6 Jul 2026 22:17:27 +0000	[thread overview]
Message-ID: <akwpd6TXTH_pIgKJ@google.com> (raw)
In-Reply-To: <20260703032806.40946-4-nnmlinux@linux.ibm.com>

On 2026-07-02 11:28 PM, Narayana Murty N wrote:
> Add helper support for sPAPR TCE v2 DMA windows in the VFIO selftest
> library.
> 
> Track the platform default DMA window separately from selftest-created
> dynamic DMA windows. The default window is discovered with
> VFIO_IOMMU_SPAPR_TCE_GET_INFO and is not removed during cleanup.
> 
> Add helpers to create and remove DDWs, return the active IOVA range, and
> register/unregister memory around DMA map/unmap operations. Window
> selection is done before IOVA allocation; the map path only validates,
> registers memory, and calls VFIO_IOMMU_MAP_DMA.
> 
> Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>

> +static int spapr_tce_read_default_window(struct iommu *iommu)

Please add vfio_iommu_*() prefix to these routines that wrap
VFIO_IOMMU_* ioctls.

e.g.

 spapr_tce_read_default_window() -> vfio_iommu_spapr_tce_get_default()
 spapr_tce_create_ddw()          -> vfio_iommu_spapr_tce_create_window()
 spapr_tce_remove_ddw()          -> vfio_iommu_spapr_tce_remove_window()
 spapr_register_memory()         -> vfio_iommu_spapr_register_memory()
 spapr_unregister_memory()       -> vfio_iommu_spapr_unregister_memory()

This helps with readability since it makes it clear these functions are
interacting with the VFIO IOMMU driver.

> +{
> +	struct vfio_iommu_spapr_tce_info info = {
> +		.argsz = sizeof(info),
> +	};
> +
> +	if (iommu->default_window.valid)
> +		return 0;
> +
> +	if (ioctl(iommu->container_fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, &info))
> +		return -errno;
> +
> +	iommu->default_window.start = info.dma32_window_start;
> +	iommu->default_window.size = info.dma32_window_size;
> +	iommu->default_window.page_shift = page_size_to_shift(getpagesize());
> +	iommu->default_window.valid = true;
> +	iommu->default_window.dynamic = false;
> +	iommu->default_window.remove_on_cleanup = false;
> +
> +	return 0;
> +}
> +
> +static int spapr_tce_create_ddw(struct iommu *iommu, u64 min_size, u32 page_shift)
> +{
> +	struct vfio_iommu_spapr_tce_create create = {
> +		.argsz = sizeof(create),
> +		.page_shift = page_shift,
> +		.levels = 1,
> +		.window_size = min_size,
> +	};
> +
> +	if (ioctl(iommu->container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create))
> +		return -errno;
> +
> +	iommu->ddw_window.start = create.start_addr;
> +	iommu->ddw_window.size = create.window_size;
> +	iommu->ddw_window.page_shift = page_shift;
> +	iommu->ddw_window.valid = true;
> +	iommu->ddw_window.dynamic = true;
> +	iommu->ddw_window.remove_on_cleanup = true;
> +
> +	return 0;
> +}
> +
> +static int spapr_tce_remove_window(struct iommu *iommu, struct spapr_tce_window *window)
> +{
> +	struct vfio_iommu_spapr_tce_remove remove = {
> +		.argsz = sizeof(remove),
> +		.start_addr = window->start,
> +	};
> +
> +	if (!window->valid || !window->remove_on_cleanup)
> +		return 0;
> +
> +	if (ioctl(iommu->container_fd, VFIO_IOMMU_SPAPR_TCE_REMOVE, &remove))
> +		return -errno;
> +
> +	window->valid = false;
> +	return 0;
> +}

  parent reply	other threads:[~2026-07-06 22:17 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 [this message]
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
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=akwpd6TXTH_pIgKJ@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.