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.

Dependency Surface

Detected Declarations

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

Implementation Notes