Skip to content

risc-v/bl808: Flush MMU Cache after updating SATP#11585

Merged
xiaoxiang781216 merged 1 commit intoapache:masterfrom
lupyuen2:satp
Jan 23, 2024
Merged

risc-v/bl808: Flush MMU Cache after updating SATP#11585
xiaoxiang781216 merged 1 commit intoapache:masterfrom
lupyuen2:satp

Conversation

@lupyuen
Copy link
Copy Markdown
Member

@lupyuen lupyuen commented Jan 22, 2024

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

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:

## 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)

Regression Testing

For Regression Testing, we tested with QEMU 64-bit RISC-V Kernel Mode:

## 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)

Thanks to @juniskane for tracking down the bug.

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 xiaoxiang781216 merged commit 62c3589 into apache:master Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants