linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: kvm@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Nico Pache <npache@redhat.com>,
	Zi Yan <ziy@nvidia.com>, Alex Mastro <amastro@fb.com>,
	David Hildenbrand <david@redhat.com>,
	Alex Williamson <alex@shazbot.org>, Zhi Wang <zhiw@nvidia.com>,
	David Laight <david.laight.linux@gmail.com>,
	Yi Liu <yi.l.liu@intel.com>, Ankit Agrawal <ankita@nvidia.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v2 2/4] mm: Add file_operations.get_mapping_order()
Date: Tue, 16 Dec 2025 14:44:29 -0500	[thread overview]
Message-ID: <aUG2ne_zMyR0eCLX@x1.local> (raw)
In-Reply-To: <20251216185850.GH6079@nvidia.com>

On Tue, Dec 16, 2025 at 02:58:50PM -0400, Jason Gunthorpe wrote:
> On Tue, Dec 16, 2025 at 12:36:13PM -0500, Peter Xu wrote:
> > On Tue, Dec 16, 2025 at 01:19:44PM -0400, Jason Gunthorpe wrote:
> > > On Tue, Dec 16, 2025 at 10:42:39AM -0500, Peter Xu wrote:
> > > > Also see __thp_get_unmapped_area() processed such pgoff, it allocates VA
> > > > with len_pad (not len), and pad the retval at last.
> > > > 
> > > > Please let me know if it didn't work like it, then it might be a bug.
> > > 
> > > It should all be documented then in the kdoc for the new ops, in this
> > > kind of language that the resulting VA flows from pgoff
> > 
> > IMHO that's one of the major benefits of this API, so that there's no need
> > to mention impl details like this.
> 
> It needs to be clearly explained exactly how pgoff and the returned
> order are related because it impacts how the drivers need to manage
> their pgoff space.

Here "pgoff" plays two roles:

  (1) as a range, (pgoff, len) on top of the fd, decides which device blob
      to be mapped.  This is relevant to the driver, for sure..

  (2) as an offset, pgoff is relevant when we want to make sure mmap()
      request's VA will be aligned in a way so that we can maximize huge
      mappings.  This has, IMHO, nothing to do with the driver, and that's
      what I want to make the new API transparent of.

I agree drivers need to know pgoff for (1) in terms of get_mapping_order(),
not (2).

> 
> > Here the point is, the driver should only care about the size of mapping,
> > nothing else like how exactly the alignments will be calculated, and how
> > that interacts with pgoff.  The kernel mm manages that. It's done exactly
> > like what anon thp does already when len is pmd aligned.
> 
> The driver owns the pgoff number space, it has to care about how that
> relates to the PTEs.
> 
> > Or maybe I misunderstood what you're suggesting to document?  If so, please
> > let me know; some example would be greatly helpful.
> 
> Just document the 'VA % order = pgoff % order' equation in the kdoc
> for the new op.

When it's "related to PTEs", it's talking about (2) above, so that's really
what I want to avoid mentioning.

Docuemnt anything about VA is just confusing on its own especially when
"int get_mapping_order(fd, pgoff, len)" doesn't even have anything in param
or retval that is relevant to the virtual address space..

If you think missing such info is harder for reviews, I can definitely add
a rich comment when repost explaining how __thp_get_unmapped_area() works
here.

We can also pause this a bit and wait for Matthew's review on the API,
where he showed concerns.  If there's major reason this API is rejected, we
don't need to bother this part of detail either.

Thanks,

-- 
Peter Xu



  reply	other threads:[~2025-12-16 19:44 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-04 15:09 [PATCH v2 0/4] mm/vfio: huge pfnmaps with !MAP_FIXED mappings Peter Xu
2025-12-04 15:10 ` [PATCH v2 1/4] mm/thp: Allow thp_get_unmapped_area_vmflags() to take alignment Peter Xu
2025-12-04 15:10 ` [PATCH v2 2/4] mm: Add file_operations.get_mapping_order() Peter Xu
2025-12-04 15:19   ` Peter Xu
2025-12-08  9:21     ` Matthew Wilcox
2025-12-10 20:24       ` Peter Xu
2025-12-07 16:21   ` Jason Gunthorpe
2025-12-10 20:23     ` Peter Xu
2025-12-16 14:44       ` Jason Gunthorpe
2025-12-16 15:42         ` Peter Xu
2025-12-16 17:19           ` Jason Gunthorpe
2025-12-16 17:36             ` Peter Xu
2025-12-16 18:58               ` Jason Gunthorpe
2025-12-16 19:44                 ` Peter Xu [this message]
2025-12-19 14:59                   ` Jason Gunthorpe
2025-12-19 15:13                     ` Peter Xu
2025-12-19 15:20                       ` Jason Gunthorpe
2025-12-19 15:53                         ` Peter Xu
2025-12-04 15:10 ` [PATCH v2 3/4] vfio: Introduce vfio_device_ops.get_mapping_order hook Peter Xu
2025-12-04 15:10 ` [PATCH v2 4/4] vfio-pci: Best-effort huge pfnmaps with !MAP_FIXED mappings Peter Xu
2025-12-05  4:33   ` kernel test robot
2025-12-05  7:45   ` kernel test robot
2025-12-07 16:26   ` Jason Gunthorpe
2025-12-10 20:43     ` Peter Xu
2025-12-16 14:42       ` Jason Gunthorpe
2025-12-16 16:01         ` Peter Xu
2025-12-16 19:01           ` Jason Gunthorpe
2025-12-16 19:58             ` Peter Xu
2025-12-08  3:11   ` Alex Mastro
2025-12-04 18:16 ` [PATCH v2 0/4] mm/vfio: " Cédric Le Goater
2025-12-07  9:13 ` Alex Mastro

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=aUG2ne_zMyR0eCLX@x1.local \
    --to=peterx@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@shazbot.org \
    --cc=amastro@fb.com \
    --cc=ankita@nvidia.com \
    --cc=david.laight.linux@gmail.com \
    --cc=david@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npache@redhat.com \
    --cc=yi.l.liu@intel.com \
    --cc=zhiw@nvidia.com \
    --cc=ziy@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox