migrate_vma_split_unmapped_folio() takes an extra folio reference because split_huge_pmd_address(..., true) drops one when it splits a PMD. However, migrate_vma only holds mmap_lock for reading. A concurrent MADV_DONTNEED can clear the migration PMD, or split it into PTE migration entries, before the split helper takes the PMD lock. The helper then does nothing and leaves the extra reference behind. folio_split_unmapped() fails with -EAGAIN due to the unexpected reference, and the reference is never dropped, so the source THP is leaked. If a THP is faulted in at the same address inside that window it is worse: freeze = true replaces the new folio's mappings with migration entries that nothing will ever remove, and drops a reference the caller never took. An existing migration PMD is expanded into PTE migration entries even with freeze = false. Use that mode and remove the extra folio_get(). The reference already held by migration keeps the source folio alive whether or not its PMD migration entry still exists. Reported-by: Zi Yan Closes: https://lore.kernel.org/all/DLZ48KMS7YG8.3BTM0UUU8CTU2@nvidia.com/ Fixes: 4265d67e405a ("mm/migrate_device: add THP splitting during migration") Cc: stable@vger.kernel.org Signed-off-by: Usama Arif --- mm/migrate_device.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 9e19fadfa65c6..3286bb8a4b73e 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -920,12 +920,7 @@ static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate, unsigned long flags; int ret = 0; - /* - * take a reference, since split_huge_pmd_address() with freeze = true - * drops a reference at the end. - */ - folio_get(folio); - split_huge_pmd_address(migrate->vma, addr, true); + split_huge_pmd_address(migrate->vma, addr, false); ret = folio_split_unmapped(folio, 0); if (ret) return ret; -- 2.53.1-Meta