Skip to content

Commit

Permalink
riscv: pmp: don't reconfigure modes
Browse files Browse the repository at this point in the history
Previously PMP was avaible only with Multithreading, since it's now
available without MT - add extra checks to prevent user/kernel mode
reconfiguration.

Signed-off-by: Volodymyr Fialko <[email protected]>
Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
f0rget-the-sad authored and nashif committed Nov 20, 2024
1 parent 850d471 commit 0d66091
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions arch/riscv/core/isr.S
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ no_fp: /* increment _current->arch.exception_depth */
li t1, RISCV_EXC_ECALLU
beq t0, t1, is_user_syscall

#ifdef CONFIG_PMP_STACK_GUARD
#if defined(CONFIG_PMP_STACK_GUARD) && defined(CONFIG_MULTITHREADING)
/*
* Determine if we come from user space. If so, reconfigure the PMP for
* kernel mode stack guard.
Expand Down Expand Up @@ -397,7 +397,7 @@ is_kernel_syscall:
addi t0, t0, 4
sr t0, __struct_arch_esf_mepc_OFFSET(sp)

#ifdef CONFIG_PMP_STACK_GUARD
#if defined(CONFIG_PMP_STACK_GUARD) && defined(CONFIG_MULTITHREADING)
/* Re-activate PMP for m-mode */
li t1, MSTATUS_MPP
csrc mstatus, t1
Expand Down Expand Up @@ -508,7 +508,7 @@ do_irq_offload:
#ifdef CONFIG_USERSPACE
is_user_syscall:

#ifdef CONFIG_PMP_STACK_GUARD
#if defined(CONFIG_PMP_STACK_GUARD) && defined(CONFIG_MULTITHREADING)
/*
* We came from userspace and need to reconfigure the
* PMP for kernel mode stack guard.
Expand Down Expand Up @@ -578,7 +578,7 @@ valid_syscall_id:

is_interrupt:

#ifdef CONFIG_PMP_STACK_GUARD
#if defined(CONFIG_PMP_STACK_GUARD) && defined(CONFIG_MULTITHREADING)
#ifdef CONFIG_USERSPACE
/*
* If we came from userspace then we need to reconfigure the
Expand Down Expand Up @@ -748,7 +748,7 @@ fp_trap_exit:
and t0, t2, t1
bnez t0, 1f

#ifdef CONFIG_PMP_STACK_GUARD
#if defined(CONFIG_PMP_STACK_GUARD) && defined(CONFIG_MULTITHREADING)
/* Remove kernel stack guard and Reconfigure PMP for user mode */
lr a0, ___cpu_t_current_OFFSET(s0)
call z_riscv_pmp_usermode_enable
Expand Down

0 comments on commit 0d66091

Please sign in to comment.