Re: [PATCHv2 2/5] mm/rmap: Fix a mlock race condition in folio_referenced_one()

From: Shakeel Butt

Date: Fri Sep 19 2025 - 17:19:05 EST


On Fri, Sep 19, 2025 at 01:40:33PM +0100, Kiryl Shutsemau wrote:
> From: Kiryl Shutsemau <kas@xxxxxxxxxx>
>
> The mlock_vma_folio() function requires the page table lock to be held
> in order to safely mlock the folio. However, folio_referenced_one()
> mlocks a large folios outside of the page_vma_mapped_walk() loop where
> the page table lock has already been dropped.
>
> Rework the mlock logic to use the same code path inside the loop for
> both large and small folios.
>
> Use PVMW_PGTABLE_CROSSED to detect when the folio is mapped across a
> page table boundary.
>
> Signed-off-by: Kiryl Shutsemau <kas@xxxxxxxxxx>

Nice, this simplifies the code.

Reviewed-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>