Skip to content

arch/risc-v: initialize qemu-rv mmu pagetable data to zero - #19975

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Ruchirtripathi:fix-19874
Aug 26, 2026
Merged

arch/risc-v: initialize qemu-rv mmu pagetable data to zero#19975
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Ruchirtripathi:fix-19874

Conversation

@Ruchirtripathi

Copy link
Copy Markdown
Contributor

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.

jerpelea
jerpelea previously approved these changes Aug 26, 2026
@github-actions github-actions Bot added Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Size: XS The size of the change in this PR is very small labels Aug 26, 2026
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Fixes apache#19874

Signed-off-by: Ruchirtripathi <tripathiruchir05@gmail.com>
@xiaoxiang781216
xiaoxiang781216 merged commit 6a543b8 into apache:master Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] none-initialized pagetable data

4 participants