From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Yin Tirui <yintirui@gmail.com>, Lorenzo Stoakes <ljs@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Kiryl Shutsemau <kas@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 13/13] mm/huge_memory: add and use has_deposited_pgtable()
Date: Wed, 15 Apr 2026 10:13:05 +0200 [thread overview]
Message-ID: <6edde1e9-0f42-4dae-b0d1-3f2895f2111b@kernel.org> (raw)
In-Reply-To: <f7f26a91-5346-40d6-aee3-3b64c3249ac4@gmail.com>
On 4/15/26 05:50, Yin Tirui wrote:
> Hi David,
>
> On 4/15/26 02:15, David Hildenbrand (Arm) wrote:
>> On 4/14/26 17:14, Yin Tirui wrote:
>>>
>>> I did a quick tree-wide grep:
>>> $ git grep -l "remap_pfn_range" | xargs grep -l "\.fault\s*="
>>> arch/powerpc/platforms/book3s/vas-api.c
>>> drivers/infiniband/hw/hfi1/file_ops.c
>>> drivers/uio/uio.c
>>> drivers/vfio/pci/vfio_pci_core.c
>>> fs/proc/vmcore.c
>>> security/selinux/selinuxfs.c
>>>
>>> It turns out there are two users of this "hybrid" approach in the kernel:
>>> 1. fs/proc/vmcore.c: It pre-maps via remap_pfn_range() but registers
>>> mmap_vmcore_fault().
>>> 2. arch/powerpc/platforms/book3s/vas-api.c: It pre-maps via
>>> remap_pfn_range(), but registers vas_mmap_fault().
>>>
>>>
>>> How would you suggest we proceed here?
>>
>> How about we populate PMDs in remap_pfn_range() only if !fault?
>
> Doing this would at most prevent VMAs with a ->fault() handler from
> getting huge mappings, which seems to have little negative impact.
>
> But wait, dynamic huge mappings are actually created through ->huge_fault().
If my memory serves me right, also fault() can nowadays install PMD
mappings.
For example, shmem only implements ->fault through shmem_fault()
finish_fault() after __do_fault() takes care of that (mapping through a
PMD if possible).
>
> I did a quick grep:
> $ git grep -l "remap_pfn_range" | xargs grep -l "\.huge_fault\s*="
> drivers/vfio/pci/vfio_pci_core.c
>
> This is a false positive. There is no case in the kernel that mixes
> remap_pfn_range() and ->huge_fault() on the same VMA.
>
> What if we use !huge_fault instead, disallowing remap_pfn_range() from
> populating PMDs if ->huge_fault() is provided?
I think we should just disallow any PMD mappings if we either have
->fault or ->huge_fault.
I would assume that ->huge_fault implies >fault, but let's rather be
save than sorry.
>
> Then, when we encounter a huge PMD, we know for sure whether it was
> installed through remap_pfn_range() (needs a deposited pgtable) or
> ->huge_fault() (no deposit needed, can be refaulted).
>
>>
>> Then, if we have !fault, we know that the PMD is from remap_pfn_range()
>> and has a disposed page table.
>>
>> Would that work?
>>
>
> So for Lorenzo's `has_deposited_pgtable()` helper, we could simply use:
>
> /* Huge PFN map without a huge_fault handler must deposit */
> if (vma_test(vma, VMA_PFNMAP_BIT))
> return !vma->vm_ops || !vma->vm_ops->huge_fault;
As mentioned above, also considering vma->vm_ops->fault;
>
>
> By the way, while auditing this, I noticed that
> drivers/gpu/drm/drm_gem_shmem_helper.c calls vmf_insert_pfn_pmd()
> directly from its normal ->fault() handler instead of implementing
> ->huge_fault().
> If we adopt the `!huge_fault` check above, this DRM driver would be
> wrongly classified as needing a deposit. It seems that DRM driver needs
> a minor refactoring to properly use ->huge_fault() to keep the MM
> semantics clean.
No, it's doing something that's allowed. If we call ->fault and there is
not PTE table, it may insert a PMD.
--
Cheers,
David
next prev parent reply other threads:[~2026-04-15 8:13 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 18:14 [PATCH v3 00/13] mm/huge_memory: refactor zap_huge_pmd() Lorenzo Stoakes (Oracle)
2026-03-20 18:07 ` [PATCH v3 01/13] mm/huge_memory: simplify vma_is_specal_huge() Lorenzo Stoakes (Oracle)
2026-03-28 18:49 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 02/13] mm/huge: avoid big else branch in zap_huge_pmd() Lorenzo Stoakes (Oracle)
2026-03-28 18:52 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 03/13] mm/huge_memory: have zap_huge_pmd return a boolean, add kdoc Lorenzo Stoakes (Oracle)
2026-03-28 18:54 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 04/13] mm/huge_memory: handle buggy PMD entry in zap_huge_pmd() Lorenzo Stoakes (Oracle)
2026-03-28 19:05 ` Suren Baghdasaryan
2026-03-30 10:08 ` Lorenzo Stoakes (Oracle)
2026-03-20 18:07 ` [PATCH v3 05/13] mm/huge_memory: add a common exit path to zap_huge_pmd() Lorenzo Stoakes (Oracle)
2026-03-28 19:08 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 06/13] mm/huge_memory: remove unnecessary VM_BUG_ON_PAGE() Lorenzo Stoakes (Oracle)
2026-03-28 19:09 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 07/13] mm/huge_memory: deduplicate zap deposited table call Lorenzo Stoakes (Oracle)
2026-03-21 5:39 ` Baolin Wang
2026-03-28 19:14 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 08/13] mm/huge_memory: remove unnecessary sanity checks Lorenzo Stoakes (Oracle)
2026-03-28 19:17 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 09/13] mm/huge_memory: use mm instead of tlb->mm Lorenzo Stoakes (Oracle)
2026-03-21 5:42 ` Baolin Wang
2026-03-28 19:18 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 10/13] mm/huge_memory: separate out the folio part of zap_huge_pmd() Lorenzo Stoakes (Oracle)
2026-03-21 5:59 ` Baolin Wang
2026-03-23 10:42 ` Lorenzo Stoakes (Oracle)
2026-03-24 12:42 ` Baolin Wang
2026-03-28 19:20 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 11/13] mm: add softleaf_is_valid_pmd_entry(), pmd_to_softleaf_folio() Lorenzo Stoakes (Oracle)
2026-03-28 19:28 ` Suren Baghdasaryan
2026-03-20 18:07 ` [PATCH v3 12/13] mm/huge_memory: add and use normal_or_softleaf_folio_pmd() Lorenzo Stoakes (Oracle)
2026-03-23 11:24 ` Lorenzo Stoakes (Oracle)
2026-03-28 19:45 ` Suren Baghdasaryan
2026-03-30 9:48 ` Lorenzo Stoakes (Oracle)
2026-03-20 18:07 ` [PATCH v3 13/13] mm/huge_memory: add and use has_deposited_pgtable() Lorenzo Stoakes (Oracle)
2026-03-23 11:45 ` Lorenzo Stoakes (Oracle)
2026-03-23 12:25 ` Lorenzo Stoakes (Oracle)
2026-03-28 19:54 ` Suren Baghdasaryan
2026-03-30 9:54 ` Lorenzo Stoakes (Oracle)
2026-04-02 3:19 ` Yin Tirui
2026-04-02 6:46 ` Lorenzo Stoakes (Oracle)
2026-04-02 7:49 ` Yin Tirui
2026-04-07 10:48 ` Lorenzo Stoakes
2026-04-14 7:36 ` Yin Tirui
2026-04-14 9:44 ` David Hildenbrand (Arm)
2026-04-14 15:14 ` Yin Tirui
2026-04-14 18:15 ` David Hildenbrand (Arm)
2026-04-15 3:50 ` Yin Tirui
2026-04-15 8:13 ` David Hildenbrand (Arm) [this message]
2026-04-15 15:27 ` Yin Tirui
2026-03-20 18:42 ` [PATCH v3 00/13] mm/huge_memory: refactor zap_huge_pmd() Andrew Morton
2026-03-23 12:08 ` Lorenzo Stoakes (Oracle)
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=6edde1e9-0f42-4dae-b0d1-3f2895f2111b@kernel.org \
--to=david@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=npache@redhat.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=yintirui@gmail.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