include/linux/userfaultfd_k.h
Source file repositories/reference/linux-study-clean/include/linux/userfaultfd_k.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/userfaultfd_k.h- Extension
.h- Size
- 12230 bytes
- Lines
- 433
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/userfaultfd.hlinux/fcntl.hlinux/mm.hlinux/swap.hlinux/leafops.hasm-generic/pgtable_uffd.hlinux/hugetlb_inline.h
Detected Declarations
struct userfaultfd_ctxstruct vm_uffd_opsenum mfill_atomic_modefunction uffd_flags_mode_isfunction uffd_flags_set_modefunction is_mergeable_vm_userfaultfd_ctxfunction uffd_disable_huge_pmd_sharefunction pte_nonefunction userfaultfd_missingfunction userfaultfd_wpfunction userfaultfd_minorfunction userfaultfd_pte_wpfunction userfaultfd_huge_pmd_wpfunction userfaultfd_armedfunction vma_has_uffd_without_event_remapfunction userfaultfd_wp_use_markersfunction formsfunction handle_userfaultfunction uffd_wp_rangefunction is_mergeable_vm_userfaultfd_ctxfunction userfaultfd_missingfunction userfaultfd_wpfunction userfaultfd_minorfunction userfaultfd_pte_wpfunction userfaultfd_huge_pmd_wpfunction userfaultfd_armedfunction dup_userfaultfdfunction dup_userfaultfd_completefunction userfaultfd_unmap_prepfunction userfaultfd_unmap_completefunction userfaultfd_wp_unpopulatedfunction userfaultfd_wp_asyncfunction vma_has_uffd_without_event_remapfunction userfaultfd_wp_use_markersfunction forms
Annotated Snippet
struct userfaultfd_ctx {
/* waitqueue head for the pending (i.e. not read) userfaults */
wait_queue_head_t fault_pending_wqh;
/* waitqueue head for the userfaults */
wait_queue_head_t fault_wqh;
/* waitqueue head for the pseudo fd to wakeup poll/read */
wait_queue_head_t fd_wqh;
/* waitqueue head for events */
wait_queue_head_t event_wqh;
/* a refile sequence protected by fault_pending_wqh lock */
seqcount_spinlock_t refile_seq;
/* pseudo fd refcounting */
refcount_t refcount;
/* userfaultfd syscall flags */
unsigned int flags;
/* features requested from the userspace */
unsigned int features;
/* released */
bool released;
/*
* Prevents userfaultfd operations (fill/move/wp) from happening while
* some non-cooperative event(s) is taking place. Increments are done
* in write-mode. Whereas, userfaultfd operations, which includes
* reading mmap_changing, is done under read-mode.
*/
struct rw_semaphore map_changing_lock;
/* memory mappings are changing because of non-cooperative event */
atomic_t mmap_changing;
/* mm with one ore more vmas attached to this userfaultfd_ctx */
struct mm_struct *mm;
};
extern vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason);
/* VMA userfaultfd operations */
struct vm_uffd_ops {
/* Checks if a VMA can support userfaultfd */
bool (*can_userfault)(struct vm_area_struct *vma, vm_flags_t vm_flags);
/*
* Called to resolve UFFDIO_CONTINUE request.
* Should return the folio found at pgoff in the VMA's pagecache if it
* exists or ERR_PTR otherwise.
* The returned folio is locked and with reference held.
*/
struct folio *(*get_folio_noalloc)(struct inode *inode, pgoff_t pgoff);
/*
* Called during resolution of UFFDIO_COPY request.
* Should allocate and return a folio or NULL if allocation fails.
*/
struct folio *(*alloc_folio)(struct vm_area_struct *vma,
unsigned long addr);
/*
* Called during resolution of UFFDIO_COPY request.
* Should only be called with a folio returned by alloc_folio() above.
* The folio will be set to locked.
* Returns 0 on success, error code on failure.
*/
int (*filemap_add)(struct folio *folio, struct vm_area_struct *vma,
unsigned long addr);
/*
* Called during resolution of UFFDIO_COPY request on the error
* handling path.
* Should revert the operation of ->filemap_add().
*/
void (*filemap_remove)(struct folio *folio, struct vm_area_struct *vma);
};
/* A combined operation mode + behavior flags. */
typedef unsigned int __bitwise uffd_flags_t;
/* Mutually exclusive modes of operation. */
enum mfill_atomic_mode {
MFILL_ATOMIC_COPY,
MFILL_ATOMIC_ZEROPAGE,
MFILL_ATOMIC_CONTINUE,
MFILL_ATOMIC_POISON,
NR_MFILL_ATOMIC_MODES,
};
#define MFILL_ATOMIC_MODE_BITS (const_ilog2(NR_MFILL_ATOMIC_MODES - 1) + 1)
#define MFILL_ATOMIC_BIT(nr) BIT(MFILL_ATOMIC_MODE_BITS + (nr))
#define MFILL_ATOMIC_FLAG(nr) ((__force uffd_flags_t) MFILL_ATOMIC_BIT(nr))
#define MFILL_ATOMIC_MODE_MASK ((__force uffd_flags_t) (MFILL_ATOMIC_BIT(0) - 1))
static inline bool uffd_flags_mode_is(uffd_flags_t flags, enum mfill_atomic_mode expected)
{
return (flags & MFILL_ATOMIC_MODE_MASK) == ((__force uffd_flags_t) expected);
}
static inline uffd_flags_t uffd_flags_set_mode(uffd_flags_t flags, enum mfill_atomic_mode mode)
Annotation
- Immediate include surface: `linux/userfaultfd.h`, `linux/fcntl.h`, `linux/mm.h`, `linux/swap.h`, `linux/leafops.h`, `asm-generic/pgtable_uffd.h`, `linux/hugetlb_inline.h`.
- Detected declarations: `struct userfaultfd_ctx`, `struct vm_uffd_ops`, `enum mfill_atomic_mode`, `function uffd_flags_mode_is`, `function uffd_flags_set_mode`, `function is_mergeable_vm_userfaultfd_ctx`, `function uffd_disable_huge_pmd_share`, `function pte_none`, `function userfaultfd_missing`, `function userfaultfd_wp`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
- 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.