arch/x86_64: give the page allocator the physical page pool base.

mm_pginitialize() documents heap_start as "the physical address of the start
of memory region", and every x86_64 consumer of mm_pgalloc() agrees:
create_spgtables(), x86_64_get_pgtable() and up_addrenv_create() all put the
result through x86_64_pgvaddr() before touching it.  x86_64_pgvaddr() in turn
range-checks against CONFIG_ARCH_PGPOOL_PBASE (arch/x86_64/src/common/
pgalloc.h:67).  arm64's equivalent passes CONFIG_ARCH_PGPOOL_PBASE.

up_allocate_pgheap() passed CONFIG_ARCH_PGPOOL_VBASE instead, and in the
other branch X86_64_PGPOOL_BASE + X86_64_LOAD_OFFSET, which is the same
mistake spelled out.  Every page handed out was therefore a virtual address
that fell outside the pool's physical window, x86_64_pgvaddr() returned 0,
and the first x86_64_pgwipe() memset NULL.

It presents as a page fault in memset() under create_spgtables() the first
time a process address environment is created, which is loading the init
program.  qemu-intel64:knsh_romfs sets PGPOOL_PBASE=0x00c000000 and
PGPOOL_VBASE=0x10c000000, so the value passed was off by the 4GB load
offset.

Impact: runtime, CONFIG_ARCH_ADDRENV builds only (CONFIG_MM_PGALLOC).

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
This commit is contained in:
Marco Casaroli 2026-07-26 17:24:57 +02:00 committed by Xiang Xiao
parent 5f9edeb6e6
commit 3c8cfa307d

View file

@ -61,15 +61,17 @@ void up_allocate_pgheap(void **heap_start, size_t *heap_size)
{
DEBUGASSERT(heap_start && heap_size);
/* The page allocator uses physical addresses. */
#ifndef CONFIG_ARCH_PGPOOL_MAPPING
/* pgheap at the end of RAM */
*heap_start = (void *)(X86_64_PGPOOL_BASE + X86_64_LOAD_OFFSET);
*heap_start = (void *)X86_64_PGPOOL_BASE;
*heap_size = (size_t)X86_64_PGPOOL_SIZE;
#else
/* pgheap defined with Kconfig options */
*heap_start = (void *)CONFIG_ARCH_PGPOOL_VBASE;
*heap_start = (void *)CONFIG_ARCH_PGPOOL_PBASE;
*heap_size = (size_t)CONFIG_ARCH_PGPOOL_SIZE;
#endif
}