2 * include/linux/userfaultfd_k.h
4 * Copyright (C) 2015 Red Hat, Inc.
8 #ifndef _LINUX_USERFAULTFD_K_H
9 #define _LINUX_USERFAULTFD_K_H
11 #ifdef CONFIG_USERFAULTFD
13 #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */
15 #include <linux/fcntl.h>
18 * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
19 * new flags, since they might collide with O_* ones. We want
20 * to re-use O_* flags that couldn't possibly have a meaning
21 * from userfaultfd, in order to leave a free define-space for
24 #define UFFD_CLOEXEC O_CLOEXEC
25 #define UFFD_NONBLOCK O_NONBLOCK
27 #define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
28 #define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS)
30 extern int handle_userfault(struct vm_fault *vmf, unsigned long reason);
32 extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start,
33 unsigned long src_start, unsigned long len);
34 extern ssize_t mfill_zeropage(struct mm_struct *dst_mm,
35 unsigned long dst_start,
39 static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
40 struct vm_userfaultfd_ctx vm_ctx)
42 return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx;
45 static inline bool userfaultfd_missing(struct vm_area_struct *vma)
47 return vma->vm_flags & VM_UFFD_MISSING;
50 static inline bool userfaultfd_armed(struct vm_area_struct *vma)
52 return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
55 extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
56 extern void dup_userfaultfd_complete(struct list_head *);
58 extern void mremap_userfaultfd_prep(struct vm_area_struct *,
59 struct vm_userfaultfd_ctx *);
60 extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *,
61 unsigned long from, unsigned long to,
64 extern bool userfaultfd_remove(struct vm_area_struct *vma,
68 extern int userfaultfd_unmap_prep(struct vm_area_struct *vma,
69 unsigned long start, unsigned long end,
70 struct list_head *uf);
71 extern void userfaultfd_unmap_complete(struct mm_struct *mm,
72 struct list_head *uf);
74 #else /* CONFIG_USERFAULTFD */
77 static inline int handle_userfault(struct vm_fault *vmf, unsigned long reason)
79 return VM_FAULT_SIGBUS;
82 static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
83 struct vm_userfaultfd_ctx vm_ctx)
88 static inline bool userfaultfd_missing(struct vm_area_struct *vma)
93 static inline bool userfaultfd_armed(struct vm_area_struct *vma)
98 static inline int dup_userfaultfd(struct vm_area_struct *vma,
104 static inline void dup_userfaultfd_complete(struct list_head *l)
108 static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma,
109 struct vm_userfaultfd_ctx *ctx)
113 static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
120 static inline bool userfaultfd_remove(struct vm_area_struct *vma,
127 static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma,
128 unsigned long start, unsigned long end,
129 struct list_head *uf)
134 static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
135 struct list_head *uf)
139 #endif /* CONFIG_USERFAULTFD */
141 #endif /* _LINUX_USERFAULTFD_K_H */