Re: [PATCH v2] mm: page_isolation: avoid unsafe folio reads while scanning compound pages
From: David Hildenbrand (Arm)
Date: Tue Jun 02 2026 - 15:38:57 EST
On 6/2/26 21:31, Zi Yan wrote:
> On 2 Jun 2026, at 14:56, David Hildenbrand (Arm) wrote:
>
>> On 6/2/26 17:02, Zi Yan wrote:
>>>
>>>
>>> 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.
>>
>> If we use compound_nr, we have to check for power-of-2, like
>> scan_movable_pages(), as folio_large_nr_pages() might use the per-computed
>> value (which might read garbage).
>
> The power-of-2 requirement comes from “pfn | (nr_pages - 1)”, right?
Yes, you could end up stepping backwards, at least in the scan_movable_pages() case.
--
Cheers,
David