[PATCHv7 08/18] mm/sparse: Check memmap alignment for compound_info_has_mask()

Kiryl Shutsemau (Meta) posted 17 patches 1 month ago
[PATCHv7 08/18] mm/sparse: Check memmap alignment for compound_info_has_mask()
Posted by Kiryl Shutsemau (Meta) 1 month ago
From: Kiryl Shutsemau <kas@kernel.org>

If page->compound_info encodes a mask, it is expected that vmemmap to be
naturally aligned to the maximum folio size.

Add a VM_WARN_ON_ONCE() to check the alignment.

Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
Acked-by: Zi Yan <ziy@nvidia.com>
---
 mm/sparse.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/sparse.c b/mm/sparse.c
index b5b2b6f7041b..dfabe554adf8 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -600,6 +600,11 @@ void __init sparse_init(void)
 	BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
 	memblocks_present();
 
+	if (compound_info_has_mask()) {
+		VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0),
+				    MAX_FOLIO_VMEMMAP_ALIGN));
+	}
+
 	pnum_begin = first_present_section_nr();
 	nid_begin = sparse_early_nid(__nr_to_section(pnum_begin));
 
-- 
2.51.2
Re: [PATCHv7 08/18] mm/sparse: Check memmap alignment for compound_info_has_mask()
Posted by David Hildenbrand (Arm) 2 weeks, 2 days ago
On 2/27/26 20:42, Kiryl Shutsemau (Meta) wrote:
> From: Kiryl Shutsemau <kas@kernel.org>
> 
> If page->compound_info encodes a mask, it is expected that vmemmap to be
> naturally aligned to the maximum folio size.
> 
> Add a VM_WARN_ON_ONCE() to check the alignment.
> 
> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> Acked-by: Zi Yan <ziy@nvidia.com>
> ---
>  mm/sparse.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/mm/sparse.c b/mm/sparse.c
> index b5b2b6f7041b..dfabe554adf8 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -600,6 +600,11 @@ void __init sparse_init(void)
>  	BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
>  	memblocks_present();
>  
> +	if (compound_info_has_mask()) {
> +		VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0),
> +				    MAX_FOLIO_VMEMMAP_ALIGN));
> +	}

You could drop the {} or incorporate it into the VM_WARN_ON_ONCE

VM_WARN_ON_ONCE(compound_info_has_mask() &&
		!IS_ALIGNED((unsigned long) pfn_to_page(0),
			    MAX_FOLIO_VMEMMAP_ALIGN)

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David