arch/risc-v: initialize qemu-rv mmu pagetable data to zero - #19975
Merged
Conversation
Ruchirtripathi
requested review from
masayuki2009,
pussuw and
simbit18
as code owners
August 26, 2026 11:07
jerpelea
previously approved these changes
Aug 26, 2026
Fixes apache#19874 Signed-off-by: Ruchirtripathi <tripathiruchir05@gmail.com>
Ruchirtripathi
force-pushed
the
fix-19874
branch
from
August 26, 2026 11:49
563cca9 to
0fd9d22
Compare
acassis
approved these changes
Aug 26, 2026
xiaoxiang781216
approved these changes
Aug 26, 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.
Fixes #19874
Note: Please adhere to Contributing Guidelines https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md.
Summary
When running QEMU with a backend file to simulate RAM with randomized or uninitialized data, the MMU page tables
contain garbage values. This occurs because the m_l1_pgtable, m_l2_pgtable, and m_l3_pgtable structures are placed
in the .pgtables section, which is marked as NONLOAD in the linker script.
Because they aren't zeroed out alongside .bss during initialization, qemu_rv_kernel_mappings() incorrectly uses this
uninitialized memory when configuring the MMU, causing mmu_ln_getentry to fetch invalid mappings and fail.
This PR fixes the issue by explicitly calling memset() to zero-initialize the L1/L2/L3 page tables at the beginning
of qemu_rv_kernel_mappings() prior to setting up the slab allocator.
Impact
• Users: Resolves boot failures for users running qemu-rv boards on QEMU with simulated/randomized RAM backend files.
• Architecture: Changes are strictly confined to the qemu-rv RISC-V architecture memory initialization logic. No
impact on other targets.
• Build/Hardware: No build or hardware compatibility impact.
Testing
• Host machine: Ubuntu 24.04 (Host QEMU 10.0.0)
• Target: qemu-rv (rv32 / rv64)
• Testing procedure:
1. Configured NuttX for the qemu-rv target.
2. Booted the resulting image using QEMU with a backend file simulating randomly initialized RAM.
3. Verified that the map_region MMU logic correctly allocates from the zero-initialized page tables, and the
kernel boots smoothly without faults.