From 0d66091cce5d5fd50afe5b24968e4d698361eb1f Mon Sep 17 00:00:00 2001 From: Volodymyr Fialko Date: Wed, 20 Nov 2024 19:38:46 +0100 Subject: [PATCH] riscv: pmp: don't reconfigure modes 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 Signed-off-by: Anas Nashif --- arch/riscv/core/isr.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/riscv/core/isr.S b/arch/riscv/core/isr.S index 5ac71fe17b4734..1def6cfa62d141 100644 --- a/arch/riscv/core/isr.S +++ b/arch/riscv/core/isr.S @@ -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. @@ -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 @@ -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. @@ -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 @@ -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