Skip to content

Commit c435e93

Browse files
authored
fix(exec): clean robust futex state before mm replacement (#2191)
Successful exec replaced the current address space while leaving the task's robust-list registration pointing into the old mm. A later task exit attempted to walk that stale userspace list, producing recoverable missing-VMA faults and skipping the required owner-death transition. Take robust-list ownership exactly once and reuse one cleanup core for exit and exec. During the successful exec commit, temporarily restore the old mm, perform best-effort owner-death cleanup, and switch back to the new mm. Keep failed exec paths unchanged. Align exec mm switching with the scheduler's active-CPU and TLB ordering. Replace raw userspace AtomicU32 operations with exception-table-protected cmpxchg implementations for x86_64, RISC-V, and LoongArch, including 32-bit sign-extension and weak LL/SC ordering requirements. Validate robust entries, preserve PI and pending metadata, use namespace-visible task IDs, and stop safely on malformed userspace state. Defer missing-VMA diagnostics until exception-table recovery fails so expected nofault accesses do not emit misleading errors. Add exec ABI coverage for owner-death cleanup, registration reset, deterministic read-only futex faults, and early and late exec failure preservation. Signed-off-by: longjin <longjin@dragonos.org>
1 parent 567e2b1 commit c435e93

6 files changed

Lines changed: 501 additions & 129 deletions

File tree

kernel/src/arch/x86_64/mm/fault.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,19 @@ impl X86_64MMArch {
347347
continue;
348348
}
349349

350-
log::error!(
351-
"pid:{}, can not find nearest vma, \n\terror_code: {:?}, address: {:#x}, rip: {:#x}",
352-
ProcessManager::current_pid().data(),
353-
error_code,
354-
address.data(),
355-
regs.rip,
356-
);
357-
358-
// VMA不存在,检查是否需要异常表修复
350+
// No VMA exists, so try an exception-table fixup first.
359351
if handle_kernel_access_failed(regs) {
360-
return; // 已通过异常表修复
352+
return;
361353
}
362354

355+
log::error!(
356+
"pid:{}, can not find nearest vma, \n\terror_code: {:?}, address: {:#x}, rip: {:#x}",
357+
ProcessManager::current_pid().data(),
358+
error_code,
359+
address.data(),
360+
regs.rip,
361+
);
362+
363363
send_segv_maperr();
364364
return;
365365
}
@@ -469,19 +469,20 @@ impl X86_64MMArch {
469469
drop(space_guard);
470470
continue 'fault_retry;
471471
} else {
472-
log::error!(
473-
"pid: {} No mapped vma, error_code: {:?},rip:{:#x}, address: {:#x}, flags: {:?}",
474-
ProcessManager::current_pid().data(),
475-
error_code,
476-
regs.rip,
477-
address.data(),
478-
flags
479-
);
480-
// 地址不在VMA范围内,检查是否需要异常表修复
472+
// The address is outside every VMA; try an exception-table fixup first.
481473
if handle_kernel_access_failed(regs) {
482-
return; // 已通过异常表修复
474+
return;
483475
}
484476

477+
log::error!(
478+
"pid: {} No mapped vma, error_code: {:?},rip:{:#x}, address: {:#x}, flags: {:?}",
479+
ProcessManager::current_pid().data(),
480+
error_code,
481+
regs.rip,
482+
address.data(),
483+
flags
484+
);
485+
485486
send_segv_maperr();
486487
return;
487488
}

0 commit comments

Comments
 (0)