Re: [v2 04/16] mm/huge_memory: move softleaf_to_folio() inside migration branch
From: Zi Yan
Date: Sat Jun 13 2026 - 15:03:05 EST
On 2 Jun 2026, at 10:24, Usama Arif wrote:
> change_non_present_huge_pmd() calls softleaf_to_folio() unconditionally
> at the top of the function. softleaf_to_folio() extracts a PFN from
> the entry and converts it to a folio pointer, which is only meaningful
> for migration and device_private entries that encode a real PFN.
>
> A swap entry encodes a swap offset instead, so softleaf_to_folio()
> would produce a bogus pointer and crash on mprotect() when a PMD swap
> entry is present.
>
> Move the call into the migration_write branch where the folio is
> actually used, so the function is safe for any non-present PMD type.
>
> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Reviewed-by: Dev Jain <dev.jain@xxxxxxx>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> ---
> mm/huge_memory.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
LGTM.
Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
--
Best Regards,
Yan, Zi