feat(oscomp): 支持评测自动运行并修复大内存启动#261
Conversation
帧分配器与内核直映射此前硬编码到编译期 MEMORY_END(riscv 128MB / loongarch 128MB)。评测机给 1–2GB(本地复现 -m 4G)时,QEMU 把 DTB 放在 RAM 顶端(-m 4G 时约 0xbfe0_0000),落在 128MB 直映射窗口之外,切换页表后 platform::init() 解引用 DTB 即缺页 panic;且帧分配器也无法管理评测所需的 大内存。 改为优先采用 device_tree::dram_info() 报告的真实 DRAM 末端: - mm::init():帧分配器 end 取 DRAM 末端; - map_kernel_space():物理内存直映射 end 取同一 DRAM 末端,二者保持一致, 保证每个可分配帧都在直映射内。 - LoongArch:经 DMW 硬件直映射访问物理内存(不走页表),且 DTB 报告超大 RAM 窗口,4K 页映射多 GB 既慢又无意义,故两处均 cap 在 1GiB。 - RISC-V:不设上限覆盖全部 DRAM,并对 DTB 增加兜底映射(map_mmio_region), 以防其落在直映射窗口外。 已用 qemu-system-riscv64 -m 2G 验证:正确识别 DRAM 0x80000000-0x100000000, 解析顶端 DTB 不再 panic,ext4 挂载与 rootfs 选择正常。
让 `make all` 产出的内核在评测机上自动跑测试并主动关机: - os/Cargo.toml:新增 `oscomp` feature。 - fs/mod.rs:init_oscomp_filesystems()——按内容探测双盘,rootfs(认 /bin/sh|/bin/ash)挂 /,测试镜像(认 *_testcode.sh)挂 /tests; total_blocks 由设备实际大小推导。 - kernel/boot.rs:oscomp 模式下 init() 调 init_oscomp_filesystems(), 否则保持原有单盘 init_ext4_from_block_device()。 - data/*/etc/init.d/rcS(两架构一致):扫 /tests 下 *_testcode.sh(含下一层), glibc loader 软链到 /lib,逐个执行,跑完 /sbin/poweroff -f;无 /tests 回落 交互 shell。 - Makefile:kernel-rv/la 默认带 --features oscomp;新增 run-oscomp-rv/la、 prepare-testimg-rv/la 及相关变量。 两架构 --features oscomp 编译通过,冒烟测试确认 init_oscomp_filesystems() 正确识别 rootfs。注意:内核态首次写 ext4(mkdir /tests 等)会触发一个既有的 ext4 写路径崩溃(write_offset 收到 self=pa_to_va(0)),端到端尚未跑通,该写 路径 bug 另行处理。
There was a problem hiding this comment.
Code Review
This pull request introduces the OSCOMP evaluation mode, enabling automatic test execution and shutdown on QEMU for both RISC-V and LoongArch architectures. Key changes include new Makefile targets, automated test runner scripts (rcS), dynamic physical memory mapping based on device tree DRAM info, and dual-disk probing/mounting. The reviewer feedback highlights several critical issues: failed filesystem mount attempts for rootfs and testfs must be unmounted to prevent resource leaks; the directory scanner must skip "." and ".." to avoid recursive scanning of the parent directory; the DTB mapping size should be restricted if it lies before the kernel to prevent overlapping with the kernel's .text segment; and the rcS scripts should use "ln -sf" to safely handle broken symlinks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
背景
OSCOMP 评测环境会同时挂载测试镜像和我们的 rootfs,并要求系统启动后自动运行测试、测试结束后自动关机。
当前分支同时处理两个问题:
*_testcode.shMEMORY_END会导致 DTB 或可用内存范围处理不完整改动
oscompfeature,make all构建评测内核时默认启用该 feature/bin/sh或/bin/ash识别 rootfs*_testcode.sh识别测试镜像,并挂载到/testsrcS:/tests下的测试脚本poweroffmake run-oscomp-rvmake run-oscomp-la兼容性
非
oscompfeature 下仍保持原有单盘启动和交互式 shell 行为,本地开发流程不受影响。