arch/x86/mm/fault.c
Source file repositories/reference/linux-study-clean/arch/x86/mm/fault.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/mm/fault.c- Extension
.c- Size
- 42850 bytes
- Lines
- 1541
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched.hlinux/sched/task_stack.hlinux/kdebug.hlinux/memblock.hlinux/bpf_defs.hlinux/kfence.hlinux/kprobes.hlinux/mmiotrace.hlinux/perf_event.hlinux/hugetlb.hlinux/context_tracking.hlinux/uaccess.hlinux/efi.hlinux/mm_types.hlinux/mm.hlinux/vmalloc.hasm/cpufeature.hasm/traps.hasm/fixmap.hasm/vsyscall.hasm/vm86.hasm/mmu_context.hasm/efi.hasm/desc.hasm/cpu_entry_area.hasm/pgtable_areas.hasm/kvm_para.hasm/vdso.hasm/irq_stack.hasm/fred.hasm/sev.htrace/events/exceptions.h
Detected Declarations
function Copyrightfunction check_prefetch_opcodefunction is_amd_k8_pre_nptfunction is_prefetchfunction vmalloc_faultfunction arch_sync_kernel_mappingsfunction list_for_each_entryfunction low_pfnfunction dump_pagetablefunction bad_addressfunction dump_pagetablefunction is_errata93function is_errata100function is_f00f_bugfunction show_ldttssfunction show_fault_oopsfunction pgtable_badfunction sanitize_error_codefunction set_signal_archinfofunction page_fault_oopsfunction get_stack_guard_infofunction kernelmode_fixup_or_oopsfunction show_signal_msgfunction __bad_area_nosemaphorefunction bad_area_nosemaphorefunction __bad_areafunction bad_area_access_from_pkeysfunction bad_area_access_errorfunction do_sigbusfunction spurious_kernel_fault_checkfunction pagefunction access_errorfunction accessesfunction fault_in_kernel_spacefunction do_kern_addr_faultfunction vmalloc_faultfunction do_user_addr_faultfunction addressfunction trace_page_fault_entriesfunction handle_page_fault
Annotated Snippet
fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs);
if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
vma_end_read(vma);
if (!(fault & VM_FAULT_RETRY)) {
count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
goto done;
}
count_vm_vma_lock_event(VMA_LOCK_RETRY);
if (fault & VM_FAULT_MAJOR)
flags |= FAULT_FLAG_TRIED;
/* Quick path to respond to signals */
if (fault_signal_pending(fault, regs)) {
if (!user_mode(regs))
kernelmode_fixup_or_oops(regs, error_code, address,
SIGBUS, BUS_ADRERR,
ARCH_DEFAULT_PKEY);
return;
}
lock_mmap:
retry:
vma = lock_mm_and_find_vma(mm, address, regs);
if (unlikely(!vma)) {
bad_area_nosemaphore(regs, error_code, address);
return;
}
/*
* Ok, we have a good vm_area for this memory access, so
* we can handle it..
*/
if (unlikely(access_error(error_code, vma))) {
bad_area_access_error(regs, error_code, address, mm, vma);
return;
}
/*
* If for any reason at all we couldn't handle the fault,
* make sure we exit gracefully rather than endlessly redo
* the fault. Since we never set FAULT_FLAG_RETRY_NOWAIT, if
* we get VM_FAULT_RETRY back, the mmap_lock has been unlocked.
*
* Note that handle_userfault() may also release and reacquire mmap_lock
* (and not return with VM_FAULT_RETRY), when returning to userland to
* repeat the page fault later with a VM_FAULT_NOPAGE retval
* (potentially after handling any pending signal during the return to
* userland). The return to userland is identified whenever
* FAULT_FLAG_USER|FAULT_FLAG_KILLABLE are both set in flags.
*/
fault = handle_mm_fault(vma, address, flags, regs);
if (fault_signal_pending(fault, regs)) {
/*
* Quick path to respond to signals. The core mm code
* has unlocked the mm for us if we get here.
*/
if (!user_mode(regs))
kernelmode_fixup_or_oops(regs, error_code, address,
SIGBUS, BUS_ADRERR,
ARCH_DEFAULT_PKEY);
return;
}
/* The fault is fully completed (including releasing mmap lock) */
if (fault & VM_FAULT_COMPLETED)
return;
/*
* If we need to retry the mmap_lock has already been released,
* and if there is a fatal signal pending there is no guarantee
* that we made any progress. Handle this case first.
*/
if (unlikely(fault & VM_FAULT_RETRY)) {
flags |= FAULT_FLAG_TRIED;
goto retry;
}
mmap_read_unlock(mm);
done:
if (likely(!(fault & VM_FAULT_ERROR)))
return;
if (fatal_signal_pending(current) && !user_mode(regs)) {
kernelmode_fixup_or_oops(regs, error_code, address,
0, 0, ARCH_DEFAULT_PKEY);
return;
}
Annotation
- Immediate include surface: `linux/sched.h`, `linux/sched/task_stack.h`, `linux/kdebug.h`, `linux/memblock.h`, `linux/bpf_defs.h`, `linux/kfence.h`, `linux/kprobes.h`, `linux/mmiotrace.h`.
- Detected declarations: `function Copyright`, `function check_prefetch_opcode`, `function is_amd_k8_pre_npt`, `function is_prefetch`, `function vmalloc_fault`, `function arch_sync_kernel_mappings`, `function list_for_each_entry`, `function low_pfn`, `function dump_pagetable`, `function bad_address`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.