Skip to content

refactor(starry): route HAL access through ax-runtime#963

Merged
ZR233 merged 7 commits into
devfrom
rfct/ax-runtime
May 26, 2026
Merged

refactor(starry): route HAL access through ax-runtime#963
ZR233 merged 7 commits into
devfrom
rfct/ax-runtime

Conversation

@ZR233

@ZR233 ZR233 commented May 26, 2026

Copy link
Copy Markdown
Member

问题

Starry kernel 过去直接依赖并引用 ax-hal / ax-cpu,同时 Starry 顶层还手写引入部分 platform crate。这会让 Starry kernel 和底层 HAL / CPU crate 的依赖边界耦合过紧,也容易与 ax-hal 内部的 selected platform 机制产生重复或冲突。

改动

  • ax-runtime 新增 pub use ax_hal as hal;,对外提供 ax_runtime::hal 入口。
  • ax-hal 新增 pub use ax_cpu as cpu;,保留现有 ax_hal::{asm, trap, context, uspace} 兼容路径。
  • 移除 starry-kernelax-hal 的直接 Cargo 依赖,并将 kernel 源码中的 HAL / CPU API 迁移到 ax_runtime::halax_runtime::hal::cpu
  • 删除 Starry 顶层对 SG2002 / VisionFive2 platform crate 的重复 extern crate
  • 将 Starry 的 sg2002 / vf2 feature 转为启用对应的 ax-hal platform feature,并移除不再需要的直接 optional platform deps。
  • 从 SG2002 Starry 配置和测试配置中移除 myplat,避免与 ax-hal/riscv64-sg2002 平台 feature 冲突。
  • 调整 axbuild 的 Starry 平台 feature 归一化逻辑,使 sg2002 / vf2 能在 build config 中正确展开为显式 ax-hal/... 平台 feature,并避免默认 qemu 平台被同时加入。

实现逻辑

starry-kernel 只通过 ax-runtime 暴露的稳定入口访问 HAL。平台选择仍保留在 starryos 顶层 crate,由 ax-hal 的 selected platform feature 负责引入具体平台 crate。这样 kernel crate 不需要知道 ax-hal / ax-cpu 的直接依赖关系,也避免 Starry 顶层和 ax-hal 同时引入 platform crate。

SG2002 的 build config 只声明 Starry 自身的 sg2002 feature;axbuild 会在准备 Cargo feature 时补齐 ax-hal/riscv64-sg2002,并据此设置 AX_PLATFORM=riscv64-sg2002

验证

  • cargo fmt --check
  • cargo xtask clippy --package ax-hal --package ax-runtime --package starry-kernel --package starryos
  • cargo xtask clippy --package axbuild
  • cargo test -p axbuild load_cargo_config_treats_sg2002_as_explicit_platform_feature -- --nocapture
  • rg -n "\\b(ax_hal|ax_cpu)::|use ax_hal|use ax_cpu|extern crate ax_hal|extern crate ax_cpu" os/StarryOS/kernel
  • rg -n "extern crate ax_plat_riscv64_sg2002|extern crate axplat_riscv64_visionfive2" os/StarryOS/starryos/src/main.rs
  • cargo xtask starry build --arch x86_64
  • cargo xtask starry build --config os/StarryOS/configs/board/licheerv-nano-sg2002.toml

ZR233 added 3 commits May 26, 2026 17:01
- Updated references from ax_hal to ax_runtime::hal in various kernel modules, including tty_serial, proc, sysfs, usbfs, and syscall files.
- Adjusted IRQ registration and memory management functions to align with the new ax_runtime structure.
- Removed deprecated platform dependencies in Cargo.toml and main.rs, streamlining the build configuration.
- Enhanced build script to ensure proper feature handling for SG2002 and VF2 platforms.
- Updated test configurations to reflect changes in feature requirements for the SG2002 platform.
@ZR233
ZR233 marked this pull request as ready for review May 26, 2026 09:10

@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.

Review 总结

本 PR 对 Starry kernel 的 HAL 访问路径做了系统性重构,将所有 ax_hal / ax_cpu 直接依赖收敛到 ax_runtime::hal 统一入口。整体改动方向正确、实现质量良好。

