risc-v/bl808: Flush MMU Cache after updating SATP#11585
Merged
xiaoxiang781216 merged 1 commit intoapache:masterfrom Jan 23, 2024
Merged
risc-v/bl808: Flush MMU Cache after updating SATP#11585xiaoxiang781216 merged 1 commit intoapache:masterfrom
xiaoxiang781216 merged 1 commit intoapache:masterfrom
Conversation
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`.
xiaoxiang781216
approved these changes
Jan 23, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Ox64 BL808 crashes with a Page Fault when we run
getprimethenhello. 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:
This is derived from the T-Head Errata for Linux Kernel. More details here
Modified Files
arch/risc-v/src/common/riscv_mmu.h: If needed,mmu_write_satp()callsmmu_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. Extendmmuflagsfrom 32-bit to 64-bit to be consistent withmmu_ln_setentry().boards/risc-v/bl808/ox64/configs/nsh/defconfig: Enableostestin the Build Config. UpdateCONFIG_BOARD_LOOPSPERMSECaccording tocalib_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
getprimethenhello:(See the Complete Log)
Regression Testing
For Regression Testing, we tested with QEMU 64-bit RISC-V Kernel Mode:
(See the Complete Log)
Thanks to @juniskane for tracking down the bug.