1 /* SPDX-License-Identifier: GPL-2.0 */
3 * include/linux/userfaultfd_k.h
5 * Copyright (C) 2015 Red Hat, Inc.
9 #ifndef _LINUX_USERFAULTFD_K_H
10 #define _LINUX_USERFAULTFD_K_H
12 #ifdef CONFIG_USERFAULTFD
14 #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */
16 #include <linux/fcntl.h>
19 * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
20 * new flags, since they might collide with O_* ones. We want
21 * to re-use O_* flags that couldn't possibly have a meaning
22 * from userfaultfd, in order to leave a free define-space for
25 #define UFFD_CLOEXEC O_CLOEXEC
26 #define UFFD_NONBLOCK O_NONBLOCK
28 #define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
29 #define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS)
31 extern int handle_userfault(struct vm_fault
*vmf
, unsigned long reason
);
33 extern ssize_t
mcopy_atomic(struct mm_struct
*dst_mm
, unsigned long dst_start
,
34 unsigned long src_start
, unsigned long len
);
35 extern ssize_t
mfill_zeropage(struct mm_struct
*dst_mm
,
36 unsigned long dst_start
,
40 static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct
*vma
,
41 struct vm_userfaultfd_ctx vm_ctx
)
43 return vma
->vm_userfaultfd_ctx
.ctx
== vm_ctx
.ctx
;
46 static inline bool userfaultfd_missing(struct vm_area_struct
*vma
)
48 return vma
->vm_flags
& VM_UFFD_MISSING
;
51 static inline bool userfaultfd_armed(struct vm_area_struct
*vma
)
53 return vma
->vm_flags
& (VM_UFFD_MISSING
| VM_UFFD_WP
);
56 extern int dup_userfaultfd(struct vm_area_struct
*, struct list_head
*);
57 extern void dup_userfaultfd_complete(struct list_head
*);
59 extern void mremap_userfaultfd_prep(struct vm_area_struct
*,
60 struct vm_userfaultfd_ctx
*);
61 extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx
*,
62 unsigned long from
, unsigned long to
,
65 extern bool userfaultfd_remove(struct vm_area_struct
*vma
,
69 extern int userfaultfd_unmap_prep(struct vm_area_struct
*vma
,
70 unsigned long start
, unsigned long end
,
71 struct list_head
*uf
);
72 extern void userfaultfd_unmap_complete(struct mm_struct
*mm
,
73 struct list_head
*uf
);
75 #else /* CONFIG_USERFAULTFD */
78 static inline int handle_userfault(struct vm_fault
*vmf
, unsigned long reason
)
80 return VM_FAULT_SIGBUS
;
83 static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct
*vma
,
84 struct vm_userfaultfd_ctx vm_ctx
)
89 static inline bool userfaultfd_missing(struct vm_area_struct
*vma
)
94 static inline bool userfaultfd_armed(struct vm_area_struct
*vma
)
99 static inline int dup_userfaultfd(struct vm_area_struct
*vma
,
105 static inline void dup_userfaultfd_complete(struct list_head
*l
)
109 static inline void mremap_userfaultfd_prep(struct vm_area_struct
*vma
,
110 struct vm_userfaultfd_ctx
*ctx
)
114 static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx
*ctx
,
121 static inline bool userfaultfd_remove(struct vm_area_struct
*vma
,
128 static inline int userfaultfd_unmap_prep(struct vm_area_struct
*vma
,
129 unsigned long start
, unsigned long end
,
130 struct list_head
*uf
)
135 static inline void userfaultfd_unmap_complete(struct mm_struct
*mm
,
136 struct list_head
*uf
)
140 #endif /* CONFIG_USERFAULTFD */
142 #endif /* _LINUX_USERFAULTFD_K_H */