Skip to main content

ensure_kernel_subtree_ready

Function ensure_kernel_subtree_ready 

Source
fn ensure_kernel_subtree_ready(token: &IrqDisabledToken)
Expand description

Pre-allocate the intermediate page-table nodes (PML4 → PDPT → PD) for the vmalloc virtual address range in the canonical kernel page table.

§Why this is necessary

Every new user address space clones PML4[256..512] from the kernel L4 at creation time. If the PDPT/PD nodes for the vmalloc arena do not exist at that point, the new address space inherits PML4[256] = 0 (not present). Any subsequent kernel access to a vmalloc address in that process’s context will fault, because its page-table walk stops at the missing PML4 entry.

By mapping a page at VMALLOC_VIRT_START during init() and keeping that mapping (see bootstrap_frame), we force the page-table allocator to create and wire all intermediate nodes. The leaf mapping anchors the subtree; the allocatable arena begins at page 1 so callers never receive the bootstrap virtual address.

§Caller contract

Called only from init(), which runs before any user address space is created. Do not call this from vmalloc(): the check (subtree_ready) would always succeed after boot and would add a gratuitous VMALLOC lock acquire on every allocation hot path.