Feat: Loongarch run through - #266
Conversation
# Conflicts: # data/loongarch_musl/etc/init.d/rcS
There was a problem hiding this comment.
Code Review
This pull request introduces support for local test images outside the worktree, cleans up the LoongArch musl test initialization, and adds a no-std, cross-platform ext4_rs vendor crate. It also implements floating-point state saving/restoring, LS7A RTC support, and MMIO mapping for the LoongArch architecture. Key feedback includes a critical logic error in trap_entry.S that checks the old PLV instead of the target PLV before restoring floating-point state, a deadlock risk in check_timer due to synchronous network polling in the hard interrupt context, a bug in ext4_rs where inserting an extent overwrites existing extents without shifting them, and missing boundary checks in bitmap operations and Ext4DirEntryTail::copy_to_slice that could lead to panics or undefined behavior.
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.
概述
本 PR 将 LoongArch 分支推进到可以稳定启动并跑通当前 OSComp musl 冒烟测试的状态。修复范围覆盖早期 MMIO 映射、地址空间切换、TLB refill、用户态返回、启动 trap frame、FPU 上下文保存恢复、RTC、timer 驱动网络轮询,以及官方测试镜像的挂载运行流程。
当前 LoongArch 的
rcS仍然是明确白名单,只自动运行以下四组 musl 测试:basic_testcode.shbusybox_testcode.shlua_testcode.shiperf_testcode.sh主要修改
LoongArch MMIO 与地址空间
mmio_pa_to_va()路径,让 LoongArch MMIO 使用非缓存的 DMW0 直接映射窗口,而不是走缓存 RAM direct map。PGDH,用户地址空间使用PGDL,避免切换用户地址空间后丢失高半区内核映射。LoongArch Trap 与 TLB Refill
Dir3 -> Dir2 -> Dir1 -> PTE。ertn从PRMD恢复特权级,不再在 restore 路径中手动改写CRMD。SpinLock<TrapFrame>替换为 rawUnsafeCell<TrapFrame>存储。启动 trap frame 会被trap_entry异步写入,普通自旋锁无法作为这里的同步保护,并且会在早期 trap 设置中被破坏。f0-f31、fcsr0和打包的fcc0-fcc7。信号mcontext.fpregs也使用同一份状态布局。时间、RTC 与网络轮询
clock_freq()换算,不再依赖调度 tick。loongson,ls7a-rtc,同时保留 goldfish RTC 支持。测试镜像与运行流程
make run-la和os/qemu-loongarch-run.sh支持通过TESTIMG_LA=/path/to/sdcard-la.img指定测试镜像;默认也会查找../CCYOS/sdcard-la.img。rcS将官方 raw ext4 测试镜像从/dev/vdb挂载到/tests,并在原地运行四组白名单 musl 测试,不再把测试二进制复制进 tmpfs。ext4 目录校验和加固
验证
构建已通过:
使用官方测试镜像直接挂载运行 LoongArch QEMU:
观察到
rcS自动完成:/dev/vdb成功挂载到/testsbasic_testcode.sh返回rc=0busybox_testcode.sh返回rc=0lua_testcode.sh返回rc=0iperf_testcode.sh返回rc=0BASIC_UDP、BASIC_TCP、PARALLEL_UDP、PARALLEL_TCP、REVERSE_UDP、REVERSE_TCP均输出success[Tests] all tests finished; powering off,QEMU 正常退出注意事项与风险
/tests/musl下所有*_testcode.sh。/dev/vdb。如果在它前面插入额外 block device,设备名会变化,自动挂载路径需要同步调整。docs/os-myself/big-bug-record.md是本轮排查过程记录,虽然本地可能有修改,但不属于本 PR 文档更新范围,也不会随本 PR 提交。