riscv: pmp: switch over to the new implementation

Add the appropriate hooks effectively replacing the old implementation
with the new one.

Also the stackguard wasn't properly enforced especially with the
usermode combination. This is now fixed.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2022-04-06 22:03:54 -04:00 committed by Carles Cufí
commit 2fece49a14
9 changed files with 118 additions and 50 deletions

View file

@ -75,19 +75,25 @@ skip_store_fp_callee_saved:
/* Get the new thread's stack pointer */
lr sp, _thread_offset_to_sp(a0)
#ifdef CONFIG_PMP_STACK_GUARD
/* Preserve a0 across following call. s0 is not yet restored. */
#if defined(CONFIG_PMP_STACK_GUARD)
/*
* Stack guard has priority over user space for PMP usage.
* Preserve a0 across following call. s0 is not yet restored.
*/
mv s0, a0
call z_riscv_configure_stack_guard
call z_riscv_pmp_stackguard_enable
mv a0, s0
#endif
#ifdef CONFIG_USERSPACE
#elif defined(CONFIG_USERSPACE)
/*
* When stackguard is not enabled, we need to configure the PMP only
* at context switch time as the PMP is not in effect while inm-mode.
* (it is done on every exception return otherwise).
*/
lb t0, _thread_offset_to_user_options(a0)
andi t0, t0, K_USER
beqz t0, not_user_task
mv s0, a0
call z_riscv_configure_user_allowed_stack
call z_riscv_pmp_usermode_enable
mv a0, s0
not_user_task:
#endif