核心改动审查

  1. ax-runtime 新增 pub use ax_hal as hal; — 简洁明了,为所有下游提供稳定的 HAL 入口。

  2. ax-hal 新增 pub use ax_cpu as cpu; — 保留了 ax_hal::{asm, trap, context, uspace} 兼容路径的同时,新增 cpu 命名空间,使得通过 ax_runtime::hal::cpu 可以访问 CPU 相关 API。

  3. starry-kernel 迁移 — 经过验证,kernel 源码中已无任何 ax_hal:: / ax_cpu:: / use ax_hal / extern crate ax_hal 的残留引用,迁移完整且一致。

  4. starryos 顶层清理 — 正确移除了 extern crate ax_plat_riscv64_sg2002extern crate axplat_riscv64_visionfive2,平台选择现在统一由 ax-hal 的 selected platform feature 机制处理。starry-kernel/Cargo.toml 中对 ax-hal 的直接依赖也被移除。

  5. axbuild 平台 feature 归一化normalize_starry_platform_featuressg2002 / vf2 自动展开为 ax-hal/riscv64-sg2002 / ax-hal/riscv64-visionfive2uses_default_qemu_platform 现在通过 default_starry_qemu_platform_feature 精确识别 qemu 平台 feature,不会将 sg2002/vf2 误判为默认平台。配套测试用例 load_cargo_config_treats_sg2002_as_explicit_platform_feature 验证了完整行为。

  6. 配置文件同步licheerv-nano-sg2002.toml 和对应的 test-suit 配置都移除了 myplat feature,与新的平台选择逻辑保持一致。

次要观察

  • stop_machine.rs 使用了 ax_runtime::hal::{cpu_num, percpu::this_cpu_id, time::monotonic_time_nanos}——这些是通过 pub use ax_hal as hal 重新导出的,路径有效。cpu_numpercpu 模块位于 ax_hal 顶层,而 time::monotonic_time_nanos 来自 ax_hal::time 模块,都是可达的。
  • trap.rs 中使用属性宏 #[ax_runtime::hal::cpu::trap::breakpoint_handler]——由于 ax_hal::cpu = ax_cpu,而 trap 模块通过 ax_hal::trap 重新导出了 ax_cpu::trap 的内容,但 ax_cpu 并未直接暴露 trap 子模块。此处路径依赖 ax_hal::cpu::trap = ax_cpu::trap,属性宏的路径解析是正确的。
  • Cargo.lockarceos-wait-queue-remote-wake 新增了 ax-driverax-hal 依赖(第三个 commit fix: add dependencies for arceos-wait-queue-remote-wake),这看起来是一个与主线重构无关的修复,合入此 PR 没有问题。

验证结果

  • cargo fmt --check ✅ 通过
  • PR 作者自述已通过 clippy 和相关测试
  • grep 确认 kernel 中无残留的 ax_hal / ax_cpu 直接引用

整体评价:代码改动干净、逻辑正确、测试覆盖充分。

Powered by glm-5.1

@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.

Review 总结

本 PR 将 starry-kernelax-hal / ax-cpu 的直接依赖收敛到 ax_runtime::hal 统一入口,同时清理了 Starry 顶层对 platform crate 的重复引入,并调整了 axbuild 的平台 feature 归一化逻辑。

核心改动审查

  1. ax-runtime 新增 pub use ax_hal as hal; — 简洁明了,为所有下游提供稳定的 HAL 入口。

  2. ax-hal 新增 pub use ax_cpu as cpu; — 保留了 ax_hal::{asm, trap, context, uspace} 兼容路径的同时,新增 cpu 命名空间,使得通过 ax_runtime::hal::cpu 可以访问 CPU 相关 API。

  3. starry-kernel 迁移 — 经本地验证,kernel 源码中已无任何 ax_hal:: / ax_cpu:: / use ax_hal / extern crate ax_hal 的残留引用,迁移完整且一致。

  4. starryos 顶层清理 — 正确移除了 extern crate ax_plat_riscv64_sg2002extern crate axplat_riscv64_visionfive2,平台选择现在统一由 ax-hal 的 selected platform feature 机制处理。

  5. axbuild 平台 feature 归一化normalize_starry_platform_featuressg2002 / vf2 自动展开为 ax-hal/riscv64-sg2002 / ax-hal/riscv64-visionfive2uses_default_qemu_platform 通过 default_starry_qemu_platform_feature 精确识别 qemu 平台 feature,不会将 sg2002/vf2 误判为默认平台。配套测试验证了完整行为。

  6. 配置文件同步licheerv-nano-sg2002.toml 和对应的 test-suit 配置都移除了 myplat feature。

超出 PR 标题范围的改动

