riscv: pmp: Ensure trailing PMP entries are cleared #97238
+1
−1
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.
In
z_riscv_pmp_stackguard_enable
, the call towrite_pmp_entries
has been updated to set theclear_trailing_entries
argument totrue
.This change ensures that any PMP entries beyond the ones being actively configured are disabled. This is particularly critical for systems transitioning between different execution stages, such as jumping from Read-Only (RO) firmware to Read-Write (RW) firmware, where each stage may define its own set of PMP entries.
Without clearing, stale configurations from the RO stage could persist after transitioning to the RW stage. While the presence of a catch-all PMP entry might render this change somewhat cosmetic in terms of security, explicitly clearing unused trailing entries ensures a cleaner PMP state. This not only helps prevent subtle functional bugs due to unexpected lingering permissions but also significantly improves clarity during visual debugging of the PMP register settings.