linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Jason Gunthorpe <jgg@nvidia.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: Fri, 30 May 2025 12:04:53 +0200	[thread overview]
Message-ID: <a13eaaa6-2688-483f-97c2-8e5651ec660f@redhat.com> (raw)
In-Reply-To: <20250528182936.GB192531@nvidia.com>

On 28.05.25 20:29, Jason Gunthorpe wrote:
> 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.

I'll try to send out a prototype of that patch once I managed to ... finish
never ending stream of review :)

> 
>> 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.

As I just reviewed related code, I think when not using remap_pfn_range(), a
driver -- like vfio -- will be using vmf_insert_pfn().

There, we sanity check it as well:

vmf_insert_pfn()->vmf_insert_pfn_prot()

	BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags));

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

Not sure, only a handful even use vmf_insert_pfn(), and the BUG_ON would at
least catch it.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2025-05-30 10:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-28  1:56 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
2025-05-30 10:04                             ` David Hildenbrand [this message]
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=a13eaaa6-2688-483f-97c2-8e5651ec660f@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=jgg@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox