arch: riscv: handle PMP setting for _Fault handler#75960
arch: riscv: handle PMP setting for _Fault handler#75960nashif merged 2 commits intozephyrproject-rtos:mainfrom
Conversation
|
A few comments:
|
When RISCV_ALWAYS_SWITCH_THROUGH_ECALL is enabled, do_swap() enables PMP checking in is_kernel_syscall. If a user thread violates memory protection and do_swap() is called from the fault handler, a PMP error occurs because the thread is in privileged mode but still using the old user mode PMP setting. Update the PMP setting to privileged mode for fault handler. This also enables the stack guard for user thread's privileged stack in fault handler. Signed-off-by: Jimmy Zheng <jimmyzhe@andestech.com>
When RISCV_ALWAYS_SWITCH_THROUGH_ECALL is enabled, do_swap() enables PMP checking in is_kernel_syscall. If the PMP stack guard is triggered and do_swap() is called from the fault handler, a PMP error occurs because the stack usage violates the previous PMP setting. Remove the stack guard setting during a stack overflow handler to allow enabling PMP checking safely in fault handler. Signed-off-by: Jimmy Zheng <jimmyzhe@andestech.com>
af8175e to
2f3ae20
Compare
|
@npitre, thank you for your feedback.
The first commit majorly change PMP setting to privileged mode for faults from user mode.
These commits are independent to fix 2 different cases:
Disabling |
When
CONFIG_RISCV_ALWAYS_SWITCH_THROUGH_ECALLis enabled,do_swap()from_Faulttriggers a PMP error again if the fault is caused by a PMP violation. This PR handles the PMP settings for faults caused by PMP violations:For kernel thread stack overflow:
Remove the previous thread's PMP configuration.
For user thread violates memory protection:
Configure the PMP for the thread's privileged stack.
Although this bug occurs only when
CONFIG_RISCV_ALWAYS_SWITCH_THROUGH_ECALLis enabled, I think these fixes are also compatible whenCONFIG_RISCV_ALWAYS_SWITCH_THROUGH_ECALLis disabled.Fixes: #75959