Re: [PATCH v2 25/31] mm/ksm: look up the folio again in cmp_and_merge_page()

From: Rik van Riel

Date: Fri Dec 04 2026 - 22:16:19 EST


On Fri, 2026-12-04 at 13:50 +0100, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason@xxxxxxxxxx>
>
> try_to_merge_two_pages() gets a page (not a folio) passed and can end
> up splitting a large folio in try_to_merge_one_page().
>
> However, cmp_and_merge_page() does not look up the page's folio again
> after possibly splitting it, but compares the stale folio against
> tree_folio since commit a35d8872dae7 ("mm: remove
> PageTransCompound()").
>
> Consequently, we can end up locking a folio we hold no reference on
> and
> never unlocking it, but unlocking another folio that someone else
> might
> have locked instead.
>
> Let's fix it by looking up the folio after calling
> try_to_merge_two_pages().
>
> This has medium urgency, as ksmd can leave a folio locked.
>
> Fixes: a35d8872dae7 ("mm: remove PageTransCompound()")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ david: simplify comment and description ]
> Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> Reviewed-by: Xu Xin (vivo) <xu.xin@xxxxxxxxx>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

Reviewed-by: Rik van Riel <riel@xxxxxxxxxxx>
--
All Rights Reversed.