userfaultfd: wp: add WP pagetable tracking to x86
[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
1df319e0
SL
55static inline bool userfaultfd_wp(struct vm_area_struct *vma)
56{
57 return vma->vm_flags & VM_UFFD_WP;
58}
59
932b18e0
AA
60static inline bool userfaultfd_armed(struct vm_area_struct *vma)
61{
62 return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
63}
64
893e26e6
PE
65extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
66extern void dup_userfaultfd_complete(struct list_head *);
67
72f87654
PE
68extern void mremap_userfaultfd_prep(struct vm_area_struct *,
69 struct vm_userfaultfd_ctx *);
90794bf1 70extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *,
72f87654
PE
71 unsigned long from, unsigned long to,
72 unsigned long len);
73
70ccb92f 74extern bool userfaultfd_remove(struct vm_area_struct *vma,
d811914d
MR
75 unsigned long start,
76 unsigned long end);
05ce7724 77
897ab3e0
MR
78extern int userfaultfd_unmap_prep(struct vm_area_struct *vma,
79 unsigned long start, unsigned long end,
80 struct list_head *uf);
81extern void userfaultfd_unmap_complete(struct mm_struct *mm,
82 struct list_head *uf);
83
932b18e0
AA
84#else /* CONFIG_USERFAULTFD */
85
86/* mm helpers */
2b740303
SJ
87static inline vm_fault_t handle_userfault(struct vm_fault *vmf,
88 unsigned long reason)
932b18e0
AA
89{
90 return VM_FAULT_SIGBUS;
91}
92
93static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
94 struct vm_userfaultfd_ctx vm_ctx)
95{
96 return true;
97}
98
99static inline bool userfaultfd_missing(struct vm_area_struct *vma)
100{
101 return false;
102}
103
1df319e0
SL
104static inline bool userfaultfd_wp(struct vm_area_struct *vma)
105{
106 return false;
107}
108
932b18e0
AA
109static inline bool userfaultfd_armed(struct vm_area_struct *vma)
110{
111 return false;
112}
113
893e26e6
PE
114static inline int dup_userfaultfd(struct vm_area_struct *vma,
115 struct list_head *l)
116{
117 return 0;
118}
119
120static inline void dup_userfaultfd_complete(struct list_head *l)
121{
122}
123
72f87654
PE
124static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma,
125 struct vm_userfaultfd_ctx *ctx)
126{
127}
128
90794bf1 129static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
72f87654
PE
130 unsigned long from,
131 unsigned long to,
132 unsigned long len)
133{
134}
05ce7724 135
70ccb92f 136static inline bool userfaultfd_remove(struct vm_area_struct *vma,
d811914d
MR
137 unsigned long start,
138 unsigned long end)
05ce7724 139{
70ccb92f 140 return true;
05ce7724 141}
897ab3e0
MR
142
143static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma,
144 unsigned long start, unsigned long end,
145 struct list_head *uf)
146{
147 return 0;
148}
149
150static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
151 struct list_head *uf)
152{
153}
ca49ca71 154
932b18e0
AA
155#endif /* CONFIG_USERFAULTFD */
156
157#endif /* _LINUX_USERFAULTFD_K_H */