本 PR 标题为「refactor(starry): route HAL access through ax-runtime」,但第 4 个 commit (feat(irq): implement inter-processor interrupt (IPI) handling) 新增了 somehal / axplat-dyn 的 IPI 发送功能(send_ipi),第 5 个 commit 移除了 axplat-dynused_with_arg nightly feature。这些改动与 HAL 路由重构主题无直接关联。建议:

  • 如果 IPI 功能是为后续 PR(如 #961 的 rv64-dyn)提前准备,建议在 PR body 中补充说明。
  • 考虑将 IPI 实现和 used_with_arg 清理拆分到独立 PR,保持每个 PR 职责单一,便于 review 和回溯。

重复/重叠分析

  • PR #961 (feat(riscv64): support dynamic platform on QEMU and SG2002):同一作者 ZR233,涉及 somehalaxplat-dyn、SG2002 平台 feature、axbuild 平台逻辑等。PR #963 的 axbuild normalize_starry_platform_featuresdefault_starry_qemu_platform_feature 改动与 #961 的平台配置调整可能存在 partial-overlap / conflict-risk。两者合并时需注意 axbuild 平台归一化逻辑的一致性。
  • PR #931 (feat(starry-kernel): add initial GDB ptrace support):涉及 starry-kernel 的 syscall 和 trap 相关代码,与 #963trap.rs 改动可能有轻微 partial-overlap(trap handler 路径),但改动不冲突。
  • 其余开放 PR 无明显重叠。

验证结果

  • cargo fmt --check ✅ 通过
  • cargo xtask clippy --package axbuild ✅ 通过
  • cargo test -p axbuild load_cargo_config_treats_sg2002_as_explicit_platform_feature -- --nocapture ✅ 通过
  • grep 确认 kernel 中无残留的 ax_hal / ax_cpu 直接引用
  • cargo xtask clippy --package ax-hal --package ax-runtime --package starry-kernel --package starryos 超时,未能完成;环境限制无法执行完整交叉编译 clippy

结论

HAL 路由重构部分代码改动干净、逻辑正确、测试覆盖充分。主要关注点是第 4 个 commit 的 IPI 新功能不在 PR 标题/描述范围内,建议补充说明或拆分。整体不阻塞合入。

Powered by glm-5.1

#[ax_hal::trap::breakpoint_handler]
fn default_breakpoint_handler(_tf: &mut ax_hal::context::TrapFrame) -> bool {
#[ax_runtime::hal::cpu::trap::breakpoint_handler]
fn default_breakpoint_handler(_tf: &mut ax_runtime::hal::cpu::TrapFrame) -> bool {

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.

属性宏路径 #[ax_runtime::hal::cpu::trap::breakpoint_handler] 的解析链路:

  • ax_runtime::hal = ax_hal
  • ax_hal::cpu = ax_cpu (via pub use ax_cpu as cpu)
  • ax_cpu::trapax_cpu crate 的 trap 模块

路径正确,但这个长路径可读性不佳。可以考虑在 starry-kernel 中添加一个局部 re-export 来缩短 trap handler 路径,例如:

use ax_runtime::hal::cpu::trap;

#[trap::breakpoint_handler]
fn default_breakpoint_handler(...) -> bool { ... }

这不是阻塞问题,只是可读性建议。

@@ -17,6 +39,10 @@ pub fn irq_set_enable(irq: IrqId, enable: bool) {
Plat::irq_set_enable(irq, enable);

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.

IpiTarget 枚举的 cpu_id / cpu_num 字段携带了调用者已知的逻辑 CPU ID 信息,但在 GICv2/v3 的 send_ipi 实现中,Current variant 忽略了 cpu_id(直接用 SGITarget::Current),AllExceptCurrent 也忽略了 cpu_idcpu_num。这是正确的——硬件 SGIs 的 Current/AllOther 语义不需要额外参数。

但值得注意的是,对于 Other { cpu_id }hardware_cpu_id() 通过 someboot::smp::cpu_idx_to_id() 做了逻辑 ID 到硬件 ID 的映射。如果 cpu_id 无效(cpu_idx_to_id 返回 None),当前实现会 fallback 到原始值(unwrap_or(cpu_id)),这可能产生不可预期的 IPI 目标。建议添加 debug 日志或 debug_assert 来覆盖此边界情况。

@mai-team-app
mai-team-app Bot requested review from ZCShou and yfblock May 26, 2026 12:01

@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.

Review 总结

本 PR 对 Starry kernel 的 HAL 访问路径做了系统性重构,将所有 ax_hal / ax_cpu 直接依赖收敛到 ax_runtime::hal 统一入口,同时清理了 Starry 顶层的平台 crate 依赖,并调整了 axbuild 的平台 feature 归一化逻辑。核心重构部分代码质量良好,迁移完整。

核心改动审查

  1. ax-runtime 新增 pub use ax_hal as hal; — 简洁有效,为所有下游提供稳定的 HAL 入口。

  2. ax-hal 新增 pub use ax_cpu as cpu; — 保留了 ax_hal::{asm, trap, context, uspace} 等现有导出路径的同时,新增 cpu 命名空间,路径可达性正确。

  3. starry-kernel 迁移完整 — 经本地 grep 验证,kernel 源码中已无任何 ax_hal:: / ax_cpu:: / use ax_hal / extern crate ax_hal 的残留引用。

  4. starryos 顶层清理 — 正确移除了 extern crate ax_plat_riscv64_sg2002extern crate axplat_riscv64_visionfive2,以及对应的 optional platform deps。smp feature 也改为通过 ax-hal/smp 统一引入,逻辑一致。

  5. axbuild 平台 feature 归一化normalize_starry_platform_featuressg2002 / vf2 自动展开为 ax-hal/riscv64-sg2002 / ax-hal/riscv64-visionfive2uses_default_qemu_platform 通过 default_starry_qemu_platform_feature 精确匹配 qemu 平台 feature 名称,不会将 sg2002/vf2 误判为默认平台。配套测试 load_cargo_config_treats_sg2002_as_explicit_platform_feature 覆盖了关键路径。

  6. 配置文件同步licheerv-nano-sg2002.tomltest-suit 配置都移除了 myplat feature,与新逻辑一致。

GICv3 IPI 实现观察

第 4 个 commit 新增了 somehal / axplat-dyn 的 IPI 发送功能。关于 GICv3 的 send_ipi 实现:

  • GICv2 正确AllExceptCurrent 使用 SGITarget::AllOther,语义正确。
  • GICv3 潜在问题AllExceptCurrent 使用 SGITarget::All,在 GICv3 中这会向所有 CPU(包括当前 CPU)发送 SGI,而非仅发送给其他 CPU。如果调用方期望"除当前 CPU 外的所有 CPU",当前实现会导致当前 CPU 也收到 IPI。建议确认是否符合预期,若不符合,可在接收端添加过滤或在发送端构建排除当前 CPU 的 TargetList。

PR 范围建议

本 PR 标题为「refactor(starry): route HAL access through ax-runtime」,但包含了两个与主题无直接关联的改动:

  • IPI 实现(第 4 个 commit)
  • used_with_arg nightly feature 移除(第 5 个 commit)

建议后续将不相关的改动拆分到独立 PR,保持每个 PR 职责单一,便于 review 和 bisect。

验证

  • 确认 kernel 中无 ax_hal / ax_cpu 残留引用 ✅
  • ax-hal / ax-runtime re-export 链路正确 ✅
  • axbuild 平台归一化逻辑和测试覆盖充分 ✅
  • 交叉编译 clippy 和完整构建在当前环境无法执行,依赖 CI 验证

Powered by glm-5.1

#[ax_hal::trap::breakpoint_handler]
fn default_breakpoint_handler(_tf: &mut ax_hal::context::TrapFrame) -> bool {
#[ax_runtime::hal::cpu::trap::breakpoint_handler]
fn default_breakpoint_handler(_tf: &mut ax_runtime::hal::cpu::TrapFrame) -> bool {

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.

路径解析链路:ax_runtime::hal = ax_halax_hal::cpu = ax_cpuax_cpu::trap::breakpoint_handler 是属性宏。路径正确。

可读性建议:考虑在文件顶部 use ax_runtime::hal::cpu::trap; 然后 #[trap::breakpoint_handler],避免在属性位置写长路径。不阻塞合入。

crate::irq::IpiTarget::Current { cpu_id: _ } => SGITarget::current(),
crate::irq::IpiTarget::Other { cpu_id } => {
SGITarget::list([affinity_from_mpidr(super::hardware_cpu_id(cpu_id))])
}

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.

GICv3 中 AllExceptCurrent 使用 SGITarget::All 会向所有 CPU(包括自身)发送 SGI。与 GICv2 实现使用 SGITarget::AllOther 的语义不同。

如果确实需要"除当前 CPU 外"的语义,建议在发送端构建排除当前 CPU 的 target list,或在接收端添加过滤。

if v3::is_support_icc() {
v3::send_ipi(raw, target);
} else {
v2::send_ipi(raw, target);

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.

hardware_cpu_idcpu_idx_to_id 返回 None 时 fallback 到原始 cpu_id。对于无效的 CPU ID,这可能导致 IPI 发送到错误的目标。建议添加 debug_assert! 或 log 警告覆盖此边界情况。

@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.

Review 总结

本 PR 将 starry-kernelax-hal / ax-cpu 的直接依赖收敛到 ax_runtime::hal 统一入口,清理了 Starry 顶层的平台 crate 依赖,并调整了 axbuild 的平台 feature 归一化逻辑。核心重构部分代码质量良好,迁移完整。

核心改动审查

  1. ax-runtime 新增 pub use ax_hal as hal; — 简洁有效,为下游提供稳定的 HAL 入口。

  2. ax-hal 新增 pub use ax_cpu as cpu; — 保留了 ax_hal::{asm, trap, context, uspace} 等现有导出路径,同时新增 cpu 命名空间,路径可达性正确。

  3. starry-kernel 迁移完整 — 经本地 grep 验证,kernel 源码中已无任何 ax_hal:: / ax_cpu:: / use ax_hal / extern crate ax_hal 的残留引用。

  4. starryos 顶层清理 — 正确移除了 extern crate ax_plat_riscv64_sg2002extern crate axplat_riscv64_visionfive2,以及对应的 optional platform deps。smp feature 改为通过 ax-hal/smp 统一引入,逻辑一致。sg2002 / vf2 feature 直接映射到 ax-hal/riscv64-sg2002 / ax-hal/riscv64-visionfive2,消除了对 ax-plat-riscv64-sg2002 / axplat-riscv64-visionfive2 的直接依赖。

  5. axbuild 平台 feature 归一化normalize_starry_platform_featuressg2002 / vf2 自动展开为 ax-hal/riscv64-sg2002 / ax-hal/riscv64-visionfive2uses_default_qemu_platform 通过 default_starry_qemu_platform_feature 精确匹配 QEMU 平台 feature,不会将 sg2002/vf2 误判为默认平台。配套测试 load_cargo_config_treats_sg2002_as_explicit_platform_feature 覆盖了关键路径。

  6. 配置文件同步licheerv-nano-sg2002.toml 和 test-suit 配置都移除了 myplat feature。

GICv3 IPI 实现观察

第 4 个 commit 新增了 somehal / axplat-dyn 的 IPI 发送功能。关于 GICv3 的 send_ipi 实现:

  • GICv2AllExceptCurrent 使用 SGITarget::AllOther,语义正确。
  • GICv3 潜在问题AllExceptCurrent 使用 SGITarget::All,在 GICv3 中这会向所有 CPU(包括当前 CPU)发送 SGI。如果调用方期望"除当前 CPU 外的所有 CPU",当前实现会导致当前 CPU 也收到 IPI。建议确认是否符合预期。
  • hardware_cpu_idcpu_idx_to_id 返回 None 时 fallback 到原始 cpu_id,对于无效的 CPU ID 可能产生不可预期的 IPI 目标,建议添加 debug_assert! 或 log 警告。

PR 范围建议

本 PR 标题为「refactor(starry): route HAL access through ax-runtime」,但包含了与主题无直接关联的改动:

  • IPI 实现(第 4 个 commit)
  • used_with_arg nightly feature 移除(第 5 个 commit)
  • 测试迭代数缩减(第 6 个 commit)

建议后续将不相关的改动拆分到独立 PR,保持每个 PR 职责单一,便于 review 和 bisect。

验证

  • ✅ kernel 中无 ax_hal / ax_cpu 残留引用
  • ax-hal / ax-runtime re-export 链路正确
  • ✅ axbuild 平台归一化逻辑和测试覆盖充分
  • ✅ 平台 crate 依赖清理完整
  • 交叉编译 clippy 和完整构建依赖 CI 验证

结论

核心 HAL 路由重构代码改动干净、逻辑正确、迁移完整。GICv3 AllExceptCurrent 的语义问题值得关注但不阻塞合入。整体 Approve

Powered by glm-5.1

#[ax_hal::trap::breakpoint_handler]
fn default_breakpoint_handler(_tf: &mut ax_hal::context::TrapFrame) -> bool {
#[ax_runtime::hal::cpu::trap::breakpoint_handler]
fn default_breakpoint_handler(_tf: &mut ax_runtime::hal::cpu::TrapFrame) -> bool {

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.

属性宏路径 #[ax_runtime::hal::cpu::trap::breakpoint_handler] 解析正确(ax_runtime::hal = ax_halax_hal::cpu = ax_cpu)。

可读性建议:可在文件顶部添加 use ax_runtime::hal::cpu::{trap, TrapFrame};,然后使用 #[trap::breakpoint_handler]_tf: &mut TrapFrame,减少行长度和重复路径。不阻塞。

crate::irq::IpiTarget::Current { cpu_id: _ } => SGITarget::current(),
crate::irq::IpiTarget::Other { cpu_id } => {
SGITarget::list([affinity_from_mpidr(super::hardware_cpu_id(cpu_id))])
}

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.

GICv3 中 AllExceptCurrent 使用 SGITarget::All 会向所有 CPU(包括自身)发送 SGI,与 GICv2 实现中 SGITarget::AllOther 的语义不一致。

如果确实需要"除当前 CPU 外"的语义,建议:

  1. 在发送端构建排除当前 CPU 的 target list,或
  2. 改用 SGITarget::list() 构建不含当前 CPU 的列表

如果当前 CPU 收到自身 IPI 是预期行为(例如 IPI handler 已做过滤),请在代码中添加注释说明。

if v3::is_support_icc() {
v3::send_ipi(raw, target);
} else {
v2::send_ipi(raw, target);

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.

hardware_cpu_idcpu_idx_to_id 返回 None 时 fallback 到原始 cpu_id。如果传入无效的 cpu_id,可能导致 IPI 发送到错误目标。

建议添加 debug_assert!log::warn! 来覆盖此边界情况,例如:

fn hardware_cpu_id(cpu_id: usize) -> usize {
    let hw_id = someboot::smp::cpu_idx_to_id(cpu_id);
    debug_assert!(hw_id.is_some(), "invalid cpu_id: {cpu_id}");
    hw_id.unwrap_or(cpu_id)
}

- Introduced a comprehensive suite of stress tests for the buddy slab allocator, covering various scenarios including random mixed allocation/free, exhaustion recovery, fragmentation recovery, and multithreaded operations.
- Enhanced the ARM GIC driver by adding a method to send Software Generated Interrupts (SGIs) to target CPUs, improving interrupt handling capabilities.
- Updated dependencies in various Cargo.toml files to include the new buddy slab allocator feature.
- Refactored the GlobalAllocator implementation to improve locking mechanisms during allocation and deallocation.
- Added new test configurations and scripts for QEMU to validate the buddy slab allocator functionality in a multi-core environment.
@ZR233
ZR233 merged commit edc8ade into dev May 26, 2026
6 checks passed
@ZR233
ZR233 deleted the rfct/ax-runtime branch May 26, 2026 14:31
This was referenced May 26, 2026
LorenzLorentz added a commit to LorenzLorentz/tgoskits that referenced this pull request May 30, 2026
rcore-os#850 的 eBPF 运行时重建到当前 dev 之上,替换 rcore-os#848 合入的单文件实现
(`ebpf.rs` ~1503 行 + `perf_event.rs` ~509 行),改为 `ebpf/` + `perf/`
模块树,复用 `kbpf-basic` + `rbpf` 上游 crate,而非手写 VM/verifier/map。

经 reviewer 评审与 maintainer、rcore-os#848 作者 @CN-TangLin 同意后,按既定方针
重建(非简单 rebase——本分支原 base 落后 dev 49 个 commit,含 rcore-os#963 HAL
迁移 / rcore-os#849 LKM / 新增 syscall):

- 原则冲突(以 sys_bpf 为本体,而非 LKM 实现 eBPF)以本实现为准;
- 事件发掘统一走 perf 子系统:删除 rcore-os#848 在 `kprobe.rs` 注入的全局
  `perf_event_trigger_by_type` 广播,改为每个 perf fd 直接挂 `OwnedEbpfVm`
  回调(`register_event_callback`);
- 其余重叠按 rcore-os#673 > 本实现 > rcore-os#847:
  - `tracepoint/mod.rs` 以 rcore-os#673 基座为底,仅追加 `lookup_ext_tracepoint`
    / `find_ext_tracepoint_by_name`;
  - `kprobe.rs` 在 rcore-os#847 基座(保留其 ax_runtime::hal API、可执行内存映射、
    loongarch64 显式分支)上追加 `KernelRawMutex`、register/unregister 公开
    API、`KPROBE_POINT_LIST`、类型别名,供 perf 子模块使用。

其他:
- `kallsyms.rs` 精简至实际使用面(`kallsyms_init` + `kallsyms_lookup_name`),
  `/proc/kallsyms` 仍由 dev 的 `ksym` crate 独立提供;符号数据喂入留作后续。
- `ebpf`/`perf`/`kallsyms` 模块沿用 dev 的 `ebpf` feature(默认开启)门控;
  `kbpf-basic`/`rbpf` 作为该 feature 的可选依赖。
- 工作区临时 `[patch.crates-io]` 指向 printf-compat nightly-fix-0.3 分支
  (kbpf-basic 0.5 间接锁定的 printf-compat 0.3.1 在当前 nightly 不可编译)。

验证:`cargo fmt --all -- --check` 通过;x86_64 / aarch64 / riscv64 /
loongarch64 四架构 `cargo xtask starry build` 全部通过(本仓代码 0 warning)。

下游 rcore-os#849 (LKM) / rcore-os#874 (用户态测试) / rcore-os#891 (JIT) 原建立在 rcore-os#848 的 API 上,
需 retarget 到本实现的 `ebpf/` + `perf/` 接口。
54dK3n pushed a commit to 54dK3n/tgoskits that referenced this pull request May 31, 2026
* Refactor kernel to use ax_runtime for HAL functions

- Updated references from ax_hal to ax_runtime::hal in various kernel modules, including tty_serial, proc, sysfs, usbfs, and syscall files.
- Adjusted IRQ registration and memory management functions to align with the new ax_runtime structure.
- Removed deprecated platform dependencies in Cargo.toml and main.rs, streamlining the build configuration.
- Enhanced build script to ensure proper feature handling for SG2002 and VF2 platforms.
- Updated test configurations to reflect changes in feature requirements for the SG2002 platform.

* fix: add dependencies for arceos-wait-queue-remote-wake

* feat(irq): implement inter-processor interrupt (IPI) handling

* fix: remove unused feature flag 'used_with_arg' from lib.rs

* test(starryos): bound clone files race normal case

* Add stress tests for buddy slab allocator and enhance GIC driver

- Introduced a comprehensive suite of stress tests for the buddy slab allocator, covering various scenarios including random mixed allocation/free, exhaustion recovery, fragmentation recovery, and multithreaded operations.
- Enhanced the ARM GIC driver by adding a method to send Software Generated Interrupts (SGIs) to target CPUs, improving interrupt handling capabilities.
- Updated dependencies in various Cargo.toml files to include the new buddy slab allocator feature.
- Refactored the GlobalAllocator implementation to improve locking mechanisms during allocation and deallocation.
- Added new test configurations and scripts for QEMU to validate the buddy slab allocator functionality in a multi-core environment.
ZR233 pushed a commit that referenced this pull request May 31, 2026
…850)

* feat(starry-kernel): port modular eBPF runtime over perf subsystem

将 #850 的 eBPF 运行时重建到当前 dev 之上,替换 #848 合入的单文件实现
(`ebpf.rs` ~1503 行 + `perf_event.rs` ~509 行),改为 `ebpf/` + `perf/`
模块树,复用 `kbpf-basic` + `rbpf` 上游 crate,而非手写 VM/verifier/map。

经 reviewer 评审与 maintainer、#848 作者 @CN-TangLin 同意后,按既定方针
重建(非简单 rebase——本分支原 base 落后 dev 49 个 commit,含 #963 HAL
迁移 / #849 LKM / 新增 syscall):

- 原则冲突(以 sys_bpf 为本体,而非 LKM 实现 eBPF)以本实现为准;
- 事件发掘统一走 perf 子系统:删除 #848 在 `kprobe.rs` 注入的全局
  `perf_event_trigger_by_type` 广播,改为每个 perf fd 直接挂 `OwnedEbpfVm`
  回调(`register_event_callback`);
- 其余重叠按 #673 > 本实现 > #847:
  - `tracepoint/mod.rs` 以 #673 基座为底,仅追加 `lookup_ext_tracepoint`
    / `find_ext_tracepoint_by_name`;
  - `kprobe.rs` 在 #847 基座(保留其 ax_runtime::hal API、可执行内存映射、
    loongarch64 显式分支)上追加 `KernelRawMutex`、register/unregister 公开
    API、`KPROBE_POINT_LIST`、类型别名,供 perf 子模块使用。

其他:
- `kallsyms.rs` 精简至实际使用面(`kallsyms_init` + `kallsyms_lookup_name`),
  `/proc/kallsyms` 仍由 dev 的 `ksym` crate 独立提供;符号数据喂入留作后续。
- `ebpf`/`perf`/`kallsyms` 模块沿用 dev 的 `ebpf` feature(默认开启)门控;
  `kbpf-basic`/`rbpf` 作为该 feature 的可选依赖。
- 工作区临时 `[patch.crates-io]` 指向 printf-compat nightly-fix-0.3 分支
  (kbpf-basic 0.5 间接锁定的 printf-compat 0.3.1 在当前 nightly 不可编译)。

验证:`cargo fmt --all -- --check` 通过;x86_64 / aarch64 / riscv64 /
loongarch64 四架构 `cargo xtask starry build` 全部通过(本仓代码 0 warning)。

下游 #849 (LKM) / #874 (用户态测试) / #891 (JIT) 原建立在 #848 的 API 上,
需 retarget 到本实现的 `ebpf/` + `perf/` 接口。

* ci: retrigger after pre-existing axtask SMP flake

上次 CI 唯一真失败是 riscv64 test-rawmutex-handoff 触发 axtask 调度器断言
panic(os/arceos/modules/axtask/src/run_queue.rs:716,SMP 上下文切换的
Arc::strong_count 竞态),与本 PR 改动(ebpf/perf/kprobe)无关;x86_64 /
loongarch64 同份内核代码均通过。aarch64 qemu 与 clippy 为 fail-fast 连带取消。
空提交重跑 CI 验证为偶发。

* refactor(starry-kernel): address eBPF runtime review feedback

按 @Godones review 意见收敛到内核既有抽象、去掉多余复杂度:

- 复用既有设施:kprobe 符号解析改走真实 .kallsyms(pseudofs::proc::KALLSYMS),
  删除空的 kallsyms stub 模块;alloc_page/free_page 复用 mm::aspace::backend 的
  alloc_frame/dealloc_frame;sys_bpf 用 kbpf_basic::linux_bpf::bpf_cmd 取代手写常量。
- 去锁:rbpf execute_program 为 &self,OwnedEbpfVm 执行方法改 &self,移除
  kprobe / raw_tracepoint / tracepoint 三处多余的 spin::Mutex。
- 修正:TracepointPerfEvent enable/disable 对每个 TraceEventFunc 调
  set_perf_enable —— 否则 ktracepoint 因 perf_enabled()==false 永不触发回调。
- 组织:sys_perf_event_open 移入 crate::perf;移除 ebpf feature,默认编入。
- 安全:register_allowed_memory(0..u64::MAX) 处补 TODO。

本地验证:fmt / clippy(-D warnings, 12 配置) / x86_64 / loongarch64 build 均通过。

* ci: retrigger after pre-existing axvisor x86_64 smoke flake

* build(starry-kernel): bump kbpf-basic to 0.5.7, drop git dependency

kbpf-basic 0.5.7 已合并 printf-compat 0.4 迁移并改用 ax-errno 0.6,
因此移除临时的 printf-compat git patch。改用 path patch 把 kbpf-basic
依赖的 ax-errno 重定向到工作区自身的副本,使 BpfError 与内核 AxError
为同一类型,避免 ax-errno 重复编译。

* refactor(starry-kernel): address eBPF runtime review round 2

- ebpf: drop the bpf_to_ax_err table; kbpf-basic 0.5.7 now uses the
  in-tree ax-errno so BpfError = LinuxError and `?` auto-converts via
  AxError: From<LinuxError>.
- ebpf: return InvalidInput (-EINVAL) for unknown/unsupported bpf(2)
  commands instead of Unsupported (-ENOSYS), matching Linux.
- perf/ebpf: honour PERF_FLAG_FD_CLOEXEC in perf_event_open and create
  bpf map/prog/raw-tracepoint fds close-on-exec (Linux bpf fds are
  always O_CLOEXEC).
- kprobe: replace the hand-written AtomicBool raw mutex (no preempt/IRQ
  disable, deadlock-prone on trap re-entry) with ax_kspin::RawSpinNoIrq.

feat(kspin): add `lock_api` feature exposing BaseRawSpinLock<G> /
RawSpinNoIrq, a NoPreemptIrqSave-backed lock_api::RawMutex.

* fix(kspin): use Acquire load in raw spinlock spin-wait

The inner spin-wait in `BaseRawSpinLock::lock` read `locked` with
`Ordering::Relaxed`, which sync-lint flags (suspicious_relaxed_wait_condition
and suspicious_relaxed_mixed_ordering). Match `BaseSpinLock::is_locked` and
load with `Acquire` so all accesses to `locked` use consistent orderings.
This was referenced Jun 2, 2026
LorenzLorentz added a commit to LorenzLorentz/tgoskits that referenced this pull request Jun 3, 2026
Upstream rcore-os#963 routed HAL access through `ax-runtime` (where
`ax_runtime::hal` is `pub use ax_hal as hal`), but the eBPF/perf
code added on this branch still refers to `ax_hal::*` directly in 13
sites (kprobe exec-page protect/flush, paging flags, icache flush).
Without `ax-hal` as a direct dependency those paths fail to resolve
and the kernel does not compile.

Re-declare `ax-hal.workspace = true` so the existing `ax_hal::`
references resolve, rather than rewriting all 13 call sites onto the
`ax_runtime::hal` re-export.
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