All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: David Hildenbrand <david@redhat.com>
Cc: Peter Xu <peterx@redhat.com>, Jinjiang Tu <tujinjiang@huawei.com>,
	akpm@linux-foundation.org, lorenzo.stoakes@oracle.com,
	Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org,
	surenb@google.com, mhocko@suse.com, linux-mm@kvack.org,
	wangkefeng.wang@huawei.com
Subject: Re: [PATCH] mm: fix COW mapping handing in generic_access_phys
Date: Wed, 28 May 2025 15:29:36 -0300	[thread overview]
Message-ID: <20250528182936.GB192531@nvidia.com> (raw)
In-Reply-To: <331096ae-e648-4a6e-8728-5cc0bf319b3b@redhat.com>

On Wed, May 28, 2025 at 08:22:08PM +0200, David Hildenbrand wrote:
> On 28.05.25 20:15, Jason Gunthorpe wrote:
> > On Wed, May 28, 2025 at 08:00:34PM +0200, David Hildenbrand wrote:
> > 
> > > Having refcounted anon page in a VM_PFNMAP doesn't suddenly turn the whole
> > > thing into a MIXEDMAP where other things with a "struct page" are suddenly
> > > refcounted as well.
> > 
> > The special COW rules for PFNMAP require a single linear mapping so
> > that vma->vm_pgoff can encode the "special" range.
> 
> Yes, I have a semi-ugly patch to adjust remove that special casing.
> 
> (less ugly than current handling: *still* lookup the struct page, and if it
> references an anonymous folio, we ... have an anonymous folio. Because
> nobody should ever,ever,ever PFNMAP an anonymous folio. Ever.)

Hmm, maybe so.

> In remap_pfn_range_internal() we sanity-check that right now. And fail if it
> is not in place.
> 
> Any COW VM_PFNMAP that doesn't go through remap_pfn_range() would be ...
> broken. I don't think we have them.

It is a really easy driver mistake to make though, you have to omit
the rejection of !VM_SHARED, then go on and do something else.

How many drivers use VM_PFNMAP without remap_pfn_range() and don't
check for VM_SHARED?

From a driver perspective it would be much easier to understand if the
driver could just tell the core code what functions it wants to use

if (vma_prepare(vma, USE_REMAP_PFN_RANGE |
                USE_IO_REMAP_PFN_RANGE |
                USE_VMF_INSERT_PAGE |
                USE_VMF_INSERT_IO_PFN |
                [.. etc ..]))

Then the above would set the VM flags properly and fail in cases that
are wrong. Like you can't do USE_VMF_INSERT_IO_PFN without VM_SHARED.

No more messes of drivers doing random and confusing mixtures of
VM_XX.

So much easier to audit if the drivers are doing the right stuff
because we just check what mm functions they call against the bit mask
they provide. A debug kernel could enforce the check.

Then we can say with clarity that VM_XX flags are used with various
insertion functions exclusively and know alot better what it is they
mean.

Jason


  reply	other threads:[~2025-05-28 18:29 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-28  1:56 [PATCH] mm: fix COW mapping handing in generic_access_phys Jinjiang Tu
2025-05-28  8:59 ` David Hildenbrand
2025-05-28  9:59   ` David Hildenbrand
2025-05-28 12:14     ` Jinjiang Tu
2025-05-28 14:54     ` Peter Xu
2025-05-28 15:02       ` David Hildenbrand
2025-05-28 15:25         ` Peter Xu
2025-05-28 15:29           ` David Hildenbrand
2025-05-28 16:06             ` Peter Xu
2025-05-28 16:29               ` Jason Gunthorpe
2025-05-28 17:14                 ` Peter Xu
2025-05-28 17:34                   ` Jason Gunthorpe
2025-05-28 17:37                   ` David Hildenbrand
2025-05-28 17:32                 ` David Hildenbrand
2025-05-28 17:47                   ` Jason Gunthorpe
2025-05-28 17:59                     ` Jason Gunthorpe
2025-05-28 18:03                       ` David Hildenbrand
2025-05-28 18:00                     ` David Hildenbrand
2025-05-28 18:15                       ` Jason Gunthorpe
2025-05-28 18:22                         ` David Hildenbrand
2025-05-28 18:29                           ` Jason Gunthorpe [this message]
2025-05-30 10:04                             ` David Hildenbrand
2025-05-28 12:13   ` Jinjiang Tu

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=20250528182936.GB192531@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=tujinjiang@huawei.com \
    --cc=vbabka@suse.cz \
    --cc=wangkefeng.wang@huawei.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.