Re: [PATCHv6 09/17] mm/sparse: Check memmap alignment for compound_info_has_mask()

David Hildenbrand (Arm)
2026-02-05T13:59:06Z

On 2/5/26 14:31, David Hildenbrand (Arm) wrote:
> On 2/2/26 16:56, Kiryl Shutsemau wrote:
>> If page->compound_info encodes a mask, it is expected that vmemmap to be
>> naturally aligned to the maximum folio size.
>>
>> Add a VM_BUG_ON() to check the alignment.
>>
>> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
>> Acked-by: Zi Yan <ziy@nvidia.com>
>> ---
>>   mm/sparse.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/mm/sparse.c b/mm/sparse.c
>> index b5b2b6f7041b..6c9b62607f3f 100644
>> --- a/mm/sparse.c
>> +++ b/mm/sparse.c
>> @@ -600,6 +600,13 @@ void __init sparse_init(void)
>>       BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
>>       memblocks_present();
>> +    if (compound_info_has_mask()) {
>> +        unsigned long alignment;
>> +
>> +        alignment = MAX_FOLIO_NR_PAGES * sizeof(struct page);
>> +        VM_BUG_ON(!IS_ALIGNED((unsigned long) pfn_to_page(0),
>> alignment));
>
> No VM_BUG_ON. VM_WARN_ON_ONCE() should be good enough, no?
>
> As discussed in the other thread, is checking for MAX_FOLIO_NR_PAGES
> alignment sufficient?

And after further discussions, we could use MAX_FOLIO_VMEMMAP_ALIGN
macro once we have that.

--
Cheers,

David