From bb4a97ec6304bf1f7f4a731f5a53268c1ec5bc79 Mon Sep 17 00:00:00 2001 From: vasilito Date: Sun, 26 Jul 2026 18:06:57 +0900 Subject: [PATCH] kernel: replace todo!() in page fault handler with SIGSEGV delivery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two todo!() calls in the user-space page fault correction path (memory/mod.rs:1238,1240) were boot-time bombs: Err(PfError::Oom) => todo!("oom") Err(PfError::NonfatalInternalError) => todo!() Both fire when try_correcting_page_tables fails during a correctable page fault. The OOM case triggers under memory pressure; the NonfatalInternalError case triggers on internal consistency issues (the name says 'nonfatal'). The previous todo!() panicked the kernel, taking down the whole system instead of just the faulting process. The fix delivers SIGSEGV to the faulting process (by falling through to the existing Err(Segv) path) and logs a warning. This matches the behaviour of the adjacent Segv/RecursionLimitExceeded arm. For the OOM case specifically: Linux would invoke the OOM killer here. Red Bear does not yet have an OOM killer — SIGSEGV is strictly better than kernel panic. A future round can add proper OOM handling. Part of the LG Gram Round 3 stub sweep. --- src/memory/mod.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 39891bc9fb..935940d487 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -1235,9 +1235,21 @@ pub fn page_fault_handler( let mut token = unsafe { CleanLockToken::new() }; match context::memory::try_correcting_page_tables(faulting_page, mode, &mut token) { Ok(()) => return Ok(()), - Err(PfError::Oom) => todo!("oom"), + Err(PfError::Oom) => { + // Kernel could not allocate a frame to correct the fault. + // Linux would invoke the OOM killer here; Red Bear does not + // yet have one. Deliver SIGSEGV to the faulting process + // rather than panicking the kernel (the previous todo!() + // was a boot-time bomb on memory-pressure systems). + warn!("memory: OOM during page fault correction, delivering SIGSEGV"); + } Err(PfError::Segv | PfError::RecursionLimitExceeded) => (), - Err(PfError::NonfatalInternalError) => todo!(), + Err(PfError::NonfatalInternalError) => { + // Internal consistency issue inside try_correcting_page_tables. + // The name says nonfatal — log and deliver SIGSEGV rather + // than panicking the kernel. + warn!("memory: nonfatal internal error during page fault correction, delivering SIGSEGV"); + } } }