Skip to content

Commit 1d2b8fc

Browse files
committed
arch/riscv: Defer locking of interrupt stack guard PMP entry
The PMP entry for the interrupt stack guard is initially configured in `z_riscv_pmp_init()`. This entry was previously locked immediately using the `PMP_L` (Lock) flag. This immediate locking causes issues in complex boot scenarios, such as systems that jump from a Read-Only (RO) image to a Read-Write (RW) image. When switching images, the kernel must re-initialize PMP. If the interrupt stack address, calculated as `(uintptr_t)z_interrupt_stacks[_current_cpu->id]`, changes between the RO and RW stages, the already-locked PMP entry for the original address cannot be reconfigured, leading to an incorrect or inoperable memory protection setup. This commit removes the premature `PMP_L` flag from the PMP entry setup in `z_riscv_pmp_init()`. The essential locking of the interrupt stack guard will now be deferred and correctly applied within `z_riscv_pmp_stackguard_enable()`, which is executed only when the system is ready and the conditions `defined(CONFIG_PMP_STACK_GUARD) && defined(CONFIG_MULTITHREADING)` are met. Signed-off-by: Firas Sammoura <[email protected]>
1 parent b8576db commit 1d2b8fc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/riscv/core/pmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void z_riscv_pmp_init(void)
378378
* addresses inaccessible. This will never change so we do it here
379379
* and lock it too.
380380
*/
381-
set_pmp_entry(&index, PMP_NONE | PMP_L,
381+
set_pmp_entry(&index, PMP_NONE,
382382
(uintptr_t)z_interrupt_stacks[_current_cpu->id],
383383
Z_RISCV_STACK_GUARD_SIZE,
384384
pmp_addr, pmp_cfg, ARRAY_SIZE(pmp_addr));

0 commit comments

Comments
 (0)