refactor(starry): route HAL access through ax-runtime#963
Conversation
- 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.
There was a problem hiding this comment.
Review 总结
本 PR 对 Starry kernel 的 HAL 访问路径做了系统性重构,将所有 ax_hal / ax_cpu 直接依赖收敛到 ax_runtime::hal 统一入口。整体改动方向正确、实现质量良好。
核心改动审查
-
ax-runtime新增pub use ax_hal as hal;— 简洁明了,为所有下游提供稳定的 HAL 入口。 -
ax-hal新增pub use ax_cpu as cpu;— 保留了ax_hal::{asm, trap, context, uspace}兼容路径的同时,新增cpu命名空间,使得通过ax_runtime::hal::cpu可以访问 CPU 相关 API。 -
starry-kernel迁移 — 经过验证,kernel 源码中已无任何ax_hal::/ax_cpu::/use ax_hal/extern crate ax_hal的残留引用,迁移完整且一致。 -
starryos顶层清理 — 正确移除了extern crate ax_plat_riscv64_sg2002和extern crate axplat_riscv64_visionfive2,平台选择现在统一由ax-hal的 selected platform feature 机制处理。starry-kernel/Cargo.toml中对ax-hal的直接依赖也被移除。 -
axbuild 平台 feature 归一化 —
normalize_starry_platform_features将sg2002/vf2自动展开为ax-hal/riscv64-sg2002/ax-hal/riscv64-visionfive2;uses_default_qemu_platform现在通过default_starry_qemu_platform_feature精确识别 qemu 平台 feature,不会将 sg2002/vf2 误判为默认平台。配套测试用例load_cargo_config_treats_sg2002_as_explicit_platform_feature验证了完整行为。 -
配置文件同步 —
licheerv-nano-sg2002.toml和对应的 test-suit 配置都移除了myplatfeature,与新的平台选择逻辑保持一致。
次要观察
stop_machine.rs使用了ax_runtime::hal::{cpu_num, percpu::this_cpu_id, time::monotonic_time_nanos}——这些是通过pub use ax_hal as hal重新导出的,路径有效。cpu_num和percpu模块位于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.lock中arceos-wait-queue-remote-wake新增了ax-driver和ax-hal依赖(第三个 commitfix: 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
There was a problem hiding this comment.
Review 总结
本 PR 将 starry-kernel 对 ax-hal / ax-cpu 的直接依赖收敛到 ax_runtime::hal 统一入口,同时清理了 Starry 顶层对 platform crate 的重复引入,并调整了 axbuild 的平台 feature 归一化逻辑。
核心改动审查
-
ax-runtime新增pub use ax_hal as hal;— 简洁明了,为所有下游提供稳定的 HAL 入口。 -
ax-hal新增pub use ax_cpu as cpu;— 保留了ax_hal::{asm, trap, context, uspace}兼容路径的同时,新增cpu命名空间,使得通过ax_runtime::hal::cpu可以访问 CPU 相关 API。 -
starry-kernel迁移 — 经本地验证,kernel 源码中已无任何ax_hal::/ax_cpu::/use ax_hal/extern crate ax_hal的残留引用,迁移完整且一致。 -
starryos顶层清理 — 正确移除了extern crate ax_plat_riscv64_sg2002和extern crate axplat_riscv64_visionfive2,平台选择现在统一由ax-hal的 selected platform feature 机制处理。 -
axbuild 平台 feature 归一化 —
normalize_starry_platform_features将sg2002/vf2自动展开为ax-hal/riscv64-sg2002/ax-hal/riscv64-visionfive2;uses_default_qemu_platform通过default_starry_qemu_platform_feature精确识别 qemu 平台 feature,不会将 sg2002/vf2 误判为默认平台。配套测试验证了完整行为。 -
配置文件同步 —
licheerv-nano-sg2002.toml和对应的 test-suit 配置都移除了myplatfeature。
超出 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-dyn 的 used_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,涉及somehal、axplat-dyn、SG2002 平台 feature、axbuild 平台逻辑等。PR #963 的 axbuildnormalize_starry_platform_features和default_starry_qemu_platform_feature改动与 #961 的平台配置调整可能存在 partial-overlap / conflict-risk。两者合并时需注意 axbuild 平台归一化逻辑的一致性。 - PR #931 (
feat(starry-kernel): add initial GDB ptrace support):涉及starry-kernel的 syscall 和 trap 相关代码,与 #963 的trap.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 { |
There was a problem hiding this comment.
属性宏路径 #[ax_runtime::hal::cpu::trap::breakpoint_handler] 的解析链路:
ax_runtime::hal=ax_halax_hal::cpu=ax_cpu(viapub use ax_cpu as cpu)ax_cpu::trap是ax_cpucrate 的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); | |||
There was a problem hiding this comment.
IpiTarget 枚举的 cpu_id / cpu_num 字段携带了调用者已知的逻辑 CPU ID 信息,但在 GICv2/v3 的 send_ipi 实现中,Current variant 忽略了 cpu_id(直接用 SGITarget::Current),AllExceptCurrent 也忽略了 cpu_id 和 cpu_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 来覆盖此边界情况。
There was a problem hiding this comment.
Review 总结
本 PR 对 Starry kernel 的 HAL 访问路径做了系统性重构,将所有 ax_hal / ax_cpu 直接依赖收敛到 ax_runtime::hal 统一入口,同时清理了 Starry 顶层的平台 crate 依赖,并调整了 axbuild 的平台 feature 归一化逻辑。核心重构部分代码质量良好,迁移完整。
核心改动审查
-
ax-runtime新增pub use ax_hal as hal;— 简洁有效,为所有下游提供稳定的 HAL 入口。 -
ax-hal新增pub use ax_cpu as cpu;— 保留了ax_hal::{asm, trap, context, uspace}等现有导出路径的同时,新增cpu命名空间,路径可达性正确。 -
starry-kernel迁移完整 — 经本地grep验证,kernel 源码中已无任何ax_hal::/ax_cpu::/use ax_hal/extern crate ax_hal的残留引用。 -
starryos顶层清理 — 正确移除了extern crate ax_plat_riscv64_sg2002和extern crate axplat_riscv64_visionfive2,以及对应的 optional platform deps。smpfeature 也改为通过ax-hal/smp统一引入,逻辑一致。 -
axbuild 平台 feature 归一化 —
normalize_starry_platform_features将sg2002/vf2自动展开为ax-hal/riscv64-sg2002/ax-hal/riscv64-visionfive2;uses_default_qemu_platform通过default_starry_qemu_platform_feature精确匹配 qemu 平台 feature 名称,不会将 sg2002/vf2 误判为默认平台。配套测试load_cargo_config_treats_sg2002_as_explicit_platform_feature覆盖了关键路径。 -
配置文件同步 —
licheerv-nano-sg2002.toml和test-suit配置都移除了myplatfeature,与新逻辑一致。
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_argnightly feature 移除(第 5 个 commit)
建议后续将不相关的改动拆分到独立 PR,保持每个 PR 职责单一,便于 review 和 bisect。
验证
- 确认 kernel 中无
ax_hal/ax_cpu残留引用 ✅ ax-hal/ax-runtimere-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 { |
There was a problem hiding this comment.
路径解析链路:ax_runtime::hal = ax_hal,ax_hal::cpu = ax_cpu,ax_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))]) | ||
| } |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
hardware_cpu_id 在 cpu_idx_to_id 返回 None 时 fallback 到原始 cpu_id。对于无效的 CPU ID,这可能导致 IPI 发送到错误的目标。建议添加 debug_assert! 或 log 警告覆盖此边界情况。
There was a problem hiding this comment.
Review 总结
本 PR 将 starry-kernel 对 ax-hal / ax-cpu 的直接依赖收敛到 ax_runtime::hal 统一入口,清理了 Starry 顶层的平台 crate 依赖,并调整了 axbuild 的平台 feature 归一化逻辑。核心重构部分代码质量良好,迁移完整。
核心改动审查
-
ax-runtime新增pub use ax_hal as hal;— 简洁有效,为下游提供稳定的 HAL 入口。 -
ax-hal新增pub use ax_cpu as cpu;— 保留了ax_hal::{asm, trap, context, uspace}等现有导出路径,同时新增cpu命名空间,路径可达性正确。 -
starry-kernel迁移完整 — 经本地grep验证,kernel 源码中已无任何ax_hal::/ax_cpu::/use ax_hal/extern crate ax_hal的残留引用。 -
starryos顶层清理 — 正确移除了extern crate ax_plat_riscv64_sg2002和extern crate axplat_riscv64_visionfive2,以及对应的 optional platform deps。smpfeature 改为通过ax-hal/smp统一引入,逻辑一致。sg2002/vf2feature 直接映射到ax-hal/riscv64-sg2002/ax-hal/riscv64-visionfive2,消除了对ax-plat-riscv64-sg2002/axplat-riscv64-visionfive2的直接依赖。 -
axbuild 平台 feature 归一化 —
normalize_starry_platform_features将sg2002/vf2自动展开为ax-hal/riscv64-sg2002/ax-hal/riscv64-visionfive2;uses_default_qemu_platform通过default_starry_qemu_platform_feature精确匹配 QEMU 平台 feature,不会将 sg2002/vf2 误判为默认平台。配套测试load_cargo_config_treats_sg2002_as_explicit_platform_feature覆盖了关键路径。 -
配置文件同步 —
licheerv-nano-sg2002.toml和 test-suit 配置都移除了myplatfeature。
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 也收到 IPI。建议确认是否符合预期。 hardware_cpu_id在cpu_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_argnightly feature 移除(第 5 个 commit)- 测试迭代数缩减(第 6 个 commit)
建议后续将不相关的改动拆分到独立 PR,保持每个 PR 职责单一,便于 review 和 bisect。
验证
- ✅ kernel 中无
ax_hal/ax_cpu残留引用 - ✅
ax-hal/ax-runtimere-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 { |
There was a problem hiding this comment.
属性宏路径 #[ax_runtime::hal::cpu::trap::breakpoint_handler] 解析正确(ax_runtime::hal = ax_hal,ax_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))]) | ||
| } |
There was a problem hiding this comment.
GICv3 中 AllExceptCurrent 使用 SGITarget::All 会向所有 CPU(包括自身)发送 SGI,与 GICv2 实现中 SGITarget::AllOther 的语义不一致。
如果确实需要"除当前 CPU 外"的语义,建议:
- 在发送端构建排除当前 CPU 的 target list,或
- 改用
SGITarget::list()构建不含当前 CPU 的列表
如果当前 CPU 收到自身 IPI 是预期行为(例如 IPI handler 已做过滤),请在代码中添加注释说明。
| if v3::is_support_icc() { | ||
| v3::send_ipi(raw, target); | ||
| } else { | ||
| v2::send_ipi(raw, target); |
There was a problem hiding this comment.
hardware_cpu_id 在 cpu_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.
将 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/` 接口。
* 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.
…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.
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.
问题
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-kernel对ax-hal的直接 Cargo 依赖,并将 kernel 源码中的 HAL / CPU API 迁移到ax_runtime::hal与ax_runtime::hal::cpu。extern crate。sg2002/vf2feature 转为启用对应的ax-halplatform feature,并移除不再需要的直接 optional platform deps。myplat,避免与ax-hal/riscv64-sg2002平台 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 自身的
sg2002feature;axbuild 会在准备 Cargo feature 时补齐ax-hal/riscv64-sg2002,并据此设置AX_PLATFORM=riscv64-sg2002。验证
cargo fmt --checkcargo xtask clippy --package ax-hal --package ax-runtime --package starry-kernel --package starryoscargo xtask clippy --package axbuildcargo test -p axbuild load_cargo_config_treats_sg2002_as_explicit_platform_feature -- --nocapturerg -n "\\b(ax_hal|ax_cpu)::|use ax_hal|use ax_cpu|extern crate ax_hal|extern crate ax_cpu" os/StarryOS/kernelrg -n "extern crate ax_plat_riscv64_sg2002|extern crate axplat_riscv64_visionfive2" os/StarryOS/starryos/src/main.rscargo xtask starry build --arch x86_64cargo xtask starry build --config os/StarryOS/configs/board/licheerv-nano-sg2002.toml