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: Wed, 28 May 2025 20:00:34 +0200 [thread overview]
Message-ID: <84a19161-765d-4aba-b42f-5fdd8c986bdf@redhat.com> (raw)
In-Reply-To: <20250528174754.GA61950@nvidia.com>
On 28.05.25 19:47, Jason Gunthorpe wrote:
> On Wed, May 28, 2025 at 07:32:59PM +0200, David Hildenbrand wrote:
>> On 28.05.25 18:29, Jason Gunthorpe wrote:
>>> On Wed, May 28, 2025 at 12:06:07PM -0400, Peter Xu wrote:
>>>> #define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
>>>>
>>>> I'm not confident to blame any driver yet to have those special cases for
>>>> VM_PFNMAP, because it only says "managed without struct page", it didn't
>>>> say "it must not contain struct page".. Hence it hints the core mm "please
>>>> do not manage these mappings with struct page at all". Still sounds fair
>>>> contract, even if not ideal.
>>>
>>> I think it is pretty clear, if a VMA has VM_PFNMAP then nothing must
>>> ever try to obtain a struct page from any PTEs in it, for any reason,
>>> even if things in it might have a struct page. In practice it means
>>> nothing can call vm_normal_page() on a VM_PFNMAP.
>>
>> No, not until we remove any COW mappings of VM_PFNMAP.
>
> I stand by the statement, the COW mapping thing is broken. Just
> because it is wrong doesn't mean it is allowed to call
> vm_normal_page() on VM_PFNMAP.
>
> It makes no sense at all to have VM_PFNMAP where someone has COW'd the
> pages and effectively turned it into a MIXEDMAP.
>
Well, not quite.
MIXEDMAP is clearly documented that whatever has a refcount (struct
page) is refcounted. That's not the case for PFNMAP, obviously, where
nothing is refcounted, except ... anon pages in COW mappings.
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.
> It should just be a MIXEDMAP at that point!!
>
> IMHO we should have the core code complain with a dmesg for
VM_PFNMAP> without VM_SHARED and get driver authors to fix it. Either
add the
> missed VM_SHARED or changed to MIXEDMAP. Make it WARN_ON in a few
> years.
>
> If they can't follow the rules required to use MIXEDMAP then they
> certainly do not have working COW!!
>
>>> In either case GUP doesn't really work on the VMA. PFNMAP is
totally>>> blocked, and for MIXEDMAP userspace has no way to discover which
>>> subset of the VMA is GUPable. I think that GUP is supported on
>>> MIXEDMAP at all is a bit of a weirdo thing.
>>
>> IIRC (after recent discussions with Lorenzo) there are use cases for that.
>
> Really? Somehow userspace can know which sub slice of the VMA is
> GUP'able? Gross :P
Well, the primary use case is mapping kernel allocations into user space
and GUP'ing them. So the pages are refcounted ...
MIXEDMAP is likely just abused for that ... so I take back that that's a
requirement, rather that MIXEDMAP is automatically used when using the
interfaces -- vm_insert_pages -- to insert refcounted pages into page
tables :)
... and that should definitely be changed, such that MIXEDMAP is really
only used when actually having non-refcounted things in there.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-05-28 18:00 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 [this message]
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
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=84a19161-765d-4aba-b42f-5fdd8c986bdf@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