blob: 0468548acebfef5431ea7bfd6f565cfdfb73f348 [file] [log] [blame]
Andrea Arcangeli932b18e2015-09-04 15:46:10 -07001/*
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
Jan Kara82b0f8c2016-12-14 15:06:58 -080030extern int handle_userfault(struct vm_fault *vmf, unsigned long reason);
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070031
Andrea Arcangelic1a4de92015-09-04 15:47:04 -070032extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start,
33 unsigned long src_start, unsigned long len);
34extern ssize_t mfill_zeropage(struct mm_struct *dst_mm,
35 unsigned long dst_start,
36 unsigned long len);
37
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070038/* mm helpers */
39static 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
45static inline bool userfaultfd_missing(struct vm_area_struct *vma)
46{
47 return vma->vm_flags & VM_UFFD_MISSING;
48}
49
50static inline bool userfaultfd_armed(struct vm_area_struct *vma)
51{
52 return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
53}
54
Pavel Emelyanov893e26e2017-02-22 15:42:27 -080055extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
56extern void dup_userfaultfd_complete(struct list_head *);
57
Pavel Emelyanov72f87652017-02-22 15:42:34 -080058extern void mremap_userfaultfd_prep(struct vm_area_struct *,
59 struct vm_userfaultfd_ctx *);
Andrea Arcangeli90794bf2017-02-22 15:42:37 -080060extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *,
Pavel Emelyanov72f87652017-02-22 15:42:34 -080061 unsigned long from, unsigned long to,
62 unsigned long len);
63
Mike Rapoportd8119142017-02-24 14:56:02 -080064extern void userfaultfd_remove(struct vm_area_struct *vma,
65 struct vm_area_struct **prev,
66 unsigned long start,
67 unsigned long end);
Pavel Emelyanov05ce7722017-02-22 15:42:40 -080068
Mike Rapoport897ab3e2017-02-24 14:58:22 -080069extern int userfaultfd_unmap_prep(struct vm_area_struct *vma,
70 unsigned long start, unsigned long end,
71 struct list_head *uf);
72extern void userfaultfd_unmap_complete(struct mm_struct *mm,
73 struct list_head *uf);
74
Mike Rapoportca49ca72017-02-24 14:58:25 -080075extern void userfaultfd_exit(struct mm_struct *mm);
76
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070077#else /* CONFIG_USERFAULTFD */
78
79/* mm helpers */
Jan Kara82b0f8c2016-12-14 15:06:58 -080080static inline int handle_userfault(struct vm_fault *vmf, unsigned long reason)
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070081{
82 return VM_FAULT_SIGBUS;
83}
84
85static 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
91static inline bool userfaultfd_missing(struct vm_area_struct *vma)
92{
93 return false;
94}
95
96static inline bool userfaultfd_armed(struct vm_area_struct *vma)
97{
98 return false;
99}
100
Pavel Emelyanov893e26e2017-02-22 15:42:27 -0800101static inline int dup_userfaultfd(struct vm_area_struct *vma,
102 struct list_head *l)
103{
104 return 0;
105}
106
107static inline void dup_userfaultfd_complete(struct list_head *l)
108{
109}
110
Pavel Emelyanov72f87652017-02-22 15:42:34 -0800111static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma,
112 struct vm_userfaultfd_ctx *ctx)
113{
114}
115
Andrea Arcangeli90794bf2017-02-22 15:42:37 -0800116static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
Pavel Emelyanov72f87652017-02-22 15:42:34 -0800117 unsigned long from,
118 unsigned long to,
119 unsigned long len)
120{
121}
Pavel Emelyanov05ce7722017-02-22 15:42:40 -0800122
Mike Rapoportd8119142017-02-24 14:56:02 -0800123static inline void userfaultfd_remove(struct vm_area_struct *vma,
124 struct vm_area_struct **prev,
125 unsigned long start,
126 unsigned long end)
Pavel Emelyanov05ce7722017-02-22 15:42:40 -0800127{
128}
Mike Rapoport897ab3e2017-02-24 14:58:22 -0800129
130static 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
137static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
138 struct list_head *uf)
139{
140}
Mike Rapoportca49ca72017-02-24 14:58:25 -0800141
142static inline void userfaultfd_exit(struct mm_struct *mm)
143{
144}
145
Andrea Arcangeli932b18e2015-09-04 15:46:10 -0700146#endif /* CONFIG_USERFAULTFD */
147
148#endif /* _LINUX_USERFAULTFD_K_H */