Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在完成 CH8 作业时,我遇到了以下问题:单独运行测例程序能够正常运行,但是运行
ch8b_usertest
或ch8_usertest
时就有概率发生 kernel panic 报错,如下所示:经过检查,我发现 ch8 代码中有如下缺陷:
sepc/stval
等寄存器的信息,我发现上面汇报 Page Fault 时的内存地址和触发代码为内核栈内的有效空间以及trap_from_kernel()
函数。结合汇编代码我推断,由于 kernel trap handler 复用了当前正在使用的 kernel stack,因此当 stack 发生异常时将无法正常执行 trap handler。对此我修改了 kernel trap handler,在进入前修改sp
至预留的内存空间中。tid == 0
时 ,该进程会回收其所有线程的资源,也包括内核栈。从而在执行后续代码(包括回收 Kernel Stack 编号 以及后续的切换任务上下文)发生 PageFault。而这一错误之所以不会经常触发则可能是因为 TLB 中仍然保留内核栈的地址转换信息,因此在删除地址段后加入sfence.vma
即可稳定触发这一 bug。因此,为了避免当前线程资源被回收,我在
TaskManager
中保留了一份当前线程的引用,以确保该线程资源不会被回收。(也许放在别的地方更好?欢迎老师助教指教)另外,我在调试过程中还发现另外一些小问题:
Makefile
中可以删除对应任务,节省编译时间。gdb
的运行命令并未更新至包含 fs 的版本。