public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex@shazbot.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: David Matlack <dmatlack@google.com>, Alex Mastro <amastro@fb.com>,
	Shuah Khan <shuah@kernel.org>, Peter Xu <peterx@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] vfio: selftests: Add vfio_dma_mapping_mmio_test
Date: Fri, 9 Jan 2026 14:38:30 -0700	[thread overview]
Message-ID: <20260109143830.176dc279@shazbot.org> (raw)
In-Reply-To: <20260109180153.GI545276@ziepe.ca>

On Fri, 9 Jan 2026 14:01:53 -0400
Jason Gunthorpe <jgg@ziepe.ca> wrote:

> On Fri, Jan 09, 2026 at 09:04:30AM -0800, David Matlack wrote:
> > > If you really want to test TYPE1 you need to test what makes it
> > > unique, which is that you can map any VMA and then unmap any slice of
> > > it. Including within what should otherwise be a 1G page.
> > >
> > > But I doubt anyone cares enough to fix this, so just exclude
> > > VFIO_TYPE1_IOMMU from this test?  
> > 
> > Ah, ok, thanks for the explanation. So VFIO_TYPE1_IOMMU should always
> > use 4K mappings regardless of backend (VFIO or iommufd) so that unmap
> > can work as intended.  
> 
> IDK, I think you should just ignore testing TYPE1v0. The actual real
> semantics that it had are quite confusing and iommufd provides an
> emulation that is going to be functionally OK (indeed, functionally
> more capable) but is not the exactly the same.
> 
> The old comment here is sort of enlightening:
> 
> +        * vfio-iommu-type1 (v1) - User mappings were coalesced together to
> +        * avoid tracking individual mappings.  This means that the granularity
> +        * of the original mapping was lost and the user was allowed to attempt
> +        * to unmap any range.  Depending on the contiguousness of physical
> +        * memory and page sizes supported by the IOMMU, arbitrary unmaps may
> +        * or may not have worked.  We only guaranteed unmap granularity
> +        * matching the original mapping; even though it was untracked here,
> +        * the original mappings are reflected in IOMMU mappings.  This
> +        * resulted in a couple unusual behaviors.  First, if a range is not
> +        * able to be unmapped, ex. a set of 4k pages that was mapped as a
> +        * 2M hugepage into the IOMMU, the unmap ioctl returns success but with
> +        * a zero sized unmap.  Also, if an unmap request overlaps the first
> +        * address of a hugepage, the IOMMU will unmap the entire hugepage.
> +        * This also returns success and the returned unmap size reflects the
> +        * actual size unmapped.
> 
> iommufd does not try to do this "returned unmap size reflects the
> actual size unmapped" part, it always unmaps exactly what was
> requested, because it disables huge pages.

I think there was also some splitting code in the IOMMU drivers that
has since been removed that may have made the v1 interface slightly
more sane.  It certainly never restricted mappings to PAGE_SIZE in
order to allow arbitrary unmaps, it relied on users to do sane things
and examine the results.  Those "sane things" sort of became the v2
interface.

In any case, we've had v2 for a long time and if IOMMUFD compat make v1
more bloated and slow such that users realize they're using an old,
crappy interface, that's probably for the best.  Examining what page
size is used for v1 is probably not worthwhile though.  Thanks,

Alex

  reply	other threads:[~2026-01-09 21:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 22:13 [PATCH] vfio: selftests: Add vfio_dma_mapping_mmio_test Alex Mastro
2026-01-07 22:37 ` Alex Mastro
2026-01-07 23:54 ` David Matlack
2026-01-08  0:54   ` Jason Gunthorpe
2026-01-08  2:41     ` Alex Mastro
2026-01-08 14:10       ` Jason Gunthorpe
2026-01-08 15:45         ` Alex Williamson
2026-01-08 18:24           ` David Matlack
2026-01-08 18:33             ` Jason Gunthorpe
2026-01-08 21:29               ` David Matlack
2026-01-09  0:36                 ` Jason Gunthorpe
2026-01-09  0:43                   ` David Matlack
2026-01-09  0:54                     ` Jason Gunthorpe
2026-01-09 17:04                       ` David Matlack
2026-01-09 18:01                         ` Jason Gunthorpe
2026-01-09 21:38                           ` Alex Williamson [this message]
2026-01-13 23:47                             ` David Matlack
2026-01-08  3:36   ` Alex Mastro
2026-01-08 14:38     ` Jason Gunthorpe
2026-01-08 16:25       ` Alex Mastro
2026-01-08 23:04         ` Alex Mastro
2026-01-08 15:42     ` Alex Williamson
2026-01-08 18:20       ` 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=20260109143830.176dc279@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=peterx@redhat.com \
    --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