From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Gregory Price <gourry@gourry.net>, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
akpm@linux-foundation.org, liam@infradead.org, ljs@kernel.org,
vbabka@kernel.org, jannh@google.com, ziy@nvidia.com,
matthew.brost@intel.com, joshua.hahnjy@gmail.com,
rakie.kim@sk.com, byungchul@sk.com, ying.huang@linux.alibaba.com,
apopple@nvidia.com, peterx@redhat.com, jgg@ziepe.ca,
sashiko-bot <sashiko-bot@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/mempolicy: use vm_normal_folio_pmd() in queue_folios_pmd()
Date: Thu, 27 Aug 2026 19:05:21 +0200 [thread overview]
Message-ID: <6d855beb-1d24-4a6e-ae62-ac9e05e358e5@kernel.org> (raw)
In-Reply-To: <20260821144947.167382-2-gourry@gourry.net>
On 8/21/26 16:49, Gregory Price wrote:
> mmap a VM_PFNMAP region whose ->huge_fault installs a PMD through
> vmf_insert_pfn_pmd() - a vfio-pci MMIO BAR does this - then
>
> mbind(p, len, MPOL_BIND, &mask, maxnode, MPOL_MF_STRICT);
>
> With a stand-in module for the driver:
>
> BUG: unable to handle page fault for address: fffff96dc0000008
> RIP: 0010:queue_folios_pte_range+0xaf/0x440
> walk_pgd_range+0x52b/0xaf0
> __walk_page_range+0x6a/0x1d0
> walk_page_range_mm_unsafe+0x193/0x230
> queue_pages_range+0x64/0xa0
> do_mbind+0x25e/0x640
>
> queue_folios_pmd(), inlined above, calls pmd_folio() on that PMD. The pfn
> is raw MMIO with no memmap entry, so the folio lands in unpopulated
> vmemmap. Neither guard stops the walk:
>
> walk_page_test() skips VM_PFNMAP, but queue_pages_walk_ops
> supplies ->test_walk, so it never runs
> queue_pages_test_walk() honours vma_migratable(), but only while
> MPOL_MF_STRICT is clear
>
> A VM_MIXEDMAP vma needs neither flag, being vma_migratable(), so plain
> mbind(MPOL_MF_MOVE) reaches this too - and there the bad folio carries on
> into migrate_folio_add() and folio_isolate_lru(). mshv_vtl_low is such a
> mapping.
>
> Use vm_normal_folio_pmd() and skip on NULL, as the PTE loop in
> queue_folios_pte_range() already does with vm_normal_folio(). The huge
> zero PMD moves ahead of the lookup, since vm_normal_folio_pmd() returns
> NULL for it and its ACTION_CONTINUE would be lost.
>
> mbind(MPOL_MF_STRICT) over a PMD mapped VM_PFNMAP region now returns 0
> rather than -EIO. The PTE loop already returned 0 there.
>
> Fixes: 3c8e44c9b369 ("mm: mark special bits for huge pfn mappings when inject")
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260817220810.1175596-1-gourry%40gourry.net
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> ---
> mm/mempolicy.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index f1aba551f9f1..85803c845965 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -650,7 +650,8 @@ static inline bool queue_folio_required(struct folio *folio,
> return node_isset(nid, *qp->nmask) == !(flags & MPOL_MF_INVERT);
> }
>
> -static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk)
> +static void queue_folios_pmd(pmd_t *pmd, unsigned long addr,
> + struct mm_walk *walk)
> {
> struct folio *folio;
> struct queue_pages *qp = walk->private;
> @@ -661,13 +662,15 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk)
> qp->nr_failed++;
> return;
> }
> - folio = pmd_folio(pmdval);
> - if (folio_is_zone_device(folio))
> - return;
> - if (is_huge_zero_folio(folio)) {
> + if (is_huge_zero_pmd(pmdval)) {
> walk->action = ACTION_CONTINUE;
> return;
> }
> + folio = vm_normal_folio_pmd(walk->vma, addr, pmdval);
> + if (!folio)
> + return
I think this is best written as:
folio = vm_normal_folio_pmd(walk->vma, addr, pmdval);
if (!folio) {
if (is_huge_zero_pmd(pmdval)) {
walk->action = ACTION_CONTINUE;
return;
}
return;
}
That way we minimize checks on the expected path.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
next prev parent reply other threads:[~2026-08-27 17:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 14:49 [PATCH 0/2] mm: stop calling pmd_folio() on special PMDs Gregory Price
2026-08-21 14:49 ` [PATCH 1/2] mm/mempolicy: use vm_normal_folio_pmd() in queue_folios_pmd() Gregory Price
2026-08-27 17:05 ` David Hildenbrand (Arm) [this message]
2026-08-27 18:48 ` Gregory Price
2026-08-21 14:49 ` [PATCH 2/2] mm/madvise: use vm_normal_folio_pmd() in cold/pageout PMD range Gregory Price
2026-08-27 17:07 ` David Hildenbrand (Arm)
2026-08-27 18:50 ` Gregory Price
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=6d855beb-1d24-4a6e-ae62-ac9e05e358e5@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=gourry@gourry.net \
--cc=jannh@google.com \
--cc=jgg@ziepe.ca \
--cc=joshua.hahnjy@gmail.com \
--cc=kernel-team@meta.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=peterx@redhat.com \
--cc=rakie.kim@sk.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--cc=vbabka@kernel.org \
--cc=ying.huang@linux.alibaba.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
all inboxes | Powered by JetHome®