-
Notifications
You must be signed in to change notification settings - Fork 8.1k
arch: riscv: Add function to clear all unlocked PMP entries #97310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2a291aa
to
4507398
Compare
tested on my side:
---> Call the
|
a13cada
to
d17e907
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need automated testing in https://github.com/zephyrproject-rtos/zephyr/tree/main/tests/arch/riscv/pmp
This is better suited to be tested once the multi-threading units test get merged: I have experimented with the framework and I should be able to add unit tests. Currently, we are only testing single threads (no multithreading config) and all entries are locked. So adding a PMP reset will not yield meaningful results. |
617f99f
to
a74f2ae
Compare
Introduce `z_riscv_pmp_write_config` to abstract writing to pmpcfg registers. This function handles the differing register layouts and slot counts between RV32 and RV64 architectures, writing to the appropriate pmpcfg0, pmpcfg1, pmpcfg2, or pmpcfg3 CSRs as needed based on CONFIG_PMP_SLOTS. Signed-off-by: Firas Sammoura <[email protected]>
a74f2ae
to
599bde7
Compare
b176616
to
c2e5694
Compare
The PR has been modified and a uint test was included |
Introduce the new function `riscv_pmp_clear_all()` to reset the Physical Memory Protection (PMP) configuration. This function iterates through all configured PMP slots. For each entry, it writes 0x0 to the entry's 8-bit configuration register. This action attempts to clear all fields, including the Address Matching Mode (A) bits (setting the region type to OFF), the permission bits (R, W, X), and the Lock (L) bit. According to the RISC-V specification, any writes to the configuration or address registers of a locked PMP entry are ignored. Thus, locked entries will remain unchanged, while all non-locked entries will be effectively disabled and their permissions cleared. The function ensures it operates in Machine mode with MSTATUS.MPRV = 0 and MSTATUS.MPP = M-mode before modifying any PMP Control and Status Registers (CSRs). This provides a mechanism to clear all non-locked PMP regions, returning them to a default disabled state. The function declaration is exposed in the `include/zephyr/arch/riscv/pmp.h` header file, making it available for inclusion and use by external modules. It is recommended for firmware to call this function before transitioning from a Read-Only (RO) stage to a Read-Write (RW) stage. This ensures that any PMP settings established during the RO phase, which might no longer be appropriate, are cleared, providing a clean and secure base PMP configuration for the RW firmware. Signed-off-by: Firas Sammoura <[email protected]>
21ad35f
to
1dad080
Compare
Adds a new test suite to verify the behavior of `riscv_pmp_clear_all()`. These tests ensure that the function correctly clears all unlocked PMP entries while preserving any entries that are locked. Signed-off-by: Firas Sammoura <[email protected]>
1dad080
to
4d6025c
Compare
|
Introduce the new function
riscv_pmp_clear_all()
to securely reset the Physical Memory Protection (PMP) configuration.This function iterates through all configured PMP slots. For each entry, it checks if the Lock (L) bit is set. If the entry is not locked, it clears the Address Matching Mode (A) bits, effectively setting the region type to OFF (Null Region), disabling the entry.
The function ensures it operates in Machine mode with MSTATUS.MPRV = 0 before modifying any PMP Control and Status Registers (CSRs).
This provides a mechanism to clear all non-locked PMP regions, returning them to a default disabled state. The function is exposed in the pmp.h header file.