fix(starry): support eBPF ringbuf mmap on LoongArch DMW#1208
Conversation
Godones
commented
Jun 10, 2026
- update Starry eBPF integration for kbpf-basic 0.6 and kprobe 0.6 APIs
- add BPF map fd mmap support for non-contiguous ringbuf page lists
- support borrowed shared physical pages for device mmap backends
- move LoongArch kernel page-table-backed aspace out of the DMW direct-map range
- skip redundant DMW direct-map PTE insertion and allocate page-table-backed iomap aliases when needed
- add a shared kernel text patching helper and route kprobe through it
- handle LoongArch DMW kernel text patching without requiring PTE lookup/protect
- add clone syscall tracepoint coverage and adjust kprobe/uprobe manager usage
- document LoongArch DMW versus kernel page-table address-space rules
- update Starry eBPF integration for kbpf-basic 0.6 and kprobe 0.6 APIs - add BPF map fd mmap support for non-contiguous ringbuf page lists - support borrowed shared physical pages for device mmap backends - move LoongArch kernel page-table-backed aspace out of the DMW direct-map range - skip redundant DMW direct-map PTE insertion and allocate page-table-backed iomap aliases when needed - add a shared kernel text patching helper and route kprobe through it - handle LoongArch DMW kernel text patching without requiring PTE lookup/protect - add clone syscall tracepoint coverage and adjust kprobe/uprobe manager usage - document LoongArch DMW versus kernel page-table address-space rules Signed-off-by: Godones <chenlinfeng25@outlook.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates kernel virtual memory and probe/eBPF plumbing to support LoongArch64 DMW direct-map behavior and page-list-based device mmaps (e.g., BPF ringbuf), alongside kprobe/kbpf dependency upgrades.
Changes:
- Adjust LoongArch64 kernel aspace configuration and mapping logic to avoid DMW aliasing with page-table-backed VAs.
- Add
DeviceMmap::PhysicalPages+ borrowed shared-page backend support for non-contiguous physical page mappings. - Refactor kprobe/uprobe manager ownership/locking, add clone syscall tracepoint, and bump
kprobe/kbpf-basicversions.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/axbuild/scripts/starry-kallsyms.sh | Switches kallsyms padding to truncate for fixed-size output. |
| platforms/ax-plat-loongarch64-qemu-virt/axconfig.toml | Moves kernel aspace out of LoongArch64 DMW window. |
| os/arceos/modules/axmm/src/lib.rs | Skips mapping direct-map ranges outside kernel aspace; improves iomap for DMW platforms. |
| os/StarryOS/kernel/src/uprobe/mod.rs | Updates uprobe registration/handling to use new manager type. |
| os/StarryOS/kernel/src/task/mod.rs | Changes per-process uprobe manager storage from Mutex to direct value. |
| os/StarryOS/kernel/src/syscall/task/clone.rs | Adds sys_clone tracepoint event and emits it. |
| os/StarryOS/kernel/src/syscall/mm/mmap.rs | Adds mmap handling for DeviceMmap::PhysicalPages. |
| os/StarryOS/kernel/src/pseudofs/sysfs.rs | Tweaks sysfs CPU range string formatting. |
| os/StarryOS/kernel/src/pseudofs/device.rs | Extends DeviceMmap to support explicit physical page lists. |
| os/StarryOS/kernel/src/perf/kprobe.rs | Adjusts callback ownership model to Arc. |
| os/StarryOS/kernel/src/mm/aspace/backend/shared.rs | Adds “borrowed pages” mode to SharedPages with ownership tracking. |
| os/StarryOS/kernel/src/mm/aspace/backend/mod.rs | Renames/clarifies frame alloc/free helpers and docs. |
| os/StarryOS/kernel/src/mm/access.rs | Introduces patch_kernel_text for safe text patching (incl. LoongArch64 DMW). |
| os/StarryOS/kernel/src/kprobe.rs | Refactors global kprobe manager/list, retprobe instance storage, and selftest gating. |
| os/StarryOS/kernel/src/entry.rs | Switches from unconditional selftest to kprobe_test feature-gated test. |
| os/StarryOS/kernel/src/ebpf/transform.rs | Updates kbpf auxiliary ops API usage; adds vunmap with page counts. |
| os/StarryOS/kernel/src/ebpf/prog.rs | Updates ebpf preprocessor invocation for new generics. |
| os/StarryOS/kernel/src/ebpf/mod.rs | Wires KernelRawMutex into kbpf map ops calls. |
| os/StarryOS/kernel/src/ebpf/map.rs | Reworks unified map locking model; implements device_mmap for BPF maps. |
| os/StarryOS/kernel/Cargo.toml | Adds kprobe_test feature; bumps kprobe and kbpf-basic. |
| os/StarryOS/docs/loongarch64-dmw-kernel-aspace.md | Documents DMW vs page-table-backed aspace requirements and rationale. |
| Cargo.toml | Disables release LTO at the workspace level. |
Comments suppressed due to low confidence (2)
os/StarryOS/kernel/src/kprobe.rs:1
- This removes the previous uprobe fallback path (user-planted breakpoints) and now returns
falsewhenever the breakpoint isn’t a kernel kprobe. If the trap dispatch still relies onhandle_breakpointto also cover uprobes, user-space uprobes will stop working. Restore dispatch tocrate::uprobe::break_uprobe_handler(tf)when kernel kprobe handling returnsNone, or move that uprobe dispatch to the trap handler and keephandle_breakpointstrictly ‘kernel only’ (but then update callers accordingly).
//! Kernel probe (kprobe) subsystem for StarryOS.
os/StarryOS/kernel/src/kprobe.rs:1
- Using
try_lock().unwrap()can panic under contention. Since this is a spin lock (SpinNoIrq), it’s typically safe to use a blockinglock()here (especially for non-exception-context operations like probe registration) and avoid turning transient contention into a kernel panic. If you intentionally want a non-blocking path, return an error (orOption<R>) instead of unwrapping.
//! Kernel probe (kprobe) subsystem for StarryOS.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
评审总结
本 PR 对 StarryOS 内核进行了以下改动:
- eBPF/kprobe 依赖升级:
kbpf-basic0.5.7 → 0.6.0,kprobe0.5.5 → 0.6.0,API 适配(泛型MapLock参数、vunmap替换unmap、RetprobeInstance路径变更等) - BPF ringbuf mmap 支持:新增
DeviceMmap::PhysicalPages变体,支持非连续物理页列表的 mmap;新增BpfMap::device_mmap实现 - LoongArch64 DMW 内核地址空间:将内核页表地址空间移出 DMW 直接映射范围,跳过 DMW 区域 PTE 插入,为
iomap分配独立页表映射 - 内核文本补丁重构:抽取
patch_kernel_text通用函数,支持 LoongArch64 DMW 直接补丁路径(无需 PTE 查找/保护) - kprobe 管理器重构:全局管理器改为
static直接值(不再用Option),KprobeManager::new()初始化 - kprobe selftest 改造:旧的
run_selftest()替换为 feature-gatedkprobe_test(),支持 kprobe/kretprobe 双探针测试 - clone tracepoint:新增
sys_clonetracepoint 事件 - kretprobe 实例存储:支持当
current为 None 时回退到静态Vec存储
重复/重叠分析
- PR #1192(同一作者):"Modernize eBPF apps and add rawtp/upb2 demos" — 用户态 eBPF 应用侧改动。本 PR 是内核侧配套改动,两者互补,不冲突。作者在 PR 评论中也说明了这一点。
- 检查了 base 分支(
origin/dev)的近期提交,未发现与本 PR 重复或冲突的实现。
CI 状态
CI workflow run #27261162563 总体结论为 failure,原因是 Run clippy / run_host 任务被取消(而非因代码问题失败)。所有其他实际执行的测试任务均通过(success=17, cancelled=1, skipped=若干互斥的 run_container 任务)。Run clippy 任务的 "Run command" 步骤被取消,可能是基础设施超时。
本地 cargo clippy --manifest-path os/StarryOS/kernel/Cargo.toml --all-features -- -D warnings 通过,无警告。
本地验证
cargo fmt --check✓ 通过cargo clippy --manifest-path os/StarryOS/kernel/Cargo.toml --all-features -- -D warnings✓ 通过cargo clippy --manifest-path os/arceos/modules/axmm/Cargo.toml --all-features -- -D warnings✓ 通过
前人评审意见
Copilot bot 的评审指出了两个问题:
handle_breakpoint移除 uprobe 回退路径 — 该问题仍然存在且为阻塞性问题(见下方内联评论)try_lock().unwrap()可能 panic — 对于SpinNoIrq而言理论上安全,但不够优雅
阻塞性问题
uprobe 断点/单步分发路径被移除
handle_breakpoint 和 handle_debug 原来在非内核 kprobe 的情况下会回退到 crate::uprobe::break_uprobe_handler / crate::uprobe::debug_uprobe_handler,现在直接返回 false。uprobe/mod.rs 中的这两个 handler 函数仍然存在且被 pub 导出,但不再被任何 trap 路径调用。
这意味着用户态 uprobe 功能将完全失效。请恢复 uprobe 分发路径,或将 uprobe handler 注册为独立的 trap handler。
工作空间级 LTO 变更未说明
Cargo.toml 中将 lto = true 改为 lto = false。这是一个影响整个工作空间的构建配置变更,会改变所有 crate 的二进制大小和链接时优化行为。PR 描述和提交信息中均未提及此变更的原因。请说明为何需要此变更,或者如果这是意外修改请恢复。
Powered by deepseek-v4-pro
ZR233
left a comment
There was a problem hiding this comment.
复核了当前 head c113ec3,重点看了 BPF map mmap、DeviceMmap::PhysicalPages/SharedPages::borrowed、LoongArch DMW kernel aspace/iomap、kprobe/uprobe trap 路径。uprobe 断点/单步目前在 task/user.rs 的用户态 trap 路径中仍会分发,因此我没有把 kernel trap fallback 移除作为阻塞项。
重叠检查:#1192 主要是用户态 eBPF app;#1140/#1141/#1142/#1163 是 eBPF JIT/测试相关,未发现与本 PR 的 ringbuf mmap/LoongArch DMW 内核实现重复或冲突。
CI 检查:Starry x86_64 qemu 和 Run clippy 都是在构建过程中被取消,没有看到 Rust 编译错误或测试失败诊断;Axvisor board 失败在 U-Boot setenv autoload yes 连续超时,更像 self-hosted board/基础设施问题。
本地验证:git diff --check origin/dev...HEAD 通过;cargo xtask clippy --package starry-kernel 14/14 checks 通过。
但下面两个问题需要在合入前处理。
- wrap UnifiedMap in Arc so mmap retainers can keep map storage alive - pass the UnifiedMap Arc as the PhysicalPages retainer for BPF map mmap - prevent ringbuf VMAs from outliving their backing map pages after fd close - restore release LTO setting Signed-off-by: Godones <chenlinfeng25@outlook.com>
我已经修复这些问题 |
There was a problem hiding this comment.
复核总结
对 PR #1208 当前 head (c213e11) 进行复核,确认前一版本(c113ec3)中的两个阻塞性问题已在最新 commit 中解决。
之前阻塞性问题的修复情况
-
✅ BPF map mmap retainer 缺失(ZR233 指出):最新 commit
fix(starry-ebpf): pin BPF map pages across mmap lifetime已将BpfMap::unified_map包装为Arc<UnifiedMap<KernelRawMutex>>,并在device_mmap()中传递Some(retain),确保 VMA 存活期间 map 底层页不被释放。 -
✅ 工作空间级 LTO 关闭(ZR233 及 mai-team 指出):
Cargo.toml中的lto = true已恢复。 -
✅ uprobe 断点/单步分发路径(mai-team 指出):复核确认 uprobe 分发现由
task/user.rs中的用户态 trap 路径处理,不再依赖 kprobe kernel trap handler 的 fallback。ZR233 前次复核已确认此路径正确,我不将其作为阻塞项。
本地验证
cargo fmt --check✓ 通过cargo clippy --manifest-path os/StarryOS/kernel/Cargo.toml --all-features -- -D warnings✓ 通过cargo clippy --manifest-path os/arceos/modules/axmm/Cargo.toml --all-features -- -D warnings✓ 通过
CI 状态
当前 head 的 CI run #27275210408 正在执行中(Check formatting/run_host 和 Run sync-lint/run_container in_progress),其余互斥 job 为正常 skipped。Detect changed paths 和 Cancel stale CI runs 已成功。
crates.io patch 检查
工作空间中未发现 [patch.crates-io]。kbpf-basic 0.6.0 通过 crates.io 正常解析其依赖 ax-errno 0.6.0,与本地 workspace components/axerrno 隔离,符合规范。
非阻塞性观察
with_manager_and_list中使用try_lock().unwrap();在注册路径(非异常上下文)中该锁不会被竞争,实际安全。建议未来可考虑返回Option<R>或使用可阻塞的lock()。
重复/重叠分析
- PR #1192(同一作者)为用户态 eBPF app 侧改动,本 PR 为内核侧配套改动,互补不冲突。
- 检查了 base 分支及 #1140/#1141/#1142/#1163 等 eBPF 相关 PR,未发现重复或冲突实现。
结论
所有之前的阻塞性问题已修复,代码质量良好,本地验证通过。APPROVE。
Powered by deepseek-v4-pro
ZR233
left a comment
There was a problem hiding this comment.
复核当前 head c213e11addc769dc2cc2407e715cc41c368d02b9。
上一轮 request changes 的两个阻塞点已经解决:
BpfMap现在把UnifiedMap<KernelRawMutex>放进Arc,device_mmap()返回DeviceMmap::PhysicalPages(phy_addrs, Some(retain)),VMA 持有 borrowed ringbuf pages 时会 pin 住 map backing。- workspace
Cargo.toml的 releaselto = true已恢复,当前最终 diff 不再包含这个无关的全局构建策略改动。
本轮检查:review threads 已解析/过期;git diff --check origin/dev...HEAD 通过;未发现 [patch.crates-io];cargo xtask clippy --package starry-kernel 本地 14/14 checks 通过。current-head CI 已有 formatting、sync-lint、std、Starry aarch64/loongarch64 QEMU、ArceOS/Axvisor 多项成功;截至本次提交 review 时,Starry x86_64/riscv64 QEMU container jobs 仍在运行中但尚无失败。
未发现新的阻塞问题,批准。
* fix(starry): support eBPF ringbuf mmap on LoongArch DMW - update Starry eBPF integration for kbpf-basic 0.6 and kprobe 0.6 APIs - add BPF map fd mmap support for non-contiguous ringbuf page lists - support borrowed shared physical pages for device mmap backends - move LoongArch kernel page-table-backed aspace out of the DMW direct-map range - skip redundant DMW direct-map PTE insertion and allocate page-table-backed iomap aliases when needed - add a shared kernel text patching helper and route kprobe through it - handle LoongArch DMW kernel text patching without requiring PTE lookup/protect - add clone syscall tracepoint coverage and adjust kprobe/uprobe manager usage - document LoongArch DMW versus kernel page-table address-space rules Signed-off-by: Godones <chenlinfeng25@outlook.com> * fix typos Signed-off-by: Godones <chenlinfeng25@outlook.com> * fix(starry-ebpf): pin BPF map pages across mmap lifetime - wrap UnifiedMap in Arc so mmap retainers can keep map storage alive - pass the UnifiedMap Arc as the PhysicalPages retainer for BPF map mmap - prevent ringbuf VMAs from outliving their backing map pages after fd close - restore release LTO setting Signed-off-by: Godones <chenlinfeng25@outlook.com> --------- Signed-off-by: Godones <chenlinfeng25@outlook.com>