Re: [PATCH v2] mm: page_isolation: avoid unsafe folio reads while scanning compound pages
From: Zi Yan
Date: Tue Jun 02 2026 - 13:46:31 EST
On 2 Jun 2026, at 13:11, Andrew Morton wrote:
> On Tue, 02 Jun 2026 11:02:41 -0400 Zi Yan <ziy@xxxxxxxxxx> wrote:
>
>>> - *step = folio_nr_pages(folio) - folio_page_idx(folio, page);
>>> + nr_pages = 1UL << order;
>>> + pfn = page_to_pfn(page);
>>> + *step = (pfn | (nr_pages - 1)) + 1 - pfn;
>>> return false;
>>> }
>>
>> LGTM. Thanks.
>>
>> Just a comment, order can be dropped and use
>> nr_pages = compound_nr(&folio->page) instead:
>> 1. order > MAX_FOLIO_ORDER -> nr_pages > MAX_FOLIO_NR_PAGES
>> 2. PAGE_SIZE << order -> PAGE_SIZE * nr_pages.
>> But it is not worth a new version.
>>
>> Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
>
> Thanks, I queued this.
>
> What are we to make of Sashiko's question?
> https://sashiko.dev/#/patchset/20260602130755.38794-1-kaitao.cheng@xxxxxxxxx
Sashiko asked if compound_order() returns bogus order and the code
can skip checking unmovable pages and return false negative (the
range has unmovable pages but returning false), leading to offline
in-use memory.
Answer is no. 1. order > MAX_FOLIO_ORDER restricts the number of
skipped pages; 2. the actual users of page_is_unmovable(), alloc_contig_range()
or hot offline, will perform page migration and unmovable pages
will fail the migration and prevent these users from doing
anything.
Best Regards,
Yan, Zi