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 2/2] mm/madvise: use vm_normal_folio_pmd() in cold/pageout PMD range
Date: Thu, 27 Aug 2026 19:07:38 +0200 [thread overview]
Message-ID: <01865a13-2c18-464e-94eb-466613de7bb3@kernel.org> (raw)
In-Reply-To: <20260821144947.167382-3-gourry@gourry.net>
On 8/21/26 16:49, Gregory Price wrote:
> mmap a VM_MIXEDMAP region whose ->huge_fault installs a PMD through
> vmf_insert_pfn_pmd() - mshv_vtl_low does this, and needs CAP_SYS_ADMIN to
> open - then
>
> madvise(p, PMD_SIZE, MADV_PAGEOUT);
>
> With a stand-in module for the driver:
>
> BUG: unable to handle page fault for address: fffff587c0000008
> RIP: 0010:madvise_cold_or_pageout_pte_range+0x410/0x9b0
> walk_pgd_range+0x52b/0xaf0
> __walk_page_range+0x6a/0x1d0
> walk_page_range_vma_unsafe+0x8e/0x120
> madvise_pageout+0xb2/0x180
> madvise_vma_behavior+0x46b/0xa90
> do_madvise+0x108/0x190
> __x64_sys_madvise+0x26/0x30
>
> Nothing validates the pfn on the way in:
>
> can_madv_lru_vma() rejects VM_PFNMAP, but not VM_MIXEDMAP
> can_fault() *pfn = vmf->pgoff & ~(mask >> PAGE_SHIFT);
> vmf_insert_pfn_pmd() no pfn_valid() check
> pmd_folio() pfn_to_page() -> unpopulated vmemmap
>
> Even with a valid pfn the path is wrong. The mapping carries no rmap, so
> folio_maybe_mapped_shared() sees mapcount 0, and the walker goes on to
> folio_deactivate(), or folio_isolate_lru() plus reclaim_pages(), against a
> folio this mapping does not own.
>
> Use vm_normal_folio_pmd() and skip on NULL, as the PTE half of this same
> walker already does with vm_normal_folio(). The huge zero PMD is already
> handled further up by is_huge_zero_pmd().
The last part doesn't make sense, see below.
>
> 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> # v6.19+
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> ---
> mm/madvise.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/madvise.c b/mm/madvise.c
> index ffd6a68320a8..ab362bc482a5 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -393,7 +393,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
> goto huge_unlock;
> }
>
> - folio = pmd_folio(orig_pmd);
> + folio = vm_normal_folio_pmd(vma, addr, orig_pmd);
> + if (!folio)
> + goto huge_unlock;
I think you can now drop the is_huge_zero_pmd() check, because
!vm_normal_folio_pmd() includes the huge zero folio.
--
Cheers,
David
next prev parent reply other threads:[~2026-08-27 17:07 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)
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) [this message]
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=01865a13-2c18-464e-94eb-466613de7bb3@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