Re: [PATCH] mm/compaction: guard move_freelist_head() against invalid freepage
From: Giorgi Tchankvetadze
Date: Thu Jun 04 2026 - 08:59:59 EST
On Tue, Jun 2, 2026 at 12:44 AM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Seems correct from my reading. That code is rather twisty.
>
> > This issue was identified via Coccinelle (use_after_iter.cocci).
>
> But AI review is worried:
> https://sashiko.dev/#/patchset/20260601133941.111989-2-giorgitchankvetadze1997@xxxxxxxxx
>
>
Hey Andrew. Thanks for the review. Yes, Sashiko is right. This seems
to be deeper than I initially thought.
My patch is too broad and skips the freelist rotation mechanism when
the scan reached the limit without finding a suitable page. In that
case page is NULL, but freepage still points to the last scanned real
entry, so the rotation should be preserved to avoid retrying the same
unsuitable tail entries.
I'm thinking of assigning freepage to NULL like this :
struct page *freepage = NULL;
and later checking:
if (freepage)
move_freelist_head(freelist, freepage);