From: sashiko-bot@kernel.org
To: "Eliav Farber" <farbere@amazon.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: "David Hildenbrand" <david@kernel.org>,
"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>,
linux-mm@kvack.org
Subject: Re: [PATCH 3/4] mm/char-mem: implement huge_fault support for /dev/mem
Date: Wed, 11 Nov 2026 22:50:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-209832@kernel.org> (raw)
In-Reply-To: <20261111113045.35368-4-farbere@amazon.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/char-mem: read-only PTE after fixup_user_fault() in
mmap_mem_access()
--
commit 2398e62524e61afe6489b128b93a5b0922afcd83
Author: Eliav Farber <farbere@amazon.com>
mm/char-mem: implement huge_fault support for /dev/mem
This commit switches non-COW /dev/mem mappings from eager remap at mmap()
time to fault-time population using ->fault and ->huge_fault handlers, and
adds mmap_mem_access() to fault in untouched pages before calling
generic_access_phys().
> diff --git a/mm/char-mem.c b/mm/char-mem.c
> index c5761ddedbd7d..b9ed8473baeb7 100644
> --- a/mm/char-mem.c
> +++ b/mm/char-mem.c
> @@ -318,9 +318,92 @@ static inline int private_mapping_ok(struct vm_area_desc *desc)
[ ... ]
> +#ifdef CONFIG_HAVE_IOREMAP_PROT
> +/*
> + * generic_access_phys() only follows present PTEs, and a lazily populated
> + * mapping has none for pages the target has not touched yet. Fault the page in
> + * first, so that remote access (ptrace, /proc/pid/mem) keeps working.
> + *
> + * fixup_user_fault() refuses a fault the vma does not permit, so an untouched
> + * page of a mapping without VM_READ stays unreadable, where the eager mapping
> + * left a present PTE.
> + */
> +static int mmap_mem_access(struct vm_area_struct *vma, unsigned long addr,
> + void *buf, int len, int write)
> +{
> + unsigned int fault_flags = FAULT_FLAG_REMOTE;
> +
> + if (write)
> + fault_flags |= FAULT_FLAG_WRITE;
> +
> + /*
> + * COW mappings are populated at mmap() time, and a write fault would
> + * copy the page instead. With unlocked == NULL, fixup_user_fault()
> + * keeps the mmap lock held and the vma valid.
> + */
> + if (!vma_is_cow_mapping(vma))
> + fixup_user_fault(vma->vm_mm, addr, fault_flags, NULL);
> +
> + return generic_access_phys(vma, addr, buf, len, write);
> +}
> +#endif
[Severity: Medium]
Can a remote write to an untouched order-0 page fail with -EINVAL when
soft-dirty tracking is armed on the VMA?
Writing 4 to /proc/pid/clear_refs clears VM_SOFTDIRTY on the VMA and strips
write permission from vma->vm_page_prot via vma_set_page_prot(). On an
order-0 fault, vmf_insert_pfn_order() calls vmf_insert_pfn(), which calls
insert_pfn() with mkwrite == false and installs a read-only PTE:
mm/memory.c:vmf_insert_pfn_order() {
struct vm_area_struct *vma = vmf->vma;
bool write = vmf->flags & FAULT_FLAG_WRITE;
if (!order)
return vmf_insert_pfn(vma, vmf->address, pfn);
fixup_user_fault() only invokes handle_mm_fault() once, so it does not take
the second write-protection fault (do_wp_page() -> wp_pfn_shared()) that a
CPU store would take to make the PTE writable. generic_access_phys() then
sees !args.writable with FOLL_WRITE set and returns -EINVAL on the first
write attempt.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111113045.35368-1-farbere@amazon.com?part=3
next prev parent reply other threads:[~2026-11-11 22:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 11:30 [PATCH 0/4] mm, uio: huge PFN mappings for /dev/mem and UIO Eliav Farber
2026-11-11 11:30 ` [PATCH 1/4] mm: add MMAP_PFN_TRACK action and pfn_range_track() for lazy PFN maps Eliav Farber
2026-11-11 11:30 ` [PATCH 2/4] mm: add vmf_insert_pfn_order() and vmf_pfn_order_ok() helpers Eliav Farber
2026-11-11 22:50 ` sashiko-bot
2026-11-11 11:30 ` [PATCH 3/4] mm/char-mem: implement huge_fault support for /dev/mem Eliav Farber
2026-11-11 22:50 ` sashiko-bot [this message]
2026-11-11 11:30 ` [PATCH 4/4] uio: implement huge_fault support for physical mappings Eliav Farber
2026-11-11 22:50 ` sashiko-bot
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-209832@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=farbere@amazon.com \
--cc=gregkh@linuxfoundation.org \
--cc=jannh@google.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/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