From: sashiko-bot@kernel.org
To: "Eliav Farber" <farbere@amazon.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Zi Yan" <ziy@nvidia.com>
Cc: "Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>, "Jann Horn" <jannh@google.com>,
"Pedro Falcato" <pfalcato@suse.de>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Nico Pache" <nico.pache@linux.dev>,
"Ryan Roberts" <ryan.roberts@arm.com>,
"Dev Jain" <dev.jain@arm.com>, "Barry Song" <baohua@kernel.org>,
"Lance Yang" <lance.yang@linux.dev>,
"Usama Arif" <usama.arif@linux.dev>,
"Kiryl Shutsemau" <kas@kernel.org>,
linux-mm@kvack.org
Subject: Re: [PATCH v3 4/5] mm/char-mem: implement huge_fault support for /dev/mem
Date: Wed, 25 Nov 2026 13:16:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-233479@kernel.org> (raw)
In-Reply-To: <20261124131510.38745-5-farbere@amazon.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm/char-mem: unchecked runtime PUD support in
mmap_mem_huge_fault()
- [Medium] mm/char-mem: missing thp_get_unmapped_area in mem_fops
defeats huge_fault
--
commit 67f1816619b76ea83350a58c506176be1eb3bbc4
Author: Eliav Farber <farbere@amazon.com>
mm/char-mem: implement huge_fault support for /dev/mem
This commit changes non-COW /dev/mem mappings (when CONFIG_IO_STRICT_DEVMEM
is disabled) from eager 4KiB remap_pfn_range() population at mmap() time to
fault-driven population with ->fault and ->huge_fault handlers using
vmf_insert_pfn_order().
> diff --git a/mm/char-mem.c b/mm/char-mem.c
> index c5761ddedbd7d..283531645f185 100644
> --- a/mm/char-mem.c
> +++ b/mm/char-mem.c
> @@ -318,9 +318,68 @@ static inline int private_mapping_ok(struct vm_area_desc *desc)
> }
> #endif
>
> +#ifdef CONFIG_MMU
> +/* Populate /dev/mem on fault, huge where the arch and alignment allow */
> +static vm_fault_t mmap_mem_huge_fault(struct vm_fault *vmf, unsigned int order)
> +{
> + unsigned long addr = vmf->address & ~((PAGE_SIZE << order) - 1);
> + struct vm_area_struct *vma = vmf->vma;
> + unsigned long pfn;
> +
> + /* An order-aligned addr below the VMA would wrap the subtraction */
> + if (addr < vma->vm_start)
> + return VM_FAULT_FALLBACK;
> +
> + pfn = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT);
> +
> + return vmf_insert_pfn_order(vmf, pfn, order);
> +}
[Severity: Medium]
Can a PUD_ORDER fault reach vmf_insert_pfn_pud() here on a system that
lacks runtime PUD hugepage support?
For VM_PFNMAP mappings, __thp_vma_allowable_orders() enables both PMD_ORDER
and PUD_ORDER, and thp_disabled_by_hw() only checks PMD support via
has_transparent_hugepage(). vmf_insert_pfn_order() checks compile-time
IS_ENABLED(CONFIG_ARCH_SUPPORTS_PUD_PFNMAP) without verifying runtime PUD
support (such as has_transparent_pud_hugepage() or
arch_vmap_pud_supported()).
On PowerPC Book3S 64 with 64KiB pages running on the Hash MMU
(!radix_enabled()), CONFIG_ARCH_SUPPORTS_PUD_PFNMAP is enabled while PUD
hugepages are unsupported, so vmf_insert_pfn_pud() -> insert_pud() ->
pfn_pud() -> __pud_mkhuge() hits an unconditional BUG(). On x86_64 CPUs or
VMs without X86_FEATURE_GBPAGES, pud_mkhuge() sets _PAGE_PSE on the PUD
entry, causing a reserved-bit page fault and an oops in pgtable_bad().
[ ... ]
> @@ -355,11 +414,25 @@ static int mmap_mem_prepare(struct vm_area_desc *desc)
> size,
> desc->page_prot);
>
> + desc->action.error_override = -EAGAIN;
> +
> + /*
> + * COW can't be populated on fault: vmf_insert_pfn*() BUG_ON() it. And
> + * with IO_STRICT_DEVMEM a fault can install an entry after
> + * revoke_iomem() has zapped it, so keep the revoke final.
> + */
> + if (IS_ENABLED(CONFIG_IO_STRICT_DEVMEM) ||
> + vma_desc_is_cow_mapping(desc)) {
> + /* Remap-pfn-range will mark the range with the I/O flag. */
> + desc->vm_ops = &mmap_mem_eager_vm_ops;
> + mmap_action_remap_full(desc, desc->pgoff);
> + return 0;
> + }
> +
> desc->vm_ops = &mmap_mem_ops;
>
> - /* Remap-pfn-range will mark the range with the I/O flag. */
> - mmap_action_remap_full(desc, desc->pgoff);
> - desc->action.error_override = -EAGAIN;
> + /* Tracking reserves the memory type, for PAT conflict detection */
> + mmap_action_track_pfn(desc, desc->pgoff);
>
> return 0;
> }
[Severity: Medium]
Should mem_fops also set .get_unmapped_area = thp_get_unmapped_area under
CONFIG_MMU so unhinted mmap() calls receive a PMD-aligned virtual address?
In __get_unmapped_area(), the automatic thp_get_unmapped_area_vmaflags()
fallback only runs when !file. Because mem_fops leaves .get_unmapped_area
as NULL on CONFIG_MMU, an unhinted mmap(NULL, len, ...) of /dev/mem gets a
4KiB-aligned virtual address from mm_get_unmapped_area_vmaflags().
Whenever vma->vm_start and vma->vm_pgoff << PAGE_SHIFT are not congruent
modulo PMD_SIZE, mmap_mem_huge_fault() computes an unaligned PFN at every
PMD and PUD boundary, which vmf_insert_pfn_pmd() and vmf_insert_pfn_pud()
reject with VM_FAULT_FALLBACK, falling back from the previous batched
remap_pfn_range() to individual 4KiB page faults across the mapping.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124131510.38745-1-farbere@amazon.com?part=4
next prev parent reply other threads:[~2026-11-25 13:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:15 [PATCH v3 0/5] mm, uio: huge PFN mappings for /dev/mem and UIO Eliav Farber
2026-11-24 13:15 ` [PATCH v3 1/5] mm: add MMAP_TRACK_PFN action and track_pfn_range() for lazy PFN maps Eliav Farber
2026-11-24 13:15 ` [PATCH v3 2/5] mm/huge_memory: check the window and the pfn alignment before inserting Eliav Farber
2026-11-24 13:15 ` [PATCH v3 3/5] mm: add vmf_insert_pfn_order() Eliav Farber
2026-11-24 13:15 ` [PATCH v3 4/5] mm/char-mem: implement huge_fault support for /dev/mem Eliav Farber
2026-11-25 13:16 ` sashiko-bot [this message]
2026-11-24 13:15 ` [PATCH v3 5/5] uio: implement huge_fault support for physical mappings Eliav Farber
2026-11-24 14:12 ` Greg Kroah-Hartman
2026-11-24 13:28 ` [PATCH v3 0/5] mm, uio: huge PFN mappings for /dev/mem and UIO Lorenzo Stoakes (ARM)
2026-11-24 18:15 ` Farber, Eliav
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=sashiko-outbox-233479@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=farbere@amazon.com \
--cc=gregkh@linuxfoundation.org \
--cc=jannh@google.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=nico.pache@linux.dev \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--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