lupyuen opened a new pull request, #11585: URL: https://github.com/apache/nuttx/pull/11585
## Summary Ox64 BL808 crashes with a Page Fault when we run `getprime` then `hello`. This is caused by the T-Head C906 MMU incorrectly accessing the MMU Page Tables of the Previous Process (`getprime`) while starting the New Process (`hello`). To fix the problem, this PR flushes the MMU Cache whenever we point the MMU SATP Register to the New Page Tables. We execute 2 RISC-V Instructions that are specific to T-Head C906: - DCACHE.IALL: Invalidate all Page Table Entries in the D-Cache - SYNC.S: Ensure that all Cache Operations are completed This is derived from the T-Head Errata for Linux Kernel. [More details here](https://lupyuen.github.io/articles/mmu#appendix-flush-the-mmu-cache-for-t-head-c906) ### Modified Files - `arch/risc-v/src/common/riscv_mmu.h`: If needed, `mmu_write_satp()` calls `mmu_flush_cache()` (weak function) to flush the MMU Cache. (Like for T-Head C906) - `arch/risc-v/src/bl808/bl808_mm_init.c`: Flush the MMU Cache for T-Head C906. Extend `mmuflags` from 32-bit to 64-bit to be consistent with `mmu_ln_setentry()`. - `boards/risc-v/bl808/ox64/configs/nsh/defconfig`: Enable `ostest` in the Build Config. Update `CONFIG_BOARD_LOOPSPERMSEC` according to `calib_udelay`. ## Impact With this PR, New Processes (`hello`) will no longer access the Page Tables of the Old Processes (`getprime`) on Ox64 BL808. There is no impact on other NuttX Ports. ## Testing ### Ox64 BL808 Testing Ox64 BL808 no longer crashes when we run `getprime` then `hello`: ```text ## tools/configure.sh ox64:nsh nsh> getprime ... getprime took 15408 msec nsh> hello Hello, World!! nsh> getprime ... getprime took 15403 msec nsh> hello Hello, World!! ``` [(See the Complete Log)](https://gist.github.com/lupyuen/f2eb5c6e92b7cf8e10c27cc59df08065) ### Regression Testing For Regression Testing, we tested with QEMU 64-bit RISC-V Kernel Mode: ```text ## tools/configure.sh rv-virt:knsh64 nsh> getprime ... getprime took 441 msec nsh> hello Hello, World!! nsh> getprime ... getprime took 448 msec nsh> hello Hello, World!! ``` [(See the Complete Log)](https://gist.github.com/lupyuen/c58997a2600615f8114f6e07d8c6fc41) Thanks to @juniskane for tracking down the bug. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org