All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Mahmoud Nagy Adam <mngyadam@amazon.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Kumar, Praveen" <pravkmr@amazon.de>,
	"Woodhouse, David" <dwmw@amazon.co.uk>,
	"nagy@khwaternagy.com" <nagy@khwaternagy.com>
Subject: Re: [RFC PATCH 0/9] vfio: Introduce mmap maple tree
Date: Thu, 14 Aug 2025 11:52:47 -0600	[thread overview]
Message-ID: <20250814115247.4458764a.alex.williamson@redhat.com> (raw)
In-Reply-To: <lrkyq349uut66.fsf_-_@dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com>

On Thu, 14 Aug 2025 11:52:17 +0200
Mahmoud Nagy Adam <mngyadam@amazon.de> wrote:

> The last email was a draft sent by mistake. This is the full version.
> 
> Alex Williamson <alex.williamson@redhat.com> writes:
> 
> > Currently we have a struct vfio_pci_region stored in an array that we
> > dynamically resize for device specific regions and the offset is
> > determined statically from the array index.  We could easily specify an
> > offset and alias field on that object if we wanted to make the address
> > space more compact (without a maple tree) and facilitate multiple
> > regions referencing the same device resource.  This is all just
> > implementation decisions.  We also don't need to support read/write on
> > new regions, we could have them exist advertising only mmap support via
> > REGION_INFO, which simplifies and is consistent with the existing API.
> >  
> 
> What I understand is that you’re proposing an API to create a new
> region.  The user would then fetch a new index and use it with
> REGION_INFO to obtain the pgoff.  This feels like adding another layer
> on top of the pgoff, while the end goal remains the same.
> 
> I'm not sure an alias region offers more value than simply creating an
> alias pgoff.  It may even be more confusing, since—AFAIU—users expect
> indexes to align with PCI BAR indexes in the PCI case.  We would also
> need either a new API or an additional REGION_INFO member to tell the
> user which index the alias refers to and what extra attributes it has.
> 
> Ultimately, both approaches are very similar: one creates a full alias
> region, the other just a pgoff alias, but both would require nearly the
> same internal implementation for pgoff handling.
> 
> The key question is: does a full region alias provide any tangible
> benefits over a pgoff alias?
> 
> In my opinion, it’s clearer to simply have the user call e.g
> REQUEST_REGION_MMAP (which returns a pgoff for mmap) rather than request
> full region creation.

In part this is the argument we've already discussed, creating a new
region and then getting REGION_INFO adds a step for the user, but we
already have REGION_INFO as the standard mechanism for introspection of
regions.  We also have capabilities available as a mechanism within the
REGION_INFO ioctl to describe the mapping flags or region alias
relationship.

If we're this concerned about one additional step for the user, design
the DEVICE_FEATURE ioctl to return both the new region index and the
file offset, the user can ignore the region index if they choose.

To me, regions are just segments of the device fd address space,
regions have a unique offset.  Regions have a vfio-pci specific
convention where a fixed set of region indexes refer to fixed device
resources but never is there a statement in the uAPI that region 0
_uniquely_ indexes BAR 0 and there will never be another region index
mapping this device resource.  The convention exists only to bootstrap
standard device resources.  Adding a mechanism to get a file offset
which is an alias of a region, but not itself reported as a region is
to me, splitting up the device fd address space into two different
allocation methods.

The argument that userspace drivers will get confused if region N
aliases region 0 makes no sense to me.  The user has actively brought
region N into existence knowing in advance that it's addressing the
same device resource as region 0.  Exactly in the same way they'd know
the file offset they get back from REQUEST_REGION_MMAP is an alias to
the requested region.  BUT, since we're invoking a new region, we have
mechanisms to allow persistent introspection of that new region.

The tangible benefit to me is that a new region better aligns with the
existing API and has that introspection/debug'ability aspect, versus
creating an alternate mechanism for making allocations from the device
fd address space.  Thanks,

Alex


  reply	other threads:[~2025-08-14 17:52 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 10:39 [RFC PATCH 0/9] vfio: Introduce mmap maple tree Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 1/9] vfio: add mmap maple tree to vfio Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 2/9] vfio: add transient ops to support vfio mmap mt Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 3/9] vfio-pci-core: rename vm operations Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 4/9] vfio-pci-core: remove redundant offset calculations Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 5/9] vfio-pci-core: add vfio_pci_mmap & helpers Mahmoud Adam
2025-08-04 10:39 ` [RFC PATCH 6/9] vfio-pci-core: support the new vfio ops Mahmoud Adam
2025-08-04 10:40 ` [RFC PATCH 7/9] vfio-pci: use " Mahmoud Adam
2025-08-04 10:40 ` [RFC PATCH 8/9] vfio: UAPI for setting mmap attributes Mahmoud Adam
2025-08-04 10:40 ` [RFC PATCH 9/9] vfio_pci_core: support mmap attrs uapi & WC Mahmoud Adam
2025-08-04 18:49 ` [RFC PATCH 0/9] vfio: Introduce mmap maple tree Alex Williamson
2025-08-04 20:09   ` Mahmoud Nagy Adam
2025-08-05 14:31     ` Jason Gunthorpe
2025-08-05 15:48       ` Mahmoud Nagy Adam
2025-08-05 18:50         ` [RFC " Jason Gunthorpe
2025-08-05 19:00         ` Alex Williamson
     [not found]           ` <80dc87730f694b2d6e6aabbd29df49cf3c7c44fb.camel@amazon.com>
     [not found]             ` <20250806115224.GB377696@ziepe.ca>
2025-08-07  8:12               ` Herrenschmidt, Benjamin
2025-08-07 19:06                 ` Alex Williamson
2025-08-11 15:55                   ` Jason Gunthorpe
2025-08-11 22:07                     ` Alex Williamson
2025-08-12  0:30                       ` Jason Gunthorpe
2025-08-12 19:26                         ` Alex Williamson
2025-08-13  0:17                           ` Jason Gunthorpe
2025-08-14  8:39                       ` Mahmoud Nagy Adam
2025-08-14  9:52                       ` Mahmoud Nagy Adam
2025-08-14 17:52                         ` Alex Williamson [this message]
2025-08-28  8:53                           ` Mahmoud Nagy Adam
2025-08-28 19:17                             ` Alex Williamson
2025-08-07  8:13               ` Benjamin Herrenschmidt

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=20250814115247.4458764a.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=benh@kernel.crashing.org \
    --cc=dwmw@amazon.co.uk \
    --cc=jgg@ziepe.ca \
    --cc=kvm@vger.kernel.org \
    --cc=mngyadam@amazon.de \
    --cc=nagy@khwaternagy.com \
    --cc=pravkmr@amazon.de \
    /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.