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:
parent
7a55bda7e1
commit
2fece49a14
9 changed files with 118 additions and 50 deletions
|
@ -246,11 +246,6 @@ skip_store_fp_caller_saved:
|
|||
/* If a0 != 0, jump to is_interrupt */
|
||||
bnez a0, is_interrupt
|
||||
|
||||
#ifdef CONFIG_PMP_STACK_GUARD
|
||||
li t0, MSTATUS_MPRV
|
||||
csrs mstatus, t0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If the exception is the result of an ECALL, check whether to
|
||||
* perform a context-switch or an IRQ offload. Otherwise call _Fault
|
||||
|
@ -301,6 +296,14 @@ is_kernel_syscall:
|
|||
addi t0, t0, 4
|
||||
sr t0, __z_arch_esf_t_mepc_OFFSET(sp)
|
||||
|
||||
#ifdef CONFIG_PMP_STACK_GUARD
|
||||
/* Re-activate PMP for m-mode */
|
||||
li t1, MSTATUS_MPP
|
||||
csrc mstatus, t1
|
||||
li t1, MSTATUS_MPRV
|
||||
csrs mstatus, t1
|
||||
#endif
|
||||
|
||||
/* Determine what to do. Operation code is in a7. */
|
||||
lr a7, __z_arch_esf_t_a7_OFFSET(sp)
|
||||
|
||||
|
@ -356,6 +359,16 @@ do_irq_offload:
|
|||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
is_user_syscall:
|
||||
|
||||
#ifdef CONFIG_PMP_STACK_GUARD
|
||||
/*
|
||||
* We came from userspace and need to reconfigure the
|
||||
* PMP for kernel mode stack guard.
|
||||
*/
|
||||
lr a0, ___cpu_t_current_OFFSET(s0)
|
||||
call z_riscv_pmp_stackguard_enable
|
||||
#endif
|
||||
|
||||
/* It is safe to re-enable IRQs now */
|
||||
csrs mstatus, MSTATUS_IEN
|
||||
|
||||
|
@ -405,6 +418,29 @@ valid_syscall_id:
|
|||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
is_interrupt:
|
||||
|
||||
#ifdef CONFIG_PMP_STACK_GUARD
|
||||
#ifdef CONFIG_USERSPACE
|
||||
/*
|
||||
* If we came from userspace then we need to reconfigure the
|
||||
* PMP for kernel mode stack guard.
|
||||
*/
|
||||
lr t0, __z_arch_esf_t_mstatus_OFFSET(sp)
|
||||
li t1, MSTATUS_MPP
|
||||
and t0, t0, t1
|
||||
bnez t0, 1f
|
||||
lr a0, ___cpu_t_current_OFFSET(s0)
|
||||
call z_riscv_pmp_stackguard_enable
|
||||
j 2f
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
1: /* Re-activate PMP for m-mode */
|
||||
li t1, MSTATUS_MPP
|
||||
csrc mstatus, t1
|
||||
li t1, MSTATUS_MPRV
|
||||
csrs mstatus, t1
|
||||
2:
|
||||
#endif
|
||||
|
||||
/* Increment _current_cpu->nested */
|
||||
lw t3, ___cpu_t_nested_OFFSET(s0)
|
||||
addi t4, t3, 1
|
||||
|
@ -547,6 +583,12 @@ no_fp: /* make sure this is reflected in the restored mstatus */
|
|||
and t0, t4, t1
|
||||
bnez t0, 1f
|
||||
|
||||
#ifdef CONFIG_PMP_STACK_GUARD
|
||||
/* Remove kernel stack guard and Reconfigure PMP for user mode */
|
||||
lr a0, ___cpu_t_current_OFFSET(s0)
|
||||
call z_riscv_pmp_usermode_enable
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_SMP)
|
||||
/* Set user mode variable */
|
||||
li t0, 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue