Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / include / linux / userfaultfd_k.h
CommitLineData
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
cefdca0a
PX
31extern int sysctl_unprivileged_userfaultfd;
32
2b740303 33extern vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason);
932b18e0 34
c1a4de99 35extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start,
df2cc96e
MR
36 unsigned long src_start, unsigned long len,
37 bool *mmap_changing);
c1a4de99
AA
38extern ssize_t mfill_zeropage(struct mm_struct *dst_mm,
39 unsigned long dst_start,
df2cc96e
MR
40 unsigned long len,
41 bool *mmap_changing);
c1a4de99 42
932b18e0
AA
43/* mm helpers */
44static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
45 struct vm_userfaultfd_ctx vm_ctx)
46{
47 return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx;
48}
49
50static inline bool userfaultfd_missing(struct vm_area_struct *vma)
51{
52 return vma->vm_flags & VM_UFFD_MISSING;
53}
54
55static inline bool userfaultfd_armed(struct vm_area_struct *vma)
56{
57 return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
58}
59
893e26e6
PE
60extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
61extern void dup_userfaultfd_complete(struct list_head *);
62
72f87654
PE
63extern void mremap_userfaultfd_prep(struct vm_area_struct *,
64 struct vm_userfaultfd_ctx *);
90794bf1 65extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *,
72f87654
PE
66 unsigned long from, unsigned long to,
67 unsigned long len);
68
70ccb92f 69extern bool userfaultfd_remove(struct vm_area_struct *vma,
d811914d
MR
70 unsigned long start,
71 unsigned long end);
05ce7724 72
897ab3e0
MR
73extern int userfaultfd_unmap_prep(struct vm_area_struct *vma,
74 unsigned long start, unsigned long end,
75 struct list_head *uf);
76extern void userfaultfd_unmap_complete(struct mm_struct *mm,
77 struct list_head *uf);
78
932b18e0
AA
79#else /* CONFIG_USERFAULTFD */
80
81/* mm helpers */
2b740303
SJ
82static inline vm_fault_t handle_userfault(struct vm_fault *vmf,
83 unsigned long reason)
932b18e0
AA
84{
85 return VM_FAULT_SIGBUS;
86}
87
88static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
89 struct vm_userfaultfd_ctx vm_ctx)
90{
91 return true;
92}
93
94static inline bool userfaultfd_missing(struct vm_area_struct *vma)
95{
96 return false;
97}
98
99static inline bool userfaultfd_armed(struct vm_area_struct *vma)
100{
101 return false;
102}
103
893e26e6
PE
104static inline int dup_userfaultfd(struct vm_area_struct *vma,
105 struct list_head *l)
106{
107 return 0;
108}
109
110static inline void dup_userfaultfd_complete(struct list_head *l)
111{
112}
113
72f87654
PE
114static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma,
115 struct vm_userfaultfd_ctx *ctx)
116{
117}
118
90794bf1 119static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
72f87654
PE
120 unsigned long from,
121 unsigned long to,
122 unsigned long len)
123{
124}
05ce7724 125
70ccb92f 126static inline bool userfaultfd_remove(struct vm_area_struct *vma,
d811914d
MR
127 unsigned long start,
128 unsigned long end)
05ce7724 129{
70ccb92f 130 return true;
05ce7724 131}
897ab3e0
MR
132
133static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma,
134 unsigned long start, unsigned long end,
135 struct list_head *uf)
136{
137 return 0;
138}
139
140static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
141 struct list_head *uf)
142{
143}
ca49ca71 144
932b18e0
AA
145#endif /* CONFIG_USERFAULTFD */
146
147#endif /* _LINUX_USERFAULTFD_K_H */