Repository navigation
[libcpu][riscv] fix MMU and user fault handling for Smart - #11892
BernardXiong wants to merge 3 commits into
Conversation
- add XuanTie architecture selection and the SVPBMT option - translate early page table pointers with the kernel physical offset - allow the MPR range to extend below the linked kernel base - clean early page tables and clear user entries for each hart - terminate only the current LWP on unhandled user faults - keep interrupts enabled while reporting user context
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: libcpu_riscvReviewers: @Yaochenger Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-10-23 23:09 CST)
📝 Review Instructions
|
- add a forward declaration for the user fault register dump - fix the implicit declaration error on RISC-V builds
| int start_idx = USER_VADDR_START >> VPN2_SHIFT; | ||
| int end_idx = USER_VADDR_TOP >> VPN2_SHIFT; | ||
| for (i = start_idx; i <= end_idx; i++) | ||
| { | ||
| mmu_table[i] = 0; |
There was a problem hiding this comment.
熊老师好呀!这段清零好像只在非 SMP 分支,SMP 下每个 hart 的 table 是不是也要清一下?另外 common 用的是 USER_VADDR_TOP - 1,这里是 TOP,不知道是不是有意的?如有误解请指正,谢谢!
There was a problem hiding this comment.
感谢指出,确实有问题,已修复(commit bcde514):
- 将清零逻辑抽成
_clear_user_pgtbl_entries();SMP 分支现在会对每个 hart 的 L1 表(RT_CPUS_NR个页)都执行清零,不再只处理非 SMP 路径。 - 末尾索引改为
(USER_VADDR_TOP - 1) >> VPN2_SHIFT,与common实现保持一致,按半开区间[USER_VADDR_START, USER_VADDR_TOP)处理。在当前开启 ARCH_REMAP_KERNEL 的配置下两者得到的索引相同,但语义上应排除 TOP。
| sys_exit_group(-1); | ||
| csr_write(CSR_STATUS, saved_stat); |
There was a problem hiding this comment.
熊老师好呀!sys_exit_group(-1) 后面的 csr_write 按理走不到,IE 会一直开着。是不是先恢复再调更稳?如有误解请指正,谢谢!
There was a problem hiding this comment.
这里是有意把恢复放在 sys_exit_group() 之后的(commit bcde514 仅补充注释说明):
- 正常路径下
sys_exit_group()→lwp_exit()不会返回,csr_write()不会执行;此时保持 IE 开启是必要的:lwp_exit()内部的LWP_LOCK()会调用RT_DEBUG_SCHEDULER_AVAILABLE(1),在 UP + RT_DEBUGING_CONTEXT 下如果中断关闭会直接断言;另外进程 teardown 也可能获取 sleeping lock。 - 只有
lwp_self()为空、sys_exit_group()返回-EINVAL时,csr_write()才会执行并恢复进入前的 sstatus。
因此没有把恢复提前,仅在 csr_write() 前加了一条注释说明该分支。
|
The user address range was only cleared in the non-SMP branch, so SMP builds still inherited the early identity mappings in each hart's user page table. Clear the range in every per-hart table as well. Use USER_VADDR_TOP - 1 when computing the last top-level index to keep the half-open [USER_VADDR_START, USER_VADDR_TOP) semantics, matching the common RV32 implementation. Also document that the sstatus restore after sys_exit_group() only runs when there is no LWP to terminate. It must not be moved before the call: process teardown takes sleeping locks and therefore needs interrupts enabled. Co-authored-by: DeepSeek 4.1 Flash <[email protected]>
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
Several RISC-V Smart issues prevented reliable user space operation: early page table pointers were not translated with the kernel physical offset, per-hart page tables inherited user mappings, early page tables were not flushed, and unhandled user faults could terminate the kernel instead of the current process.
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up