Skip to content

Commit 58d3f32

Browse files
6eanutLinux RISC-V bot
authored andcommitted
riscv/mm: use physical alignment for vmemmap_start_pfn
RISC-V computes vmemmap_start_pfn by rounding phys_ram_base down to VMEMMAP_ADDR_ALIGN. That alignment must therefore be expressed in the physical-address domain. Commit 476849b ("riscv/mm: align vmemmap to maximal folio size") attempted to account for the maximal folio alignment by feeding MAX_FOLIO_VMEMMAP_ALIGN directly into VMEMMAP_ADDR_ALIGN. However, MAX_FOLIO_VMEMMAP_ALIGN is measured in bytes of struct page storage, whereas VMEMMAP_ADDR_ALIGN is used to align a physical address. The mask-based compound_info encoding requires pfn_to_page(0) to be naturally aligned to MAX_FOLIO_VMEMMAP_ALIGN. Commit 9f94db4 ("mm/sparse: check memmap alignment for compound_info_has_mask()") added a check for that requirement and exposed the unit mismatch on systems such as QEMU virt, where the DRAM base is not aligned to MAX_FOLIO_NR_PAGES * PAGE_SIZE. Convert MAX_FOLIO_VMEMMAP_ALIGN to the equivalent physical alignment before using it in VMEMMAP_ADDR_ALIGN. This keeps the existing round_down() logic while making the resulting vmemmap base satisfy the mask-alignment requirement. Fixes: 476849b ("riscv/mm: align vmemmap to maximal folio size") Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Assisted-by: YuanSheng:DeepSeek-V4-Flash Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
1 parent 8ca72ef commit 58d3f32

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

arch/riscv/mm/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ EXPORT_SYMBOL(phys_ram_base);
6363

6464
#ifdef CONFIG_SPARSEMEM_VMEMMAP
6565
#define VMEMMAP_ADDR_ALIGN max(1ULL << SECTION_SIZE_BITS, \
66-
MAX_FOLIO_VMEMMAP_ALIGN)
66+
PFN_PHYS(MAX_FOLIO_VMEMMAP_ALIGN / \
67+
sizeof(struct page)))
6768

6869
unsigned long vmemmap_start_pfn __ro_after_init;
6970
EXPORT_SYMBOL(vmemmap_start_pfn);

0 commit comments

Comments
 (0)