Re: [PATCH] mm/migrate_device: fix folio refcount leak on folio_split_unmapped failure

From: Usama Arif

Date: Fri Mar 06 2026 - 05:47:58 EST



>
> I do not think there is a need to explain why there is no folio_put()
> below. How about below?
>
> 1. it makes sure the folio has the right ref count,
> 2. it explains folio_get() is for split_huge_pmd_address() instead of
> folio_split_unmapped().
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 0a8b31939640f..0b31b878210ba 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -914,8 +914,14 @@ static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate,
> unsigned long flags;
> int ret = 0;
>
> + VM_WARN_ON_ONCE(folio_ref_count(folio) == 1);

Thanks! I have sent it in [1]. One thing is, I think you mean over here
folio_ref_count(folio) != 1, right? Thats what the patch has.


[1] https://lore.kernel.org/all/20260306104409.3915811-1-usama.arif@xxxxxxxxx/

> + /*
> + * 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);
> +
> ret = folio_split_unmapped(folio, 0);
> if (ret)
> return ret;
>
>
>>
>>>>
>>>>
>>>> [1] https://gist.github.com/uarif1/65e1e816af7aa0ae38dd6ec64d62a993
>>>> [2] https://gist.github.com/uarif1/79ea9500667daa4e2ef09cb5d308f041
>>>> [3] https://gist.github.com/uarif1/8a35a6c65ba8b3a1c1dfe72dc30e821d
>>>
>>>
>>> Best Regards,
>>> Yan, Zi
>
>
> Best Regards,
> Yan, Zi