feat(starry-kernel): add LKM support via kmod-loader integration#849
Conversation
ebbb74c to
d9dcebe
Compare
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate,实现 init_module / delete_module / finit_module 系统调用。新增 kmod_loader.rs(~180 行)包含页对齐内存分配、ELF section 权限映射和系统调用入口。同时基于 feat/starry-ebpf 分支,包含 ebpf.rs、kprobe.rs、perf_event.rs 等前置代码。附带 7 个错误路径 C 测试用例。
实现逻辑
KmodSectionMem通过alloc实现页对齐内存分配,change_perms通过修改页表实现 R/W/X 权限切换,设计合理。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数,之后forget使模块常驻内存。符合当前无卸载实现的设计。sys_delete_module/sys_finit_module为桩实现,返回Unsupported,待后续完善。- 系统调用路由在
syscall/mod.rs中正确注册,同时将bpf和perf_event_open从 dummy_fd 移至实际处理。
验证结果
- ✅
cargo fmt --check通过 ⚠️ cargo clippy --manifest-path os/StarryOS/kernel/Cargo.toml --all-features编译失败,错误来自ax-hal/kcov.rs:82(__PERCPU_IN_KCOV_TRACE未定义),属于基础分支的已有问题,非本 PR 引入。⚠️ CI 状态:mergeable_state=unstable,无法确认是否有 CI 流水线在运行。
阻断性问题
-
测试安装路径错误:
test-kmod-loader/c/CMakeLists.txt将二进制安装到usr/bin,而syscall测试组的test_commands(qemu-*.toml)遍历/usr/bin/starry-test-suit/*。同目录下所有其他测试(如test-kill-tgkill、test-close、test-write等)均安装到usr/bin/starry-test-suit。此测试将不会被测试运行器发现和执行。 -
KmodSectionMemnull 指针 Drop 未定义行为:当vmalloc分配失败时,StarryKmodHelper::vmalloc创建一个ptr为null_mut()的KmodSectionMem,但其Drop实现调用dealloc(self.ptr, self.layout)。Rust 要求dealloc的指针必须是由同一分配器以相同 layout 分配的非空指针,对 null 指针调用dealloc是未定义行为,可能导致内核崩溃。应改为返回Err或使用Option表示分配失败。
建议性意见
-
core::mem::forget(owner)(第 155 行)使模块资源常驻内存,这是当前无卸载功能下的合理选择,但建议添加注释说明forget的意图和未来delete_module实现时的释放计划。 -
flsuh_cache方法名来自上游kmod-loadercrate 的 trait 定义(拼写错误),PR 实现正确,可考虑向上游提 issue 修正。
未解决的审查会话
无历史审查会话。
结论
需要修复上述两个阻断性问题后方可合并。
Powered by mimo-v2.5-pro
| set(CMAKE_C_EXTENSIONS OFF) | ||
| add_executable(test-kmod-loader src/main.c) | ||
| target_compile_options(test-kmod-loader PRIVATE -Wall -Wextra -Werror) | ||
| install(TARGETS test-kmod-loader RUNTIME DESTINATION usr/bin) |
There was a problem hiding this comment.
🐛 阻断:安装路径错误
此处安装目标为 usr/bin,但 qemu-smp1/syscall/qemu-x86_64.toml 的 test_commands 遍历 /usr/bin/starry-test-suit/*。同目录下所有其他测试均安装到 usr/bin/starry-test-suit。
修复方式:
install(TARGETS test-kmod-loader RUNTIME DESTINATION usr/bin/starry-test-suit)当前路径下测试不会被分组测试运行器发现,等于没有 CI 覆盖。
|
|
||
| impl Drop for KmodSectionMem { | ||
| fn drop(&mut self) { | ||
| unsafe { dealloc(self.ptr, self.layout) }; |
There was a problem hiding this comment.
🐛 阻断:null 指针调用 dealloc 是未定义行为
此处 Drop 对 self.ptr 调用 dealloc。当上方 vmalloc 分配失败时(第 93-97 行),会创建 ptr: null_mut() 的实例。Rust 的 dealloc 要求指针必须是由同一 layout 从分配器获取的非空指针,对 null 指针调用是 UB。
建议修复方式:
- 将
vmalloc的失败情况改为返回Err,或使用Option<Box<dyn SectionMemOps>> - 或在
Drop中添加 null 检查:if !self.ptr.is_null() { unsafe { dealloc(self.ptr, self.layout) }; }
后者虽然简单但更安全,且应同时在 as_ptr/as_mut_ptr/change_perms 中处理 null 情况。
| Some(mem) => Box::new(mem), | ||
| None => { | ||
| warn!("kmod: vmalloc failed for size {size}"); | ||
| Box::new(KmodSectionMem { |
There was a problem hiding this comment.
此处创建的 null 指针 KmodSectionMem 在 drop 时会导致 UB(见上方 Drop 注释)。建议改为:
None => {
warn!("kmod: vmalloc failed for size {size}");
// 返回一个安全的空操作实现,或让调用方处理错误
alloc::boxed::Box::new(NullSectionMem) // 实现 no-op 的 SectionMemOps
}或者直接让 KernelModuleHelper::vmalloc 返回 Result 而非 panicking。
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。基于 feat/starry-ebpf 分支,同时包含 ebpf.rs、kprobe.rs、perf_event.rs 等前置代码。附带 7 个错误路径 C 测试用例。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache,设计思路合理。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存,符合当前无卸载设计。sys_delete_module/sys_finit_module为桩实现返回Unsupported。- 系统调用路由在
syscall/mod.rs中正确注册,同时将bpf和perf_event_open从 dummy_fd 移至实际处理。
CI 状态
所有 CI 检查均为 skipped 状态,mergeable_state=blocked。CI 跳过是因为 PR 基于 feat/starry-ebpf 分支,可能不满足 CI 触发条件。无法从 CI 获取验证信息。
前次审查意见
前一次审查(mai-team-app[bot],CHANGES_REQUESTED)指出了相同的两个阻断性问题,当前 PR head 未修复。
阻断性问题
-
测试安装路径错误:
test-kmod-loader/c/CMakeLists.txt将二进制安装到usr/bin,但syscall测试组的qemu-x86_64.toml的test_commands遍历/usr/bin/starry-test-suit/*。同目录下所有其他测试(包括test-ebpf-basics)均安装到usr/bin/starry-test-suit。此测试不会被分组测试运行器发现和执行,等于没有 CI 覆盖。 -
KmodSectionMemnull 指针 Drop 未定义行为:当vmalloc分配失败时,StarryKmodHelper::vmalloc创建一个ptr为null_mut()且 layout 为(1,1)的KmodSectionMem,但其Drop实现对self.ptr调用dealloc(self.ptr, self.layout)。Rust 要求dealloc的指针必须是由同一 layout 从分配器获取的非空指针,对 null 指针调用dealloc是未定义行为,可能导致内核崩溃。建议在Drop中添加 null 检查,或让vmalloc在失败时返回一个安全的 no-op 实现。
建议性意见
core::mem::forget(owner)使模块资源常驻内存,是当前无卸载功能下的合理选择,但建议添加注释说明forget的意图和未来delete_module实现时的释放计划。flsuh_cache方法名来自上游kmod-loadercrate 的 trait 定义(拼写错误),PR 实现正确,可考虑向上游提 issue 修正。
结论
需要修复上述两个阻断性问题后方可合并。
Powered by mimo-v2.5-pro
| set(CMAKE_C_EXTENSIONS OFF) | ||
| add_executable(test-kmod-loader src/main.c) | ||
| target_compile_options(test-kmod-loader PRIVATE -Wall -Wextra -Werror) | ||
| install(TARGETS test-kmod-loader RUNTIME DESTINATION usr/bin) |
There was a problem hiding this comment.
🐛 阻断:安装路径错误
此处安装目标为 usr/bin,但 qemu-smp1/syscall/qemu-x86_64.toml 的 test_commands 遍历 /usr/bin/starry-test-suit/*。同目录下所有其他测试(包括 test-ebpf-basics)均安装到 usr/bin/starry-test-suit。
修复方式:
install(TARGETS test-kmod-loader RUNTIME DESTINATION usr/bin/starry-test-suit)当前路径下测试不会被分组测试运行器发现,等于没有 CI 覆盖。此问题已在前次审查中指出,仍未修复。
|
|
||
| impl Drop for KmodSectionMem { | ||
| fn drop(&mut self) { | ||
| unsafe { dealloc(self.ptr, self.layout) }; |
There was a problem hiding this comment.
🐛 阻断:null 指针调用 dealloc 是未定义行为
Drop 实现对 self.ptr 调用 dealloc。当上方 vmalloc 分配失败时(第 93-97 行),会创建 ptr: null_mut() 且 layout 为 Layout::from_size_align(1, 1) 的实例。Rust 的 dealloc 要求指针必须是由同一 layout 从分配器获取的非空指针,对 null 指针调用是 UB,可能导致内核崩溃。
建议修复方式:在 Drop 中添加 null 检查:
impl Drop for KmodSectionMem {
fn drop(&mut self) {
if !self.ptr.is_null() {
unsafe { dealloc(self.ptr, self.layout) };
}
}
}同时建议让 as_ptr/as_mut_ptr/change_perms 也正确处理 null 情况。
此问题已在前次审查中指出,仍未修复。
| Some(mem) => Box::new(mem), | ||
| None => { | ||
| warn!("kmod: vmalloc failed for size {size}"); | ||
| Box::new(KmodSectionMem { |
There was a problem hiding this comment.
KmodSectionMem 在 drop 时会导致 UB(见上方 Drop 注释)。更好的做法是让 KernelModuleHelper::vmalloc 返回 Result 类型,或在此处返回一个安全的 no-op 实现(如只读的零大小 SectionMemOps),而非创建 null 指针实例。
d9dcebe to
003b18d
Compare
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。基于 feat/starry-ebpf 分支,同时包含 ebpf.rs、kprobe.rs、perf_event.rs 等前置代码。附带 7 个错误路径 C 测试用例。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache,设计思路合理。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存,符合当前无卸载设计。sys_delete_module/sys_finit_module为桩实现返回Unsupported。- 系统调用路由在
syscall/mod.rs中正确注册,同时将bpf和perf_event_open从 dummy_fd 移至实际处理。
CI 状态
所有 CI 检查均为 skipped 状态,mergeable_state=dirty。CI 跳过是因为 PR 基于 feat/starry-ebpf 分支,可能不满足 CI 触发条件。无法从 CI 获取验证信息。
重复/重叠分析
- base 分支:
origin/dev上不存在任何kmod_loader、init_module相关代码,属于全新功能。 - PR #848(同一作者):eBPF 子系统,本 PR 依赖其分支,属于前置依赖,非重复。
- PR #837(Godones):kallsyms 符号表支持,本 PR 的
resolve_symbol桩实现声明了对此 PR 的依赖,属于互补关系。 - 结论:本 PR 无重复实现,与相关 PR 关系明确(前置依赖 + 未来互补)。
前次审查意见
本 PR 已收到两次 mai-team-app[bot] 的 CHANGES_REQUESTED 审查(#4338145783、#4338163988),均指出相同的两个阻断性问题。当前 PR head(003b18d3)未做任何修复提交。
阻断性问题
-
🐛 测试安装路径错误:
test-kmod-loader/c/CMakeLists.txt将二进制安装到usr/bin,但syscall测试组的所有其他测试均安装到usr/bin/starry-test-suit。测试运行器遍历/usr/bin/starry-test-suit/*,此测试不会被测试运行器发现和执行,等于没有 CI 覆盖。此问题已在两次前次审查中指出,仍未修复。 -
🐛
KmodSectionMemnull 指针 Drop 未定义行为:当vmalloc分配失败时,StarryKmodHelper::vmalloc创建一个ptr为null_mut()且 layout 为(1,1)的KmodSectionMem,但其Drop实现对self.ptr调用dealloc(self.ptr, self.layout)。Rust 要求dealloc的指针必须是由同一分配器以相同 layout 分配的非空指针,对 null 指针调用dealloc是未定义行为,可能导致内核崩溃。此问题已在两次前次审查中指出,仍未修复。
建议性意见
core::mem::forget(owner)使模块资源常驻内存,是当前无卸载功能下的合理选择,但建议添加注释说明forget的意图和未来delete_module实现时的释放计划。flsuh_cache方法名来自上游kmod-loadercrate 的 trait 定义(拼写错误),PR 实现正确,可考虑向上游提 issue 修正。
结论
需要修复上述两个阻断性问题(测试安装路径和 null 指针 Drop UB)后方可合并。这两个问题已在之前两次审查中明确指出,请优先处理。
Powered by glm-5.1
| set(CMAKE_C_EXTENSIONS OFF) | ||
| add_executable(test-kmod-loader src/main.c) | ||
| target_compile_options(test-kmod-loader PRIVATE -Wall -Wextra -Werror) | ||
| install(TARGETS test-kmod-loader RUNTIME DESTINATION usr/bin) |
There was a problem hiding this comment.
🐛 阻断:安装路径错误
此处安装目标为 usr/bin,但 qemu-smp1/syscall 目录下所有其他测试均安装到 usr/bin/starry-test-suit。测试运行器遍历 /usr/bin/starry-test-suit/*,此测试不会被分组测试运行器发现和执行,等于没有 CI 覆盖。
此问题已在之前两次审查中指出,仍未修复。
修复方式:
install(TARGETS test-kmod-loader RUNTIME DESTINATION usr/bin/starry-test-suit)|
|
||
| impl Drop for KmodSectionMem { | ||
| fn drop(&mut self) { | ||
| unsafe { dealloc(self.ptr, self.layout) }; |
There was a problem hiding this comment.
🐛 阻断:null 指针调用 dealloc 是未定义行为
Drop 实现对 self.ptr 调用 dealloc。当上方 vmalloc 分配失败时(第 93-97 行),会创建 ptr: null_mut() 且 layout 为 Layout::from_size_align(1, 1) 的实例。Rust 的 dealloc 要求指针必须是由同一 layout 从分配器获取的非空指针,对 null 指针调用是 UB,可能导致内核崩溃。
此问题已在之前两次审查中指出,仍未修复。
建议修复方式:
impl Drop for KmodSectionMem {
fn drop(&mut self) {
if !self.ptr.is_null() {
unsafe { dealloc(self.ptr, self.layout) };
}
}
}同时建议让 as_ptr/as_mut_ptr/change_perms 也正确处理 null 情况。
| Some(mem) => Box::new(mem), | ||
| None => { | ||
| warn!("kmod: vmalloc failed for size {size}"); | ||
| Box::new(KmodSectionMem { |
There was a problem hiding this comment.
KmodSectionMem 在 drop 时会导致 UB(见上方 Drop 注释)。更优方案是让 KernelModuleHelper::vmalloc 返回 Result 类型,或在此处返回一个安全的 no-op 实现(如零大小 SectionMemOps),而非创建 null 指针实例。
003b18d to
fe679d3
Compare
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。新增 kmod_loader.rs(~194 行)包含页对齐内存分配、ELF section 权限映射、NullSectionMem 安全回退和系统调用入口。同时基于 feat/starry-ebpf 分支,包含 ebpf.rs、kprobe.rs、perf_event.rs 等前置代码。附带 7 个错误路径 C 测试用例。
前次审查问题修复状态
本 PR 已收到 3 次 mai-team-app[bot] 的 CHANGES_REQUESTED 审查,均指出两个阻断性问题。最新提交 6ec4920d7 已修复全部问题:
-
✅ 测试安装路径:
CMakeLists.txt已修改为安装到usr/bin/starry-test-suit,测试运行器(遍历/usr/bin/starry-test-suit/*)现在可以发现并执行test-kmod-loader。 -
✅
KmodSectionMemnull 指针 Drop UB:Drop实现已添加if !self.ptr.is_null()检查。同时vmalloc失败时不再创建 null 指针实例,而是返回安全的NullSectionMem(实现SectionMemOpstrait,返回 null 指针和false),完全消除了 UB 风险。 -
✅
forget注释:已添加说明core::mem::forget(owner)的意图和未来delete_module实现时的释放计划。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache,设计思路合理。NullSectionMem作为vmalloc失败时的安全回退实现,避免内核崩溃。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存,符合当前无卸载设计。sys_delete_module/sys_finit_module为桩实现返回Unsupported,待后续完善。- 系统调用路由在
syscall/mod.rs中正确注册,同时将bpf和perf_event_open从 dummy_fd 移至实际处理。 flsuh_cache方法名来自上游kmod-loadercrate 的 trait 定义(拼写错误),本 PR 实现正确,aarch64条件编译和通用flush_icache_all处理得当。
重复/重叠分析
- base 分支:
origin/dev上不存在任何kmod_loader、init_module相关代码,属于全新功能。 - PR #848(同一作者):eBPF 子系统,本 PR 依赖其分支,属于前置依赖,非重复。
- PR #837(Godones):kallsyms 符号表支持,本 PR 的
resolve_symbol桩实现声明了对此 PR 的依赖,属于互补关系。 - 结论:本 PR 无重复实现,与相关 PR 关系明确(前置依赖 + 未来互补)。
已知限制
resolve_symbol当前为桩实现返回None,待 PR #837(kallsyms)合并后可通过 feature gate 启用完整符号解析。delete_module和finit_module为 stub,需要后续完善。flsuh_cache方法名来自上游拼写错误,建议向上游提 issue 修正。
CI 状态
所有 CI 检查为 skipped 状态,mergeable_state=dirty。CI 跳过可能因 PR 基于 fork 的 feature 分支。无法从 CI 获取验证信息。
结论
前次审查指出的两个阻断性问题已在最新提交中全部修复,实现合理,代码质量可接受。批准合并。
Powered by glm-5.1
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
6ec4920 to
24086f9
Compare
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。同时基于 feat/starry-ebpf 分支,包含 ebpf.rs、kprobe.rs、perf_event.rs 等前置代码。附带 7 个错误路径 C 测试用例。
前次审查问题修复状态
本 PR 已收到 3 次 CHANGES_REQUESTED 和 1 次 APPROVED 审查。最新提交 24086f94c 相对于已批准的 6ec4920d7 新增 3 个提交(仅在 ebpf.rs 中新增 +38/-5 行),已确认所有前次阻断性问题均已修复:
- ✅ 测试安装路径:
CMakeLists.txt已修改为安装到usr/bin/starry-test-suit,与同目录下其他测试一致,测试运行器可正确发现test-kmod-loader。 - ✅
KmodSectionMemnull 指针 Drop UB:Drop已添加if !self.ptr.is_null()检查。vmalloc失败时返回安全的NullSectionMem(返回 null 指针和false),完全消除了 UB 风险。 - ✅
forget注释:已添加说明core::mem::forget(owner)的意图和未来delete_module实现时的释放计划。
新增变更审查(6ec4920d7 → 24086f9)
新增变更仅涉及 ebpf.rs,包含两项改进:
-
BPF_LOOKUP_CACHE:新增全局静态缓存,helper_map_lookup_elem现在将查找结果复制到缓存再返回指针,而非直接返回map_ptr。这修复了之前直接返回 map fd 作为指针的错误行为,更接近 Linux bpf_map_lookup_elem 语义。SAFETY 注释正确说明了返回指针的有效期限制。 -
helper_probe_read改进:添加了 4096 字节上限检查防止越界读取;对用户空间地址(< 0x8000_0000_0000)尝试通过starry_vm::vm_read_slice安全读取,失败时回退到原始拷贝。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache,设计思路合理。NullSectionMem作为vmalloc失败时的安全回退实现,避免内核崩溃。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存,符合当前无卸载设计。sys_delete_module/sys_finit_module为桩实现返回Unsupported。- 系统调用路由在
syscall/mod.rs中正确注册,同时将bpf和perf_event_open从 dummy_fd 移至实际处理。
本地验证结果
- ✅
cargo fmt --check通过 - ✅
cargo xtask clippy --package starry-kernel(11 features)全部通过 - ✅
cargo xtask starry build --arch x86_64构建成功 - ✅ 合并冲突解决后(仅
Cargo.lock),上述验证重新通过
CI 状态
无 CI 检查运行(mergeable_state=dirty),CI 跳过可能因 PR 基于 fork feature 分支。
重复/重叠分析
- base 分支:
origin/dev上不存在任何kmod_loader、init_module相关代码,属于全新功能。 - PR #848(同一作者):eBPF 子系统,本 PR 的分支
feat/starry-kmod基于此分支,属于前置依赖(partial-overlap),PR #849 是 PR #848 的超集。 - PR #837(Godones):kallsyms 符号表支持,本 PR 的
resolve_symbol桩实现声明了对此 PR 的依赖,属于互补关系。 - 结论:无重复实现,与相关 PR 关系明确。
合并冲突
当前 mergeable_state=dirty。经本地验证,冲突仅在 Cargo.lock 中(其他文件自动合并成功)。解决方案:
git fetch origin
git merge origin/dev
# 解决 Cargo.lock 冲突:选择任一侧后运行 cargo generate-lockfile
git add Cargo.lock && git commit已在本地完成冲突解决并验证(fmt/clippy/build 均通过),但无法推送到贡献者 fork。
建议性意见
BPF_LOOKUP_CACHE在 SMP 场景下存在竞态风险(两个 CPU 同时执行 BPF helper 可能互相覆盖缓存指针),SAFETY 注释已说明此限制。后续可考虑 per-CPU 缓存解决。helper_probe_read中0x8000_0000_0000用户/内核地址分界线是硬编码假设,建议后续提取为平台相关常量。flsuh_cache方法名来自上游kmod-loadercrate trait 定义(拼写错误),本 PR 实现正确,可考虑向上游提 issue 修正。
结论
代码质量已达到可合并标准,所有前次阻断性问题均已修复,本地验证全部通过。当前唯一阻塞项是 Cargo.lock 合并冲突,请作者 rebase 到最新 dev 后即可合并。
Powered by glm-5.1
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
24086f9 to
f542af1
Compare
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。同时基于 feat/starry-ebpf 分支,包含完整的 eBPF 子系统(ebpf.rs 1291 行、kprobe.rs 334 行、perf_event.rs 416 行)。附带 7 个错误路径 C 测试用例。最新提交 f542af1f3 新增了 BPF/perf_event fd 关闭与资源释放功能。
前次审查问题修复状态
本 PR 已收到 3 次 CHANGES_REQUESTED 和 1 次 APPROVED。所有阻断性问题均已在当前 head f542af1f3 中修复:
- ✅ 测试安装路径:
CMakeLists.txt已修改为安装到usr/bin/starry-test-suit,与同目录下其他测试一致。 - ✅
KmodSectionMemnull 指针 Drop UB:Drop已添加if !self.ptr.is_null()检查;vmalloc失败时返回安全的NullSectionMem(返回 null 指针和false),完全消除了 UB 风险。 - ✅
forget注释:已添加说明core::mem::forget(owner)的意图和未来释放计划。
新增变更审查(相对于已批准的 6ec4920d7)
最新 3 个提交新增了以下改进:
BPF_LOOKUP_CACHE:helper_map_lookup_elem将查找结果复制到缓存再返回指针,而非直接返回 map 内部指针,更接近 Linuxbpf_map_lookup_elem语义。helper_probe_read改进:添加 4096 字节上限防止越界读取;对用户空间地址尝试通过vm_read_slice安全读取。- BPF fd 关闭与资源释放:新增
BpfFdTable::close_fd、remove_map、remove_prog、handle_obj_close(BPF_OBJ_CLOSE命令),以及perf_event_close、perf_event_fd_exists辅助函数,解决了 fd 泄漏问题。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache。NullSectionMem作为vmalloc失败时的安全回退实现,避免内核崩溃。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存。sys_delete_module/sys_finit_module为桩实现返回Unsupported。- eBPF 解释器实现了完整的 BPF 指令集,支持 Array/Hash map、多种 helper 函数。
- 系统调用路由正确注册了
bpf、perf_event_open、init_module、delete_module、finit_module。
本地验证结果
- ✅
cargo fmt --check通过 - ✅
cargo xtask clippy --package starry-kernel(11 features)全部通过 - ✅
cargo xtask starry build --arch x86_64构建成功
CI 状态
无 CI 检查运行(mergeable_state=dirty),CI 跳过可能因 PR 基于 fork feature 分支。
重复/重叠分析
- base 分支:
origin/dev上不存在kmod_loader、init_module相关代码,属于全新功能。 - PR #848(同一作者):eBPF 子系统,本 PR 分支基于此,属于前置依赖(partial-overlap)。
- PR #837(Godones):kallsyms 符号表支持,本 PR 的
resolve_symbol桩实现声明了依赖,属于互补关系。 - 结论:无重复实现,与相关 PR 关系明确。
合并冲突
当前 mergeable_state=dirty,冲突在 Cargo.lock 中。请作者 rebase 到最新 dev 后即可合并。
建议性意见
BPF_LOOKUP_CACHE在 SMP 场景下存在竞态风险(两个 CPU 同时执行 BPF helper 可能互相覆盖缓存),SAFETY 注释已说明限制。后续可考虑 per-CPU 缓存。helper_probe_read中0x8000_0000_0000用户/内核地址分界线是硬编码假设,建议后续提取为平台相关常量。flsuh_cache方法名来自上游kmod-loadercrate trait 定义(拼写错误),本 PR 实现正确,可考虑向上游提 issue。
结论
代码质量已达到可合并标准。所有前次阻断性问题均已修复,最新提交进一步完善了资源管理,本地验证全部通过。当前唯一阻塞项是 Cargo.lock 合并冲突,请作者 rebase 到最新 dev 后即可合并。
Powered by glm-5.1
| } | ||
|
|
||
| fn remove_map(&mut self, fd: u32) -> AxResult<()> { | ||
| self.maps |
There was a problem hiding this comment.
💡 建议:BPF_LOOKUP_CACHE 是全局静态,在 SMP 场景下两个 CPU 同时执行 BPF helper map_lookup_elem 时可能互相覆盖缓存内容。当前 SAFETY 注释已说明此限制。后续可考虑使用 per-CPU 缓存(如 ax_hal::percpu )来消除竞态风险。
| } | ||
| let mut guard = BPF_GLOBAL.lock(); | ||
| let map = match guard.get_map(map_ptr as u32) { | ||
| Ok(m) => m, |
There was a problem hiding this comment.
💡 建议:0x8000_0000_0000 作为用户/内核地址分界线是 x86_64 特定的硬编码假设。如果未来需要在 riscv64 或 aarch64 上运行 eBPF 程序,此值可能不正确。建议后续提取为平台相关常量(如 arch::USER_SPACE_END)。
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
f542af1 to
3501ba4
Compare
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
3501ba4 to
4a71474
Compare
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
4a71474 to
30e1396
Compare
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。同时包含完整的 eBPF 子系统(ebpf.rs、kprobe.rs、perf_event.rs)。附带错误路径 C 测试用例。
前次审查问题修复状态
前 3 次 CHANGES_REQUESTED 指出的两个阻断性问题已在当前 head 中修复:
- ✅ 测试安装路径:
CMakeLists.txt已修改为安装到usr/bin/starry-test-suit,测试运行器可正确发现。 - ✅
KmodSectionMemnull 指针 Drop UB:Drop已添加if !self.ptr.is_null()检查;vmalloc失败时返回安全的NullSectionMem。 - ✅
forget注释:已添加说明意图和未来释放计划。
本地验证结果
- ❌
cargo fmt --check失败:trap.rs和task/mod.rs中#[cfg(...)]属性格式不符合 rustfmt 规范 - ❌
cargo xtask clippy --package starry-kernel全部 12 个 feature 检查失败:lib.rs中mod ebpf;被重复声明两次(第 21 行和第 27 行),导致编译错误E0428: the name 'ebpf' is defined multiple times
阻断性问题
-
🐛
lib.rs中mod ebpf;重复声明:第 21 行和第 27 行各有一处mod ebpf;,导致所有 feature 编译均失败。这是最新提交30e13966引入的回归。修复方式:删除第 27 行多余的mod ebpf;。 -
⚠️ cargo fmt --check失败:trap.rs中#[cfg(all(feature = "kprobe", any(...)))]格式不符合 rustfmt 规范,task/mod.rs中有相同的格式问题。请运行cargo fmt修复。
重复/重叠分析
- base 分支:
origin/dev上不存在kmod_loader、init_module、ebpf、kprobe相关代码,属于全新功能。 - PR #848(同一作者):eBPF 子系统,本 PR 分支基于此,属于前置依赖(partial-overlap)。
- PR #837(Godones):kallsyms 符号表支持,本 PR 的
resolve_symbol桩实现声明了依赖,属于互补关系。 - 结论:无重复实现,与相关 PR 关系明确。
CI 状态
无 CI 检查运行(mergeable_state=dirty),CI 跳过可能因 PR 基于 fork feature 分支。
建议性意见
BPF_LOOKUP_CACHE在 SMP 场景下存在竞态风险,SAFETY 注释已说明限制,后续可考虑 per-CPU 缓存。flsuh_cache方法名来自上游kmod-loadercrate(拼写错误),本 PR 实现正确,可考虑向上游提 issue。
结论
前次审查的阻断性问题已全部修复,但最新提交引入了新的编译阻断(mod ebpf; 重复声明)和格式问题。需要修复后方可合并。
Powered by mimo-v2.5-pro
Powered by glm-5.1
| mod kcov; | ||
| #[cfg(all(feature = "kprobe", any(target_arch = "x86_64", target_arch = "riscv64", target_arch = "aarch64")))] | ||
| mod kprobe; | ||
| mod ebpf; |
There was a problem hiding this comment.
🐛 阻断:mod ebpf; 重复声明
ebpf 模块已在第 21 行声明过,此处重复声明导致编译失败:
error[E0428]: the name `ebpf` is defined multiple times
--> os/StarryOS/kernel/src/lib.rs:27:1
所有 12 个 feature 的 clippy 检查均因此失败。
修复方式:删除此行。
| @@ -1,10 +1,11 @@ | |||
| #[cfg(all(feature = "kprobe", any(target_arch = "x86_64", target_arch = "riscv64", target_arch = "aarch64")))] | |||
There was a problem hiding this comment.
cargo fmt 格式不符
此处的 #[cfg(all(feature = "kprobe", any(target_arch = "x86_64", target_arch = "riscv64", target_arch = "aarch64")))] 属性应按 rustfmt 规范拆分为多行格式。请运行 cargo fmt 自动修复。
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
30e1396 to
e76b91d
Compare
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。同时包含完整的 eBPF 子系统(ebpf.rs 1334 行、kprobe.rs 474 行、perf_event.rs 430 行)以及对应测试用例。
前次审查问题修复状态
本 PR 已收到多次审查(多次 CHANGES_REQUESTED 和 APPROVED)。当前 head fd533ecc 中所有阻断性问题均已修复:
- ✅ 测试安装路径:
CMakeLists.txt已修改为安装到usr/bin/starry-test-suit,与同目录下其他测试一致。 - ✅
KmodSectionMemnull 指针 Drop UB:Drop已添加if !self.ptr.is_null()检查;vmalloc失败时返回安全的NullSectionMem(no-op 实现),完全消除了 UB 风险。 - ✅
forget注释:已添加说明core::mem::forget(owner)的意图和未来delete_module实现时的释放计划。 - ✅
mod ebpf;重复声明:已修复,lib.rs中仅有一处mod ebpf;。 - ✅
cargo fmt格式问题:lib.rs模块声明已在字母序。
本地验证结果
- ✅
cargo fmt --check通过 - ✅
cargo xtask clippy --package starry-kernel(12 features)全部通过,0 失败
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache,设计思路合理。NullSectionMem作为vmalloc失败时的安全回退实现,避免内核崩溃。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存,符合当前无卸载设计。sys_delete_module/sys_finit_module为桩实现返回Unsupported,待后续完善。- eBPF 解释器实现了完整的 BPF 指令集(ALU/JMP/MEM),支持 Array/Hash map、11 个 helper 函数。
- 系统调用路由正确注册了
bpf、perf_event_open、init_module、delete_module、finit_module。 BpfFdTable实现了 fd 分配/回收(含 free-fd 重用)和close_fd资源释放。
重复/重叠分析
- base 分支:
origin/dev上不存在kmod_loader、init_module、ebpf、kprobe相关代码,属于全新功能。 - PR #847(同一作者):kprobe 子系统支持,本 PR 依赖其分支,属于前置依赖。
- PR #848(同一作者):eBPF 子系统,本 PR 分支基于此,属于前置依赖(partial-overlap)。
- PR #837(Godones):kallsyms 符号表支持,本 PR 的
resolve_symbol桩实现声明了依赖,属于互补关系。 - 结论:无重复实现,与相关 PR 关系明确。
CI 状态
无 CI 检查运行(mergeable_state=unstable),CI 跳过可能因 PR 基于 fork feature 分支。无法从 CI 获取验证信息,本地验证全部通过。
建议性意见(非阻断)
BPF_LOOKUP_CACHE在 SMP 场景下存在竞态风险(两个 CPU 同时执行 BPF helper 可能互相覆盖缓存),SAFETY 注释已说明限制。后续可考虑 per-CPU 缓存。helper_probe_read中用户/内核地址分界线0x8000_0000_0000是硬编码假设,建议后续提取为平台相关常量。flsuh_cache方法名来自上游kmod-loadercrate 的 trait 定义(拼写错误),本 PR 实现正确,可考虑向上游提 issue。
结论
前次审查指出的所有阻断性问题均在当前 head fd533ecc 中修复。代码质量达到可合并标准,本地验证(fmt/clippy)全部通过。批准合并。
Powered by glm-5.1
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。同时基于 feat/starry-ebpf 分支,包含完整的 eBPF 子系统(ebpf.rs、kprobe.rs、perf_event.rs)。附带 7 个错误路径 C 测试用例。
前次审查问题修复状态
本 PR 已收到 7 次审查(4 次 CHANGES_REQUESTED、2 次 APPROVED、1 次 COMMENTED)。当前 head 4defa4105 修复状态:
- ✅ 测试安装路径:
CMakeLists.txt已修改为安装到usr/bin/starry-test-suit,与同目录下其他测试一致,测试运行器可正确发现。 - ✅
KmodSectionMemnull 指针 Drop UB:Drop已添加if !self.ptr.is_null()检查;vmalloc失败时返回安全的NullSectionMem(返回 null 指针和false),完全消除 UB 风险。 - ✅
mod ebpf;重复声明:已修复,lib.rs中仅有一处声明。 - ✅
forget注释:已添加说明意图和未来释放计划。 - ✅
cargo fmt --check:当前 head 通过格式检查。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache。NullSectionMem作为 vmalloc 失败时的安全回退,避免内核崩溃。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存。sys_delete_module/sys_finit_module为桩实现返回Unsupported。- 系统调用路由在
syscall/mod.rs中正确注册。
本地验证结果
- ✅
cargo fmt --check通过 - ✅
cargo xtask clippy --package starry-kernel(13 features)全部通过 - ✅
cargo xtask starry build --arch x86_64构建成功
CI 状态
所有 CI 检查为 skipped(PR 基于 fork 的 feature 分支,不满足 CI 触发条件),与 PR 无关。
重复/重叠分析
- base 分支:
origin/dev上不存在kmod_loader、init_module相关代码,属于全新功能。 - PR #848:eBPF 子系统,本 PR 分支基于此,属于前置依赖(partial-overlap)。
- PR #837:kallsyms 符号表,
resolve_symbol桩实现声明了依赖,属于互补关系。 - 结论:无重复实现,与相关 PR 关系明确。
合并冲突
当前 mergeable_state=true,mergeable=true,rebaseable=true,无合并冲突。
建议性意见
BPF_LOOKUP_CACHE在 SMP 场景下存在竞态风险(SAFETY 注释已说明限制),后续可考虑 per-CPU 缓存。flsuh_cache方法名来自上游kmod-loadercrate trait 定义(拼写错误),本 PR 实现正确,可考虑向上游提 issue。resolve_symbol为桩实现返回None,待 PR #837 合并后启用完整符号解析。
结论
所有前次阻断性问题均已修复,本地验证全部通过(fmt/clippy/build),无合并冲突。代码质量达到可合并标准,批准合并。
Powered by glm-5.1
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
4defa41 to
51fe489
Compare
|
冲突已解决,已 rebase 到最新 dev 分支(#847 kprobe + #848 eBPF 已合并)。 主要处理:
已通过 |
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。新增 kmod_loader.rs(229 行)包含页对齐内存分配、ELF section 权限映射、NullSectionMem 安全回退和系统调用入口。同时包含对 ebpf.rs 的一个小修复和 perf_event.rs 的 cfg guard。附带 10 个错误路径 C 测试用例。
前次审查问题修复状态
本 PR 已收到 8 次审查(多次 CHANGES_REQUESTED 和 APPROVED)。当前 head 0013cdb80 已修复所有历史阻断性问题:
- ✅ 测试安装路径:
CMakeLists.txt已正确安装到usr/bin/starry-test-suit,与同目录其他测试一致。 - ✅
KmodSectionMemnull 指针 Drop UB:Drop已添加if !self.ptr.is_null()检查;vmalloc失败时返回安全的NullSectionMem(实现SectionMemOpstrait,返回 null 指针和false)。 - ✅
forget注释:已添加说明core::mem::forget(owner)的意图和未来delete_module实现时的释放计划。 - ✅
mod ebpf;重复声明:已修复,lib.rs中各模块声明唯一。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换,TLB/icache 刷新在释放地址空间锁后进行,锁粒度合理。NullSectionMem作为vmalloc失败时的安全 no-op 回退,避免内核崩溃。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存,符合当前无卸载设计。sys_delete_module/sys_finit_module为桩实现返回Unsupported,待后续完善。resolve_symbol使用AtomicBool确保仅打印一次警告,避免日志刷屏。flsuh_cache中 aarch64 专用 dcache 清理和通用 icache flush 的组合处理得当。perf_event.rs添加#[cfg(feature = "ebpf")]保护,避免非 ebpf feature 下编译错误。ebpf.rs中 BPF 验证器将BPF_CALL_OP替换为字面量0x80,语义相同但降低了可读性(见建议)。
本地验证结果
- ✅
cargo fmt --check通过 - ✅
cargo xtask clippy --package starry-kernel(14 feature 组合)全部通过,无 warning - ✅ PR head SHA 与 checkout 一致:
0013cdb802be59c1f0f3c9de91110f05d14201ce
CI 状态
所有 CI 检查均为 skipped 状态(可能因 PR 基于 fork 的 feature 分支不满足 CI 触发条件)。无 CI 失败与本 PR 相关。
重复/重叠分析
- base 分支:
origin/dev上不存在kmod_loader、init_module相关代码,属于全新功能。 - PR #848(同一作者):eBPF 子系统,已合并到 dev,本 PR 不再包含其重复代码。
- PR #837(Godones):kallsyms 符号表支持,本 PR 的
resolve_symbol桩实现声明了对此 PR 的依赖,属于互补关系。 - 结论:无重复实现,与相关 PR 关系明确。
建议性意见
ebpf.rs中op != 0x80使用字面量替代了之前的bpf_insn::BPF_CALL_OP常量引用,建议保持使用常量以提高可读性,虽然语义相同。BPF_LOOKUP_CACHE在 SMP 场景下存在竞态风险(两个 CPU 同时执行 BPF helper 可能互相覆盖缓存),SAFETY 注释已说明限制,后续可考虑 per-CPU 缓存。flsuh_cache方法名来自上游kmod-loadercrate 的 trait 定义(拼写错误),本 PR 实现正确,可考虑向上游提 issue 修正。
结论
所有历史阻断性问题均已修复,代码质量达到可合并标准。cargo fmt --check 和 clippy 全部通过。批准合并。
Powered by mimo-v2.5-pro
|
关于模块声明顺序和 trap.rs 格式问题:已在之前的 rebase commit 中修复。当前 |
- kmod_loader.rs: StarryKmodHelper (KernelModuleHelper trait impl) - KmodSectionMem: page-aligned memory with SectionMemOps, R/W/X perms - vmalloc: page-aligned kernel memory allocation - resolve_symbol: stub (depends on PR rcore-os#837 kallsyms) - flsuh_cache: icache/dcache flush for loaded module code - sys_init_module: load .ko ELF from user memory, call init - sys_delete_module / sys_finit_module: syscall stubs - test-kmod-loader: 7 test modules for error path validation - Depends on: feat/starry-kprobe, feat/starry-ebpf
1. Fix test install path: usr/bin -> usr/bin/starry-test-suit
(tests were silently skipped by qemu toml wildcard)
2. Fix KmodSectionMem null-pointer Drop UB:
- Add null check in Drop before calling dealloc
- Replace null-ptr KmodSectionMem fallback with safe NullSectionMem
(no-op SectionMemOps implementation) to avoid UB entirely
3. Add comment explaining core::mem::forget(owner) intent:
module must remain in memory; future delete_module will recover
owner via global registry
Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build.
Add module doc comments describing LKM support, key components (KmodSectionMem, NullSectionMem, StarryKmodHelper), and known limitations. Fix module ordering in lib.rs for rustfmt.
- resolve_symbol stub: use AtomicBool to warn only once, avoid log spam - add test cases for valid ET_REL header, fd=0, and large junk input
BPF_CALL_OP constant does not exist in bpf_insn module. BPF_CALL opcode is 0x85, so the high nibble is 0x80.
…conflicts - Skip kprobe and eBPF commits (already in dev via rcore-os#847 + rcore-os#848) - Resolve lib.rs, syscall/mod.rs, Cargo.toml conflicts - Update ax_hal -> ax_runtime::hal paths in kmod_loader.rs - Remove dw_apb_uart (not in workspace dependencies)
perf_event.rs references crate::ebpf::run_bpf_prog which is only available under the ebpf feature. Add cfg gates to prevent compilation failure when ebpf feature is disabled.
0013cdb to
a8f36bb
Compare
There was a problem hiding this comment.
PR 审查:feat(starry-kernel): add LKM support via kmod-loader integration
变更概述
本 PR 为 StarryOS 内核添加可加载内核模块(LKM)支持,集成 kmod-loader crate(v0.2),实现 init_module / delete_module / finit_module 系统调用。新增 kmod_loader.rs(229 行)包含页对齐内存分配 KmodSectionMem、null 安全回退 NullSectionMem、StarryKmodHelper 实现和系统调用入口。同时附带 10 个错误路径 C 测试用例和 3 个 x86_64 链接脚本。
实现逻辑
KmodSectionMem通过全局分配器实现页对齐内存分配,change_perms通过页表操作实现 R/W/X 权限切换并刷新 TLB/icache,设计合理。NullSectionMem作为vmalloc失败时的安全回退实现,避免内核崩溃。Drop已添加 null 检查,完全消除了 UB 风险。sys_init_module从用户空间读取 ELF 数据和参数字符串,调用kmod-loader加载并执行模块 init 函数后forget使模块常驻内存,符合当前无卸载设计,已添加意图注释。resolve_symbol使用AtomicBool确保仅输出一次警告,等待 PR #837(kallsyms)支持完整符号解析。sys_delete_module/sys_finit_module为桩实现返回Unsupported,待后续完善。- 系统调用路由在
syscall/mod.rs中正确注册init_module、delete_module、finit_module。 perf_event.rs新增#[cfg(feature = "ebpf")]条件编译守卫,避免无 eBPF feature 时编译错误。ebpf.rs验证器中将bpf_insn::BPF_CALL_OP替换为字面量0x80(值相同),不影响逻辑正确性,但执行路径(第 1181 行)仍使用BPF_CALL_OP常量,存在轻微风格不一致。
前次审查问题修复状态
本 PR 已收到多次审查(多次 CHANGES_REQUESTED 和 APPROVED)。当前 head a8f36bbf1 已修复全部前次阻断性问题:
- ✅ 测试安装路径:
CMakeLists.txt已修改为安装到usr/bin/starry-test-suit,与同目录下其他测试一致。 - ✅
KmodSectionMemnull 指针 Drop UB:Drop已添加if !self.ptr.is_null()检查;vmalloc失败时返回安全的NullSectionMem。 - ✅
forget注释:已添加说明core::mem::forget(owner)的意图和未来delete_module实现时的释放计划。 - ✅
mod ebpf;重复声明:当前lib.rs中仅有一处mod kmod_loader;,模块声明按字母序排列。
本地验证结果
- ✅
cargo fmt --check通过 - ✅
cargo xtask clippy --package starry-kernel全部 14 个 feature 检查通过 - ✅ 无合并冲突(
mergeable=true,mergeable_state=blocked为分支保护规则所致,非代码冲突)
CI 状态
多数 CI 检查为 skipped 状态(PR 基于 fork feature 分支,可能不满足 CI 触发条件),部分为 queued/in_progress。未观察到失败的检查。
重复/重叠分析
- base 分支:
origin/dev上不存在kmod_loader、init_module相关代码,属于全新功能。 - PR #837(Godones,kallsyms):✅ 已合并到 dev,
resolve_symbol桩实现声明了对此 PR 的依赖,后续可通过 feature gate 启用完整符号解析。 - PR #848(CN-TangLin,eBPF):✅ 已合并到 dev,本 PR 当前 head 已 rebase 到包含 eBPF 和 kprobe 的最新 dev。
- 结论:本 PR 无重复实现,与相关 PR 关系明确(前置依赖已合并)。
已知限制(非阻断)
resolve_symbol当前为桩实现返回None,待启用 kallsyms 完整符号解析。delete_module和finit_module为 stub,需要后续完善。flsuh_cache方法名来自上游kmod-loadercrate 的 trait 定义(拼写错误),本 PR 实现正确,可考虑向上游提 issue 修正。ebpf.rs验证器中0x80字面量与执行路径BPF_CALL_OP常量存在轻微风格不一致,不影响功能。
结论
所有前次阻断性问题均已修复,代码质量达到可合并标准,本地验证全部通过。批准合并。
Powered by mimo-v2.5-pro
将 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/` 接口。
…re-os#849) * feat(starry-kernel): add LKM support via kmod-loader integration - kmod_loader.rs: StarryKmodHelper (KernelModuleHelper trait impl) - KmodSectionMem: page-aligned memory with SectionMemOps, R/W/X perms - vmalloc: page-aligned kernel memory allocation - resolve_symbol: stub (depends on PR rcore-os#837 kallsyms) - flsuh_cache: icache/dcache flush for loaded module code - sys_init_module: load .ko ELF from user memory, call init - sys_delete_module / sys_finit_module: syscall stubs - test-kmod-loader: 7 test modules for error path validation - Depends on: feat/starry-kprobe, feat/starry-ebpf * fix(starry-kernel): address LKM PR rcore-os#849 review blocking issues 1. Fix test install path: usr/bin -> usr/bin/starry-test-suit (tests were silently skipped by qemu toml wildcard) 2. Fix KmodSectionMem null-pointer Drop UB: - Add null check in Drop before calling dealloc - Replace null-ptr KmodSectionMem fallback with safe NullSectionMem (no-op SectionMemOps implementation) to avoid UB entirely 3. Add comment explaining core::mem::forget(owner) intent: module must remain in memory; future delete_module will recover owner via global registry Verified: clippy 11 features, x86_64/riscv64/aarch64/loongarch64 build. * docs(starry-kernel): add module-level documentation for kmod_loader Add module doc comments describing LKM support, key components (KmodSectionMem, NullSectionMem, StarryKmodHelper), and known limitations. Fix module ordering in lib.rs for rustfmt. * fix(starry-kernel): address kmod review non-blocking suggestions - resolve_symbol stub: use AtomicBool to warn only once, avoid log spam - add test cases for valid ET_REL header, fd=0, and large junk input * fix(starry-kernel): use literal 0x80 for BPF_CALL opcode in verifier BPF_CALL_OP constant does not exist in bpf_insn module. BPF_CALL opcode is 0x85, so the high nibble is 0x80. * fix(starry-kernel): rebase onto dev with kprobe+eBPF merged, resolve conflicts - Skip kprobe and eBPF commits (already in dev via rcore-os#847 + rcore-os#848) - Resolve lib.rs, syscall/mod.rs, Cargo.toml conflicts - Update ax_hal -> ax_runtime::hal paths in kmod_loader.rs - Remove dw_apb_uart (not in workspace dependencies) * fix(starry-kernel): add cfg(ebpf) gate for perf_event module and trigger perf_event.rs references crate::ebpf::run_bpf_prog which is only available under the ebpf feature. Add cfg gates to prevent compilation failure when ebpf feature is disabled. * ci: rebase onto latest dev, resolve Cargo.lock conflict
…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.
概述
为 StarryOS 内核添加可加载内核模块(LKM)支持,集成
kmod-loadercrate,实现init_module/delete_module/finit_module系统调用。背景
可加载内核模块是 Linux 内核动态扩展的标准机制。本实现允许在运行时加载/卸载内核模块,模块可以使用 kprobe、eBPF 等内核服务,为 StarryOS 提供动态扩展能力。前置依赖 #847(kprobe)和 #848(eBPF)均已合并到 dev。
变更内容
新增文件
kmod_loader.rs:LKM 加载器核心实现resolve_symbol:内核符号解析(依赖 kallsyms)test-kmod-loader/:LKM 用户态测试程序(CMake + C)修改文件
lib.rs:注册kmod_loader模块syscall/mod.rs:添加init_module、delete_module、finit_module系统调用Cargo.toml:添加kmod-loader = "0.2"依赖验证
cargo fmt --check:通过cargo xtask clippy --package starry-kernel:通过(单独 feature 配置均通过)关联
resolve_symbol完整功能依赖 Adds support for kernel symbol dumping via kallsyms #837(kallsyms)合并