Skip to content

refactor(axvm): use generic nested page tables#1477

Merged
ZR233 merged 1 commit into
rcore-os:devfrom
ZR233:codex/axvm-nested-paging-generic
Jul 3, 2026
Merged

refactor(axvm): use generic nested page tables#1477
ZR233 merged 1 commit into
rcore-os:devfrom
ZR233:codex/axvm-nested-paging-generic

Conversation

@ZR233

@ZR233 ZR233 commented Jul 2, 2026

Copy link
Copy Markdown
Member

问题

当前 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 分配/释放、严格地址位宽检查,并增加带命中层级的查询能力。
  • 在 RISC-V 上新增真正的 G-stage Sv39x4/Sv48x4 元数据:root 使用 2048 entries/16KiB,非 root 保持 512 entries/4KiB,并分别限制 41-bit/50-bit GPA。
  • axaddrspace 收敛为泛型地址空间 facade,只依赖 NestedPageTableOps;移除 axaddrspaceax-page-table-entryax-page-table-multiarch 以及 arm-el2/svm/vmx 空 feature 的依赖。
  • 将真实 NPT 实现迁到 axvm::arch/<arch>/npt.rs:AArch64 stage-2、x86 EPT/NPT、LoongArch stage-2、RISC-V Sv39x4/Sv48x4 都在各自 arch 目录内原生实现;共享代码只保留不区分架构的 page-table-generic 适配器。
  • 移除 axvmax-page-table-entryax-page-table-multiarch 的直接依赖;同时适配最新 dev,删除 axvm/plat-dyn feature,RISC-V 平台 IRQ 注入注册改为 axvm::irq host 接口,由 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,不再硬编码模式。
  • 调整 VM prepare 顺序:先按目标物理 CPU 能力求交集并选择 nested paging 模式,再创建 arch-specific NPT、映射 guest memory/device,最后用同一份 config 设置所有 vCPU。
  • 增加 RISC-V hgatp WARL 能力探测,优先选择所有目标 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 模块内扩展不同页表级别或硬件能力。

验证

Rebase: 已于 2026-07-03 更新到最新 origin/dev (d80da3cdb2b3f9b307c7cb642df29f42863598c6),当前 PR head 为 10075d12ccddc63346748becd4aba7b5211b8758

  • cargo fmt --check
  • cargo test -p page-table-generic --test riscv_x4
  • cargo test -p axaddrspace
  • cargo check -p axaddrspace -p axvm-types -p axvm --target riscv64gc-unknown-none-elf
  • cargo check -p axvm --no-default-features --features vmx --target x86_64-unknown-none
  • cargo check -p axvm --no-default-features --features svm --target x86_64-unknown-none
  • cargo check -p axvm --target aarch64-unknown-none-softfloat
  • cargo check -p axvm --target loongarch64-unknown-none-softfloat
  • cargo xtask clippy --package axvm
  • cargo test -p axbuild --lib
  • cargo xtask clippy --package axbuild
  • cargo xtask axvisor test qemu --arch x86_64 --test-group normal --test-case smoke-vmx
  • rg -n "ept-level-4|4-level-ept" .(无残留)
  • cargo xtask clippy --package axaddrspace
  • cargo xtask clippy --package axvm-types
  • cargo xtask clippy --since origin/dev
  • cargo xtask axvisor test qemu --arch riscv64

@ZR233
ZR233 force-pushed the codex/axvm-nested-paging-generic branch from 3c5299e to 27ba423 Compare July 2, 2026 07:35
@ZR233
ZR233 marked this pull request as ready for review July 2, 2026 07:37
@ZR233
ZR233 force-pushed the codex/axvm-nested-paging-generic branch 2 times, most recently from fc7eba4 to de6c391 Compare July 2, 2026 10:26

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查总结

变更内容:将嵌套页表(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-4 feature,改用运行时硬件能力探测
  • NestedPagingConfig { root_paddr, levels, gpa_bits, mode } 替代只传 root 的 vCPU 接口
  • 新增 RISC-V hgatp WARL 能力探测

影响范围:变更涉及 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
ZR233 force-pushed the codex/axvm-nested-paging-generic branch from de6c391 to 10075d1 Compare July 3, 2026 01:23
@ZR233
ZR233 merged commit f69e7e2 into rcore-os:dev Jul 3, 2026
56 checks passed
@ZR233
ZR233 deleted the codex/axvm-nested-paging-generic branch July 3, 2026 01:50
@github-actions github-actions Bot mentioned this pull request Jul 3, 2026
@github-actions github-actions Bot mentioned this pull request Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant