From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: linux-usb@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
linux-scsi@vger.kernel.org, "Oliver Upton" <oupton@kernel.org>,
dri-devel@lists.freedesktop.org,
"Heiko Carstens" <hca@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
selinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
kvmarm@lists.linux.dev, "Marc Zyngier" <maz@kernel.org>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
kvm@vger.kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v5 07/38] mm: add mmap action for discontiguous kernel page mapping
Date: Fri, 09 Oct 2026 18:29:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-165947@kernel.org> (raw)
In-Reply-To: <20261009-b4-mmap-prepare-vma-flag-sanify-v5-7-923b70125b1e@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: missing error return after VM_WARN_ON_ONCE for VMA_PFNMAP
--
commit dfcef6542267c02a389d52c15954f3b2b60a0695
Author: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Subject: mm: add mmap action for discontiguous kernel page mapping
This commit introduces discontig_kernel_page_ops to allow drivers to map
discontiguous arrays of page pointers into VMAs. It also updates
vm_insert_page() and vm_insert_pages() to assert that the mmap write lock
is held, converting BUG_ON checks to VM_WARN_ON_ONCE while unifying the
code paths.
> diff --git a/mm/memory.c b/mm/memory.c
> index 448342883e9da..e5c1d1c35bc70 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2599,27 +2599,34 @@ int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr,
>
> if (!range_in_vma(vma, addr, end))
> return -EFAULT;
> - if (!(vma->vm_flags & VM_MIXEDMAP)) {
> - VM_WARN_ON_ONCE(mmap_read_trylock(vma->vm_mm));
> - VM_WARN_ON_ONCE(vma->vm_flags & VM_PFNMAP);
> - vm_flags_set(vma, VM_MIXEDMAP);
> + if (!vma_test(vma, VMA_MIXEDMAP_BIT)) {
> + mmap_assert_write_locked(vma->vm_mm);
> + VM_WARN_ON_ONCE(vma_test(vma, VMA_PFNMAP_BIT));
[Severity: High]
If this warning triggers, execution will fall through because there is no
error return. On production kernels where VM_WARN_ON_ONCE is a no-op, this
will silently set VMA_MIXEDMAP_BIT and insert page entries into a
PFN-mapped VMA.
During VMA teardown, zap_pte_range() will not decrement the reference
counts for these pages since vm_normal_page() returns NULL for VMAs with
VM_PFNMAP set.
Could this result in a permanent memory leak? Should this return an error
such as -EINVAL if the bit is set?
> + vma_start_write(vma);
> + vma_set_flags(vma, VMA_MIXEDMAP_BIT);
> }
> /* Defer page refcount checking till we're about to map that page. */
> return insert_pages(vma, addr, pages, num, vma->vm_page_prot);
> }
[ ... ]
> +static void __map_kernel_pages_prepare(struct vm_area_desc *desc)
> +{
> + if (vma_desc_test(desc, VMA_MIXEDMAP_BIT))
> + return;
> +
> + mmap_assert_write_locked(desc->mm);
> + VM_WARN_ON_ONCE(vma_desc_test(desc, VMA_PFNMAP_BIT));
[Severity: High]
Similar to the check in vm_insert_pages(), this warns but does not abort
the operation if the VMA has the PFNMAP bit set. Should this function be
changed to return an int so it can propagate an error and prevent inserting
refcounted pages into a PFN-mapped VMA?
> + vma_desc_set_flags(desc, VMA_MIXEDMAP_BIT);
> +}
[ ... ]
> @@ -2675,10 +2774,11 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
> {
> if (addr < vma->vm_start || addr >= vma->vm_end)
> return -EFAULT;
> - if (!(vma->vm_flags & VM_MIXEDMAP)) {
> - BUG_ON(mmap_read_trylock(vma->vm_mm));
> - BUG_ON(vma->vm_flags & VM_PFNMAP);
> - vm_flags_set(vma, VM_MIXEDMAP);
> + if (!vma_test(vma, VMA_MIXEDMAP_BIT)) {
> + mmap_assert_write_locked(vma->vm_mm);
> + VM_WARN_ON_ONCE(vma_test(vma, VMA_PFNMAP_BIT));
[Severity: High]
This replaces a strict BUG_ON() with a warning but allows execution to
continue. Does this need an early return here as well to prevent a
potential page reference leak?
> + vma_start_write(vma);
> + vma_set_flags(vma, VMA_MIXEDMAP_BIT);
> }
> return insert_page(vma, addr, page, vma->vm_page_prot, false);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261009-b4-mmap-prepare-vma-flag-sanify-v5-0-923b70125b1e@kernel.org?part=7
next prev parent reply other threads:[~2026-10-09 18:29 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 18:03 [PATCH v5 00/38] mm: make VMA flag semantics explicit, eliminate VM_SPECIAL Lorenzo Stoakes (ARM)
2026-10-09 18:03 ` [PATCH v5 01/38] mm/vma: fix mmap_prepare file handling, remove file_doesnt_need_get Lorenzo Stoakes (ARM)
2026-10-09 18:24 ` sashiko-bot
2026-10-09 18:03 ` [PATCH v5 02/38] mm/vma: introduce and use vma_[flags_]can_merge() Lorenzo Stoakes (ARM)
2026-10-09 18:21 ` sashiko-bot
2026-10-09 18:03 ` [PATCH v5 03/38] mm: consistently validate VMA state after mmap[_prepare] hooks Lorenzo Stoakes (ARM)
2026-10-09 18:33 ` sashiko-bot
2026-10-09 18:03 ` [PATCH v5 04/38] mm/vma: ensure mmap_prepare doesn't set actions on a mergeable vma Lorenzo Stoakes (ARM)
2026-10-09 18:22 ` sashiko-bot
2026-10-09 18:03 ` [PATCH v5 05/38] mm: make map_kernel_pages_[prepare,complete] internal and unexported Lorenzo Stoakes (ARM)
2026-10-09 18:20 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 06/38] mm/vma: tidy up map kernel pages enum values Lorenzo Stoakes (ARM)
2026-10-09 18:20 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 07/38] mm: add mmap action for discontiguous kernel page mapping Lorenzo Stoakes (ARM)
2026-10-09 18:29 ` sashiko-bot [this message]
2026-10-12 15:03 ` David Hildenbrand (Arm)
2026-10-12 17:46 ` Lorenzo Stoakes (ARM)
2026-10-12 19:02 ` David Hildenbrand (Arm)
2026-10-09 18:04 ` [PATCH v5 08/38] docs: filesystems: update mmap_prepare docs for discontig kernel pgs Lorenzo Stoakes (ARM)
2026-10-09 18:19 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 09/38] drivers/usb/mon: update to use mmap_prepare + map kernel pages Lorenzo Stoakes (ARM)
2026-10-09 18:32 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 10/38] infiniband: update hfi1 to use remap_vmalloc_range() Lorenzo Stoakes (ARM)
2026-10-09 18:30 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 11/38] selinux: reject writable opens of policy file, drop mmap shared/write check Lorenzo Stoakes (ARM)
2026-10-09 18:26 ` sashiko-bot
2026-10-12 15:06 ` David Hildenbrand (Arm)
2026-10-09 18:04 ` [PATCH v5 12/38] ALSA: pcm: use vm_insert_page() to map PCM status page Lorenzo Stoakes (ARM)
2026-10-09 18:38 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 13/38] bpf: arena: mark arena_map_mmap() mappings VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-10-09 18:30 ` sashiko-bot
2026-10-12 15:08 ` David Hildenbrand (Arm)
2026-10-12 15:55 ` Lorenzo Stoakes (ARM)
2026-10-12 18:56 ` David Hildenbrand (Arm)
2026-10-12 19:11 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 14/38] mm/vma: add vma[_flags]_is_mm_managed() predicates Lorenzo Stoakes (ARM)
2026-10-09 18:26 ` sashiko-bot
2026-10-12 18:06 ` David Hildenbrand (Arm)
2026-10-12 18:15 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 15/38] mm/vma: only allow mmap to clear VMA_MAYWRITE_BIT if not mm-managed Lorenzo Stoakes (ARM)
2026-10-09 18:25 ` sashiko-bot
2026-10-12 18:07 ` David Hildenbrand (Arm)
2026-10-09 18:04 ` [PATCH v5 16/38] mm/vma: add and use vma_[flags]_is_fixed_mapping Lorenzo Stoakes (ARM)
2026-10-09 18:29 ` sashiko-bot
2026-10-12 18:11 ` David Hildenbrand (Arm)
2026-10-09 18:04 ` [PATCH v5 17/38] scsi: sg: convert mmap hook to mmap_prepare and rework Lorenzo Stoakes (ARM)
2026-10-09 18:44 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 18/38] fbdev: defio: assert FBINFO_VIRTFB, drop VM_IO, add VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-10-09 18:36 ` sashiko-bot
2026-10-12 18:12 ` David Hildenbrand (Arm)
2026-10-09 18:04 ` [PATCH v5 19/38] HSI: cmt_speech: convert mmap hook to mmap_prepare, refactor Lorenzo Stoakes (ARM)
2026-10-09 18:39 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 20/38] mm/gup: error out early on !VMA_MAYREAD_BIT VMAs Lorenzo Stoakes (ARM)
2026-10-09 18:34 ` sashiko-bot
2026-10-12 18:15 ` David Hildenbrand (Arm)
2026-10-09 18:04 ` [PATCH v5 21/38] uprobes: remove VM_IO, set VM_MIXEDMAP for mapped kernel pages Lorenzo Stoakes (ARM)
2026-10-09 18:41 ` sashiko-bot
2026-10-12 18:16 ` David Hildenbrand (Arm)
2026-10-12 18:20 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 22/38] mm/mlock: clear VMA_LOCKED_MASK over mmap callback Lorenzo Stoakes (ARM)
2026-10-09 18:40 ` sashiko-bot
2026-10-12 18:19 ` David Hildenbrand (Arm)
2026-10-12 18:23 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 23/38] mm/mlock: eliminate weird VMA_IO_BIT abuse and simplify Lorenzo Stoakes (ARM)
2026-10-09 18:49 ` sashiko-bot
2026-10-12 18:23 ` David Hildenbrand (Arm)
2026-10-12 18:38 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 24/38] mm/vma: enforce that mm-managed mappings may not set VMA_IO_BIT Lorenzo Stoakes (ARM)
2026-10-09 18:36 ` sashiko-bot
2026-10-12 18:25 ` David Hildenbrand (Arm)
2026-10-12 18:35 ` Lorenzo Stoakes (ARM)
2026-10-12 18:39 ` David Hildenbrand (Arm)
2026-10-12 18:48 ` Lorenzo Stoakes (ARM)
2026-10-12 18:51 ` David Hildenbrand (Arm)
2026-10-12 18:57 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 25/38] mm: remove VMA_IO_BIT check in vma[_flags]_is_mm_managed() Lorenzo Stoakes (ARM)
2026-10-09 18:43 ` sashiko-bot
2026-10-12 18:31 ` David Hildenbrand (Arm)
2026-10-12 18:42 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 26/38] mm: remove hugetlb_inline.h Lorenzo Stoakes (ARM)
2026-10-09 18:38 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 27/38] mm: rename is_vm_hugetlb_page() to vma_is_hugetlb() Lorenzo Stoakes (ARM)
2026-10-09 18:40 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 28/38] mm: drop some redundant checks around hugetlb VMAs Lorenzo Stoakes (ARM)
2026-10-09 18:43 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 29/38] mm/madvise: update is_valid_guard_vma() to use vma_can_merge() Lorenzo Stoakes (ARM)
2026-10-09 18:44 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 30/38] mm/vma: introduce vma[_flags]_is_mm_backed() Lorenzo Stoakes (ARM)
2026-10-09 18:48 ` sashiko-bot
2026-10-12 18:45 ` David Hildenbrand (Arm)
2026-10-12 18:46 ` David Hildenbrand (Arm)
2026-10-13 10:57 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 31/38] mm/uffd: use predicates for userfaultfd checks Lorenzo Stoakes (ARM)
2026-10-09 18:46 ` sashiko-bot
2026-10-12 18:48 ` David Hildenbrand (Arm)
2026-10-13 11:29 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 32/38] mm/madvise: use predicates for madvise(..., MADV_DOFORK) Lorenzo Stoakes (ARM)
2026-10-09 18:47 ` sashiko-bot
2026-10-12 18:48 ` David Hildenbrand (Arm)
2026-10-09 18:04 ` [PATCH v5 33/38] mm: eliminate VMA_SPECIAL_FLAGS usage when hugetlb explicitly tested Lorenzo Stoakes (ARM)
2026-10-09 18:47 ` sashiko-bot
2026-10-12 18:49 ` David Hildenbrand (Arm)
2026-10-13 11:43 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 34/38] mm: eliminate VMA_SPECIAL_FLAGS check in lru_gen_look_around() Lorenzo Stoakes (ARM)
2026-10-09 18:49 ` sashiko-bot
2026-10-12 18:50 ` David Hildenbrand (Arm)
2026-10-13 11:45 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 35/38] mm: avoid use of VMA_SPECIAL_FLAGS in migrate_vma_setup() Lorenzo Stoakes (ARM)
2026-10-09 18:50 ` sashiko-bot
2026-10-12 18:52 ` David Hildenbrand (Arm)
2026-10-13 11:46 ` Lorenzo Stoakes (ARM)
2026-10-09 18:04 ` [PATCH v5 36/38] mm: eliminate VM_SPECIAL, VMA_SPECIAL_FLAGS Lorenzo Stoakes (ARM)
2026-10-09 18:48 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 37/38] fuse: dax: do not set VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-10-09 18:56 ` sashiko-bot
2026-10-09 18:04 ` [PATCH v5 38/38] mm/huge_memory: remove vma_is_special_huge() Lorenzo Stoakes (ARM)
2026-10-09 18:52 ` sashiko-bot
2026-10-12 18:53 ` David Hildenbrand (Arm)
2026-10-10 22:00 ` [PATCH v5 00/38] mm: make VMA flag semantics explicit, eliminate VM_SPECIAL Andrew Morton
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-165947@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=selinux@vger.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