feat(mem): PMM 1GB-clamp + floor hardening, no-op at 128M (ADR-0021) - #213
Merged
Conversation
Groundwork for dynamic PMM sizing (ADR-0021), all no-ops at the current hardcoded 128 MB so it ships safely ahead of the mmap-driven sizing: - New PMM_PHYS_CEIL (0x40000000) / PMM_MAX_FRAMES (262144) in memory.h — the 1 GB ceiling boot.S already identity-maps (a dedicated constant, NOT USER_VBASE whose equal value is incidental). pmm_init clamps total_frames to it BEFORE narrowing to uint32 and before sizing the bitmap, so every frame the allocator can hand out is provably mappable (a >=1GB frame would be a #158-class escalation). - Static-layout floor: if reported RAM is below the kernel heap's backing frames, pmm_init boot_panics instead of letting kheap_init build on unbacked memory. - Guarded the kernel-image reservation loop with `&& i < total_frames` (mirrors the heap loop); asserted the frame bitmap can't overrun the kernel region past 0x01100000; widened the frame-address multiply to `(uintptr_t)i * PAGE_SIZE` (the clamp was the only thing preventing a 32-bit wrap in pmm_alloc_frame). Verified: WSL build clean (-Werror), ci-smoke boots to QuantumOS ready with PMMROVER + PMMHEAP self-tests green (the changes are inert at 128 M); clang-format-18 / api-consistency / cppcheck clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First increment of ADR-0021 (dynamic PMM sizing + 1 GB clamp), designed via an adversarial panel. This PR is the hardening groundwork — all changes are no-ops at the current hardcoded 128 MB, so it ships safely ahead of the mmap-driven sizing (PR-2/3/4).
The panel corrected the ADR's stale line refs and confirmed the work is small: the bitmap is already dynamic/self-sizing and
boot.Salready identity-maps the full 1 GB, so this is about the clamp + floor + overflow guards, not new allocation machinery.Changes (
kernel/src/memory.c,kernel/include/kernel/memory.h)PMM_PHYS_CEIL(0x40000000) /PMM_MAX_FRAMES(262144) — the 1 GB identity-map ceiling. A dedicated constant, deliberately notUSER_VBASE(its equal value is incidental — a user-half relocation must not silently move the physical ceiling).pmm_initclampstotal_framesto it before narrowing to uint32 and before sizing the bitmap, so every frame the allocator can hand out is provably mappable (a>= 1 GBframe is a HIGH: in_user_range validates the address range but not the page mapping — any ring-3 process can panic the kernel (DoS) #158-class escalation).pmm_initboot_panics instead of lettingkheap_initbuild on unbacked memory.&& i < total_frames(mirrors the heap loop), asserted the bitmap can't overrun the kernel region past0x01100000, and widened the frame-address multiply to(uintptr_t)i * PAGE_SIZE(the clamp was the only thing preventing a 32-bit wrap inpmm_alloc_frame).Verification
make BUILD_TYPE=debugclean (-Werror).make ci-smokeboots toQuantumOS readywith PMMROVER + PMMHEAP self-tests green — the changes are inert at 128 M.clang-format-18/check-api-consistency.sh/cppcheckclean.Next: PR-2 (synthetic clamp teeth-check), PR-3 (real mmap sizing), PR-4 (high-mem writeback proof + differential -m 256M/512M CI).
🤖 Generated with Claude Code