mm/userfaultfd.c
Source file repositories/reference/linux-study-clean/mm/userfaultfd.c
File Facts
- System
- Linux kernel
- Corpus path
mm/userfaultfd.c- Extension
.c- Size
- 120865 bytes
- Lines
- 4543
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- 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/mm.hlinux/sched/signal.hlinux/pagemap.hlinux/rmap.hlinux/swap.hlinux/leafops.hlinux/userfaultfd_k.hlinux/mmu_notifier.hlinux/hugetlb.hlinux/list.hlinux/sched/mm.hlinux/mm_inline.hlinux/poll.hlinux/slab.hlinux/seq_file.hlinux/bug.hlinux/anon_inodes.hlinux/syscalls.hlinux/miscdevice.hlinux/uio.hlinux/file.hlinux/cleanup.hasm/tlbflush.hasm/tlb.hinternal.hswap.h
Detected Declarations
syscall userfaultfdstruct mfill_statestruct mfill_retry_statestruct userfaultfd_fork_ctxstruct userfaultfd_unmap_ctxstruct userfaultfd_wait_queuestruct userfaultfd_wake_rangefunction anon_can_userfaultfunction validate_dst_vmafunction uffd_lock_vmafunction uffd_mfill_unlockfunction uffd_mfill_unlockfunction mfill_put_vmafunction mfill_get_vmafunction mfill_establish_pmdfunction mfill_file_over_sizefunction mfill_atomic_install_ptefunction mfill_copy_folio_lockedfunction mfill_retry_state_savefunction mfill_retry_state_changedfunction mfill_retry_state_putfunction mfill_copy_folio_retryfunction __mfill_atomic_ptefunction mfill_get_vmafunction mfill_atomic_pte_copyfunction mfill_atomic_pte_zeroed_foliofunction mfill_atomic_pte_zeropagefunction mfill_atomic_pte_continuefunction mfill_atomic_pte_poisonfunction mfill_atomic_hugetlbfunction mfill_atomic_ptefunction mfill_atomicfunction mfill_atomic_copyfunction mfill_atomic_zeropagefunction mfill_atomic_continuefunction mfill_atomic_poisonfunction uffd_wp_rangefunction mwriteprotect_rangefunction double_pt_lockfunction double_pt_unlockfunction is_pte_pages_stablefunction folio_trylockfunction folio_maybe_dma_pinnedfunction move_swap_ptefunction move_zeropage_ptefunction move_pages_ptesfunction pmd_trans_hugefunction split_folio
Annotated Snippet
SYSCALL_DEFINE1(userfaultfd, int, flags)
{
if (!userfaultfd_syscall_allowed(flags))
return -EPERM;
return new_userfaultfd(flags);
}
static long userfaultfd_dev_ioctl(struct file *file, unsigned int cmd, unsigned long flags)
{
if (cmd != USERFAULTFD_IOC_NEW)
return -EINVAL;
return new_userfaultfd(flags);
}
static const struct file_operations userfaultfd_dev_fops = {
.unlocked_ioctl = userfaultfd_dev_ioctl,
.compat_ioctl = userfaultfd_dev_ioctl,
.owner = THIS_MODULE,
.llseek = noop_llseek,
};
static struct miscdevice userfaultfd_misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = "userfaultfd",
.fops = &userfaultfd_dev_fops
};
static int __init userfaultfd_init(void)
{
int ret;
ret = misc_register(&userfaultfd_misc);
if (ret)
return ret;
userfaultfd_ctx_cachep = kmem_cache_create("userfaultfd_ctx_cache",
sizeof(struct userfaultfd_ctx),
0,
SLAB_HWCACHE_ALIGN|SLAB_PANIC,
init_once_userfaultfd_ctx);
#ifdef CONFIG_SYSCTL
register_sysctl_init("vm", vm_userfaultfd_table);
#endif
return 0;
}
__initcall(userfaultfd_init);
Annotation
- Immediate include surface: `linux/mm.h`, `linux/sched/signal.h`, `linux/pagemap.h`, `linux/rmap.h`, `linux/swap.h`, `linux/leafops.h`, `linux/userfaultfd_k.h`, `linux/mmu_notifier.h`.
- Detected declarations: `syscall userfaultfd`, `struct mfill_state`, `struct mfill_retry_state`, `struct userfaultfd_fork_ctx`, `struct userfaultfd_unmap_ctx`, `struct userfaultfd_wait_queue`, `struct userfaultfd_wake_range`, `function anon_can_userfault`, `function validate_dst_vma`, `function uffd_lock_vma`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: core 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.