Re: [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios
From: Zi Yan
Date: Wed Jul 08 2026 - 11:28:40 EST
On 8 Jul 2026, at 8:20, Usama Arif wrote:
> queue_folios_pmd() is called under pmd_trans_huge_lock(), whose
> pmd_is_huge() check returns true for any non-present, non-none PMD
> softleaf. Passing such a PMD to pmd_folio() treats the softleaf encoding
> as a hardware PFN and can return a bogus folio pointer.
>
> Mirror queue_folios_pte_range(): handle non-present entries before
> looking up a folio. Keep migration entries counted as failures, but skip
> other non-present PMDs such as device-private entries.
>
> Potential trigger: an HMM-based GPU driver migrates an anonymous THP
> folio to device memory via migrate_vma_pages(), leaving a device-private
> PMD. Userspace then calls mbind(), migrate_pages() or
> set_mempolicy_home_node() on that range.
>
> Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=6
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@xxxxxxxxx>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> ---
> mm/mempolicy.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 914f81863db5..4785b55c02da 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -654,12 +654,14 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk)
> {
> struct folio *folio;
> struct queue_pages *qp = walk->private;
> + pmd_t pmdval = *pmd;
Use pmdp_get() instead?
>
> - if (unlikely(pmd_is_migration_entry(*pmd))) {
> - qp->nr_failed++;
> + if (unlikely(!pmd_present(pmdval))) {
> + if (pmd_is_migration_entry(pmdval))
> + qp->nr_failed++;
> return;
> }
> - folio = pmd_folio(*pmd);
> + folio = pmd_folio(pmdval);
> if (is_huge_zero_folio(folio)) {
> walk->action = ACTION_CONTINUE;
> return;
> --
> 2.53.0-Meta
Otherwise, LGTM.
Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
Best Regards,
Yan, Zi