public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Alex Mastro <amastro@fb.com>
Cc: Alex Williamson <alex@shazbot.org>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Alejandro Jimenez <alejandro.j.jimenez@oracle.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 4/5] vfio: selftests: update DMA map/unmap helpers to support more test kinds
Date: Mon, 27 Oct 2025 23:37:10 +0000	[thread overview]
Message-ID: <aQACJucKne4DRv06@google.com> (raw)
In-Reply-To: <20251027-fix-unmap-v5-4-4f0fcf8ffb7d@fb.com>

On 2025-10-27 10:33 AM, Alex Mastro wrote:
> Add __vfio_pci_dma_* helpers which return -errno from the underlying
> ioctls.
> 
> Add __vfio_pci_dma_unmap_all to test more unmapping code paths. Add an
> out unmapped arg to report the unmapped byte size.

nit: Please append () to function names in commit messages and comments
(e.g. "Add __vfio_pci_dma_unmap_all() to test ..."). It helps make it
obvious you are referring to a function.

> The existing vfio_pci_dma_* functions, which are intended for happy-path
> usage (assert on failure) are now thin wrappers on top of the
> double-underscore helpers.
> 
> Signed-off-by: Alex Mastro <amastro@fb.com>

Aside from the commit message and the braces nits,

  Reviewed-by: David Matlack <dmatlack@google.com>

> @@ -152,10 +153,13 @@ static void vfio_iommu_dma_map(struct vfio_pci_device *device,
>  		.size = region->size,
>  	};
>  
> -	ioctl_assert(device->container_fd, VFIO_IOMMU_MAP_DMA, &args);
> +	if (ioctl(device->container_fd, VFIO_IOMMU_MAP_DMA, &args))
> +		return -errno;

Interesting. I was imagining this would would return whatever ioctl()
returned and then the caller could check errno if it wanted to. But I
actually like this better, since it simplifies the assertions at the
caller (like in your next patch).

> +int __vfio_pci_dma_unmap_all(struct vfio_pci_device *device, u64 *unmapped)
> +{
> +	int ret;
> +	struct vfio_dma_region *curr, *next;
> +
> +	if (device->iommufd)
> +		ret = iommufd_dma_unmap(device->iommufd, 0, UINT64_MAX,
> +					device->ioas_id, unmapped);

This reminds me, I need to get rid of INVALID_IOVA in vfio_util.h.

__to_iova() can just return int for success/error and pass the iova up
to the caller via parameter.

> +	else
> +		ret = vfio_iommu_dma_unmap(device->container_fd, 0, 0,
> +					   VFIO_DMA_UNMAP_FLAG_ALL, unmapped);
> +
> +	if (ret)
> +		return ret;
> +
> +	list_for_each_entry_safe(curr, next, &device->dma_regions, link) {
> +		list_del_init(&curr->link);
> +	}

nit: No need for {} for single-line loop.

  reply	other threads:[~2025-10-27 23:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27 17:33 [PATCH v5 0/5] vfio: handle DMA map/unmap up to the addressable limit Alex Mastro
2025-10-27 17:33 ` [PATCH v5 1/5] vfio/type1: sanitize for overflow using check_*_overflow Alex Mastro
2025-10-27 17:33 ` [PATCH v5 2/5] vfio/type1: move iova increment to unmap_unpin_* caller Alex Mastro
2025-10-27 17:33 ` [PATCH v5 3/5] vfio/type1: handle DMA map/unmap up to the addressable limit Alex Mastro
2025-10-27 17:33 ` [PATCH v5 4/5] vfio: selftests: update DMA map/unmap helpers to support more test kinds Alex Mastro
2025-10-27 23:37   ` David Matlack [this message]
2025-10-27 23:58     ` Alex Mastro
2025-10-27 17:33 ` [PATCH v5 5/5] vfio: selftests: add end of address space DMA map/unmap tests Alex Mastro
2025-10-27 23:45   ` 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=aQACJucKne4DRv06@google.com \
    --to=dmatlack@google.com \
    --cc=alejandro.j.jimenez@oracle.com \
    --cc=alex@shazbot.org \
    --cc=amastro@fb.com \
    --cc=jgg@ziepe.ca \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.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