Skip to content

Commit be92659

Browse files
committed
Terminate tasks on unrecoverable PMP access faults
When PMP access fault recovery fails, the system previously panicked regardless of context. This change allows graceful degradation by terminating only the faulting task when the fault occurs in task context. The trap handler now checks if a current task exists after PMP fault recovery fails. If so, it terminates that task using the deferred cleanup mechanism. If no task context exists, the system still panics as before, since the fault must have occurred in kernel code. This prevents a single misbehaving task from crashing the entire system while still catching genuine kernel bugs.
1 parent d1b2a0a commit be92659

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/riscv/hal.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,14 @@ void do_trap(uint32_t cause, uint32_t epc, uint32_t mtval)
304304
reason = exc_msg[code];
305305

306306
/* Attempt to recover PMP access faults */
307-
if ((code == 5 || code == 7) && pmp_handle_access_fault(mtval, code == 7) == 0)
308-
return;
307+
if (code == 5 || code == 7) {
308+
if (pmp_handle_access_fault(mtval, code == 7) == 0)
309+
return;
310+
311+
/* Recovery failed - terminate task if in task context */
312+
if (kcb && kcb->task_current && kcb->task_current->data)
313+
task_terminate_current();
314+
}
309315

310316
/* All other exceptions are fatal */
311317
printf("[EXCEPTION] code=%u (%s), epc=%08x, cause=%08x\n", code, reason,

0 commit comments

Comments
 (0)