Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
932b18e0 AA |
2 | /* |
3 | * include/linux/userfaultfd_k.h | |
4 | * | |
5 | * Copyright (C) 2015 Red Hat, Inc. | |
6 | * | |
7 | */ | |
8 | ||
9 | #ifndef _LINUX_USERFAULTFD_K_H | |
10 | #define _LINUX_USERFAULTFD_K_H | |
11 | ||
12 | #ifdef CONFIG_USERFAULTFD | |
13 | ||
14 | #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */ | |
15 | ||
16 | #include <linux/fcntl.h> | |
17 | ||
18 | /* | |
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 | |
23 | * shared O_* flags. | |
24 | */ | |
25 | #define UFFD_CLOEXEC O_CLOEXEC | |
26 | #define UFFD_NONBLOCK O_NONBLOCK | |
27 | ||
28 | #define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK) | |
29 | #define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS) | |
30 | ||
82b0f8c3 | 31 | extern int handle_userfault(struct vm_fault *vmf, unsigned long reason); |
932b18e0 | 32 | |
c1a4de99 | 33 | extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start, |
df2cc96e MR |
34 | unsigned long src_start, unsigned long len, |
35 | bool *mmap_changing); | |
c1a4de99 AA |
36 | extern ssize_t mfill_zeropage(struct mm_struct *dst_mm, |
37 | unsigned long dst_start, | |
df2cc96e MR |
38 | unsigned long len, |
39 | bool *mmap_changing); | |
c1a4de99 | 40 | |
932b18e0 AA |
41 | /* mm helpers */ |
42 | static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma, | |
43 | struct vm_userfaultfd_ctx vm_ctx) | |
44 | { | |
45 | return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx; | |
46 | } | |
47 | ||
48 | static inline bool userfaultfd_missing(struct vm_area_struct *vma) | |
49 | { | |
50 | return vma->vm_flags & VM_UFFD_MISSING; | |
51 | } | |
52 | ||
53 | static inline bool userfaultfd_armed(struct vm_area_struct *vma) | |
54 | { | |
55 | return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP); | |
56 | } | |
57 | ||
893e26e6 PE |
58 | extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *); |
59 | extern void dup_userfaultfd_complete(struct list_head *); | |
60 | ||
72f87654 PE |
61 | extern void mremap_userfaultfd_prep(struct vm_area_struct *, |
62 | struct vm_userfaultfd_ctx *); | |
90794bf1 | 63 | extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *, |
72f87654 PE |
64 | unsigned long from, unsigned long to, |
65 | unsigned long len); | |
66 | ||
70ccb92f | 67 | extern bool userfaultfd_remove(struct vm_area_struct *vma, |
d811914d MR |
68 | unsigned long start, |
69 | unsigned long end); | |
05ce7724 | 70 | |
897ab3e0 MR |
71 | extern int userfaultfd_unmap_prep(struct vm_area_struct *vma, |
72 | unsigned long start, unsigned long end, | |
73 | struct list_head *uf); | |
74 | extern void userfaultfd_unmap_complete(struct mm_struct *mm, | |
75 | struct list_head *uf); | |
76 | ||
932b18e0 AA |
77 | #else /* CONFIG_USERFAULTFD */ |
78 | ||
79 | /* mm helpers */ | |
82b0f8c3 | 80 | static inline int handle_userfault(struct vm_fault *vmf, unsigned long reason) |
932b18e0 AA |
81 | { |
82 | return VM_FAULT_SIGBUS; | |
83 | } | |
84 | ||
85 | static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma, | |
86 | struct vm_userfaultfd_ctx vm_ctx) | |
87 | { | |
88 | return true; | |
89 | } | |
90 | ||
91 | static inline bool userfaultfd_missing(struct vm_area_struct *vma) | |
92 | { | |
93 | return false; | |
94 | } | |
95 | ||
96 | static inline bool userfaultfd_armed(struct vm_area_struct *vma) | |
97 | { | |
98 | return false; | |
99 | } | |
100 | ||
893e26e6 PE |
101 | static inline int dup_userfaultfd(struct vm_area_struct *vma, |
102 | struct list_head *l) | |
103 | { | |
104 | return 0; | |
105 | } | |
106 | ||
107 | static inline void dup_userfaultfd_complete(struct list_head *l) | |
108 | { | |
109 | } | |
110 | ||
72f87654 PE |
111 | static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma, |
112 | struct vm_userfaultfd_ctx *ctx) | |
113 | { | |
114 | } | |
115 | ||
90794bf1 | 116 | static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx, |
72f87654 PE |
117 | unsigned long from, |
118 | unsigned long to, | |
119 | unsigned long len) | |
120 | { | |
121 | } | |
05ce7724 | 122 | |
70ccb92f | 123 | static inline bool userfaultfd_remove(struct vm_area_struct *vma, |
d811914d MR |
124 | unsigned long start, |
125 | unsigned long end) | |
05ce7724 | 126 | { |
70ccb92f | 127 | return true; |
05ce7724 | 128 | } |
897ab3e0 MR |
129 | |
130 | static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma, | |
131 | unsigned long start, unsigned long end, | |
132 | struct list_head *uf) | |
133 | { | |
134 | return 0; | |
135 | } | |
136 | ||
137 | static inline void userfaultfd_unmap_complete(struct mm_struct *mm, | |
138 | struct list_head *uf) | |
139 | { | |
140 | } | |
ca49ca71 | 141 | |
932b18e0 AA |
142 | #endif /* CONFIG_USERFAULTFD */ |
143 | ||
144 | #endif /* _LINUX_USERFAULTFD_K_H */ |