git: f9275f94f33b - stable/14 - riscv: Permit spurious faults in kernel mode
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 04 Jan 2025 14:08:14 UTC
The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f9275f94f33bd017a05ed791b1ee56a68ab42be7 commit f9275f94f33bd017a05ed791b1ee56a68ab42be7 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2024-12-10 15:07:28 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2025-01-04 13:56:34 +0000 riscv: Permit spurious faults in kernel mode Right now, pmap_enter() does not issue an sfence.vma after overwriting an invalid PTE, so the kernel can trigger a page fault when accessing a freshly created mapping. In this case, pmap_fault() can handle the exception, but we may panic before that. Move the check; this is consistent with arm64 and serves to ensure that we don't call vm_fault() etc. from a context where that's not permitted. Also fix a related bug: don't enable interrupts if they were disabled in the context where the exception occurred. Reviewed by: br Tested by: br MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47688 (cherry picked from commit c226f193515c8c0665610cb519fe381987f8ee24) --- sys/riscv/riscv/trap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/riscv/riscv/trap.c b/sys/riscv/riscv/trap.c index 3a7b3fba26b9..0b6db7982847 100644 --- a/sys/riscv/riscv/trap.c +++ b/sys/riscv/riscv/trap.c @@ -229,11 +229,6 @@ page_fault_handler(struct trapframe *frame, int usermode) pcb = td->td_pcb; stval = frame->tf_stval; - if (td->td_critnest != 0 || td->td_intr_nesting_level != 0 || - WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL, - "Kernel page fault") != 0) - goto fatal; - if (usermode) { if (!VIRT_IS_VALID(stval)) { call_trapsignal(td, SIGSEGV, SEGV_MAPERR, (void *)stval, @@ -246,7 +241,8 @@ page_fault_handler(struct trapframe *frame, int usermode) * Enable interrupts for the duration of the page fault. For * user faults this was done already in do_trap_user(). */ - intr_enable(); + if ((frame->tf_sstatus & SSTATUS_SIE) != 0) + intr_enable(); if (stval >= VM_MIN_KERNEL_ADDRESS) { map = kernel_map; @@ -270,6 +266,11 @@ page_fault_handler(struct trapframe *frame, int usermode) if (VIRT_IS_VALID(va) && pmap_fault(map->pmap, va, ftype)) goto done; + if (td->td_critnest != 0 || td->td_intr_nesting_level != 0 || + WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL, + "Kernel page fault") != 0) + goto fatal; + error = vm_fault_trap(map, va, ftype, VM_FAULT_NORMAL, &sig, &ucode); if (error != KERN_SUCCESS) { if (usermode) {