Merge tag 'vfio-v4.11-rc1' of git://github.com/awilliam/linux-vfio
[sfrench/cifs-2.6.git] / include / linux / userfaultfd_k.h
1 /*
2  *  include/linux/userfaultfd_k.h
3  *
4  *  Copyright (C) 2015  Red Hat, Inc.
5  *
6  */
7
8 #ifndef _LINUX_USERFAULTFD_K_H
9 #define _LINUX_USERFAULTFD_K_H
10
11 #ifdef CONFIG_USERFAULTFD
12
13 #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */
14
15 #include <linux/fcntl.h>
16
17 /*
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
22  * shared O_* flags.
23  */
24 #define UFFD_CLOEXEC O_CLOEXEC
25 #define UFFD_NONBLOCK O_NONBLOCK
26
27 #define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
28 #define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS)
29
30 extern int handle_userfault(struct vm_fault *vmf, unsigned long reason);
31
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,
36                               unsigned long len);
37
38 /* mm helpers */
39 static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
40                                         struct vm_userfaultfd_ctx vm_ctx)
41 {
42         return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx;
43 }
44
45 static inline bool userfaultfd_missing(struct vm_area_struct *vma)
46 {
47         return vma->vm_flags & VM_UFFD_MISSING;
48 }
49
50 static inline bool userfaultfd_armed(struct vm_area_struct *vma)
51 {
52         return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
53 }
54
55 extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
56 extern void dup_userfaultfd_complete(struct list_head *);
57
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,
62                                         unsigned long len);
63
64 extern void madvise_userfault_dontneed(struct vm_area_struct *vma,
65                                        struct vm_area_struct **prev,
66                                        unsigned long start,
67                                        unsigned long end);
68
69 #else /* CONFIG_USERFAULTFD */
70
71 /* mm helpers */
72 static inline int handle_userfault(struct vm_fault *vmf, unsigned long reason)
73 {
74         return VM_FAULT_SIGBUS;
75 }
76
77 static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
78                                         struct vm_userfaultfd_ctx vm_ctx)
79 {
80         return true;
81 }
82
83 static inline bool userfaultfd_missing(struct vm_area_struct *vma)
84 {
85         return false;
86 }
87
88 static inline bool userfaultfd_armed(struct vm_area_struct *vma)
89 {
90         return false;
91 }
92
93 static inline int dup_userfaultfd(struct vm_area_struct *vma,
94                                   struct list_head *l)
95 {
96         return 0;
97 }
98
99 static inline void dup_userfaultfd_complete(struct list_head *l)
100 {
101 }
102
103 static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma,
104                                            struct vm_userfaultfd_ctx *ctx)
105 {
106 }
107
108 static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
109                                                unsigned long from,
110                                                unsigned long to,
111                                                unsigned long len)
112 {
113 }
114
115 static inline void madvise_userfault_dontneed(struct vm_area_struct *vma,
116                                               struct vm_area_struct **prev,
117                                               unsigned long start,
118                                               unsigned long end)
119 {
120 }
121 #endif /* CONFIG_USERFAULTFD */
122
123 #endif /* _LINUX_USERFAULTFD_K_H */