refactor(axvm): use generic nested page tables#1477
Merged
Conversation
ZR233
force-pushed
the
codex/axvm-nested-paging-generic
branch
from
July 2, 2026 07:35
3c5299e to
27ba423
Compare
ZR233
marked this pull request as ready for review
July 2, 2026 07:37
ZR233
force-pushed
the
codex/axvm-nested-paging-generic
branch
2 times, most recently
from
July 2, 2026 10:26
fc7eba4 to
de6c391
Compare
Contributor
There was a problem hiding this comment.
审查总结
变更内容:将嵌套页表(NPT)实现从 axaddrspace 解耦,迁移到 axvm::arch/<arch>/npt.rs,并为 RISC-V 添加真正的 Sv39x4/Sv48x4 G-stage 支持。
主要改动:
- 扩展
page-table-generic支持多帧 root、严格地址位宽检查和带层级的查询 - RISC-V 正确实现
Sv39x4(2048 entries/16KiB root,41-bit GPA)和Sv48x4(2048 entries/16KiB root,50-bit GPA) - AArch64 stage-2、x86 EPT/NPT、LoongArch stage-2 各自在 arch 模块内原生实现
- 移除编译期
ept-level-4feature,改用运行时硬件能力探测 - 用
NestedPagingConfig { root_paddr, levels, gpa_bits, mode }替代只传 root 的 vCPU 接口 - 新增 RISC-V
hgatpWARL 能力探测
影响范围:变更涉及 10 个 crate、82 个文件,但主要是代码迁移和重构,外部 API 通过 NestedPageTableOps trait 保持一致。axaddrspace 收敛为纯地址空间 facade,不再直接依赖架构页表实现。
CI 状态:28 个 check 成功,28 个 skipped(预期的 run_container 对应项),0 失败。
本地验证:
cargo fmt --check✅cargo test -p page-table-generic✅ (7 tests)cargo test -p page-table-generic --test riscv_x4✅ (5 tests)grep ept-level-4无残留 ✅
前置 PR:PR #1471(decouple axvisor arch logic)已合并,本 PR 是后续的 NPT 专项解耦,无冲突。
无已有 review comment。
结论:代码质量好,分层清晰,测试覆盖合理,无阻塞问题。建议合并。
Powered by mimo-v2.5-pro
ZR233
force-pushed
the
codex/axvm-nested-paging-generic
branch
from
July 3, 2026 01:23
de6c391 to
10075d1
Compare
Merged
Merged
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.
问题
当前 nested paging 的真实架构实现曾放在
axaddrspace中,导致通用地址空间管理和架构页表编码耦合;RISC-V G-stage 还依赖普通Sv39/Sv48元数据加 16KiB root 的局部补丁,无法正确表达Sv39x4/Sv48x4的 root quadrant、GPA 位宽和hgatp.MODE,高 GPA 场景存在 alias/miss 风险。改动
page-table-generic的表布局元数据,支持 root 与非 root 不同 entry 数、root 多 frame 分配/释放、严格地址位宽检查,并增加带命中层级的查询能力。Sv39x4/Sv48x4元数据:root 使用 2048 entries/16KiB,非 root 保持 512 entries/4KiB,并分别限制 41-bit/50-bit GPA。axaddrspace收敛为泛型地址空间 facade,只依赖NestedPageTableOps;移除axaddrspace对ax-page-table-entry、ax-page-table-multiarch以及arm-el2/svm/vmx空 feature 的依赖。axvm::arch/<arch>/npt.rs:AArch64 stage-2、x86 EPT/NPT、LoongArch stage-2、RISC-VSv39x4/Sv48x4都在各自 arch 目录内原生实现;共享代码只保留不区分架构的page-table-generic适配器。axvm对ax-page-table-entry、ax-page-table-multiarch的直接依赖;同时适配最新dev,删除axvm/plat-dynfeature,RISC-V 平台 IRQ 注入注册改为axvm::irqhost 接口,由axvisor侧调用axplat_dyn实现。ept-level-4/axvm/4-level-ept编译期开关,并同步清理 board 配置、test-suit 配置、axbuild 测试夹具和文档示例;nested page table 层级统一由硬件能力探测和 VM 配置在运行时选择。NestedPagingConfig { root_paddr, levels, gpa_bits, mode }替代只传 root 的 vCPU 接口,RISC-V vCPU 由 config 生成hgatp,不再硬编码模式。hgatpWARL 能力探测,优先选择所有目标 CPU 共同支持的最深Sv48x4/Sv39x4;AArch64 按 PA range 推导 3/4 级 stage-2 能力;x86/LoongArch 先通过同一 caps 接口暴露默认 4 级能力。方案逻辑
这次重构把通用地址空间管理、通用页表遍历/映射、架构真实 stage-2/G-stage 编码三层拆开:
page-table-generic负责布局驱动的页表操作,axaddrspace只负责地址空间 facade,axvm::arch/<arch>/npt.rs持有 root layout、PTE flags、mode encoding 和 TLB flush。这样 RISC-V 可以使用真正的Sv39x4/Sv48x4,AArch64/x86/LoongArch 也能在自己的 arch 模块内扩展不同页表级别或硬件能力。验证
cargo fmt --checkcargo test -p page-table-generic --test riscv_x4cargo test -p axaddrspacecargo check -p axaddrspace -p axvm-types -p axvm --target riscv64gc-unknown-none-elfcargo check -p axvm --no-default-features --features vmx --target x86_64-unknown-nonecargo check -p axvm --no-default-features --features svm --target x86_64-unknown-nonecargo check -p axvm --target aarch64-unknown-none-softfloatcargo check -p axvm --target loongarch64-unknown-none-softfloatcargo xtask clippy --package axvmcargo test -p axbuild --libcargo xtask clippy --package axbuildcargo xtask axvisor test qemu --arch x86_64 --test-group normal --test-case smoke-vmxrg -n "ept-level-4|4-level-ept" .(无残留)cargo xtask clippy --package axaddrspacecargo xtask clippy --package axvm-typescargo xtask clippy --since origin/devcargo xtask axvisor test qemu --arch riscv64