Re: [PATCH 3/3] mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd

From: Zi Yan

Date: Tue Jul 07 2026 - 16:47:36 EST


On Tue Jul 7, 2026 at 9:45 AM EDT, Usama Arif wrote:
> madvise_free_pte_range() checks pmd_trans_huge(*pmd) unlocked, then
> madvise_free_huge_pmd() takes pmd_trans_huge_lock().
> pmd_is_huge() returns true for a device-private PMD, so orig_pmd can
> be device-private and hit the VM_BUG_ON() on the !pmd_present() branch.
>
> Potential trigger: an HMM-based GPU driver races with madvise(MADV_FREE):
> migrate_vma_pages() flips the PMD to a device-private entry between the
> caller's pmd_trans_huge() check and the callee's pmd_trans_huge_lock().
>
> Skip device-private PMDs after taking the lock, before the
> !pmd_present() check.
>
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> ---
> mm/huge_memory.c | 3 +++
> 1 file changed, 3 insertions(+)
>
LGTM. cc stable as well.

Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>

--
Best Regards,
Yan, Zi