blob: f2f3b68ba910877a9fe7697f29a6f73f9e8e8221 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andrea Arcangeli932b18e2015-09-04 15:46:10 -07002/*
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
Jan Kara82b0f8c2016-12-14 15:06:58 -080031extern int handle_userfault(struct vm_fault *vmf, unsigned long reason);
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070032
Andrea Arcangelic1a4de92015-09-04 15:47:04 -070033extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start,
34 unsigned long src_start, unsigned long len);
35extern ssize_t mfill_zeropage(struct mm_struct *dst_mm,
36 unsigned long dst_start,
37 unsigned long len);
38
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070039/* mm helpers */
40static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
41 struct vm_userfaultfd_ctx vm_ctx)
42{
43 return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx;
44}
45
46static inline bool userfaultfd_missing(struct vm_area_struct *vma)
47{
48 return vma->vm_flags & VM_UFFD_MISSING;
49}
50
51static inline bool userfaultfd_armed(struct vm_area_struct *vma)
52{
53 return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
54}
55
Pavel Emelyanov893e26e2017-02-22 15:42:27 -080056extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
57extern void dup_userfaultfd_complete(struct list_head *);
58
Pavel Emelyanov72f87652017-02-22 15:42:34 -080059extern void mremap_userfaultfd_prep(struct vm_area_struct *,
60 struct vm_userfaultfd_ctx *);
Andrea Arcangeli90794bf2017-02-22 15:42:37 -080061extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *,
Pavel Emelyanov72f87652017-02-22 15:42:34 -080062 unsigned long from, unsigned long to,
63 unsigned long len);
64
Andrea Arcangeli70ccb922017-03-09 16:17:11 -080065extern bool userfaultfd_remove(struct vm_area_struct *vma,
Mike Rapoportd8119142017-02-24 14:56:02 -080066 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
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070075#else /* CONFIG_USERFAULTFD */
76
77/* mm helpers */
Jan Kara82b0f8c2016-12-14 15:06:58 -080078static inline int handle_userfault(struct vm_fault *vmf, unsigned long reason)
Andrea Arcangeli932b18e2015-09-04 15:46:10 -070079{
80 return VM_FAULT_SIGBUS;
81}
82
83static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
84 struct vm_userfaultfd_ctx vm_ctx)
85{
86 return true;
87}
88
89static inline bool userfaultfd_missing(struct vm_area_struct *vma)
90{
91 return false;
92}
93
94static inline bool userfaultfd_armed(struct vm_area_struct *vma)
95{
96 return false;
97}
98
Pavel Emelyanov893e26e2017-02-22 15:42:27 -080099static inline int dup_userfaultfd(struct vm_area_struct *vma,
100 struct list_head *l)
101{
102 return 0;
103}
104
105static inline void dup_userfaultfd_complete(struct list_head *l)
106{
107}
108
Pavel Emelyanov72f87652017-02-22 15:42:34 -0800109static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma,
110 struct vm_userfaultfd_ctx *ctx)
111{
112}
113
Andrea Arcangeli90794bf2017-02-22 15:42:37 -0800114static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
Pavel Emelyanov72f87652017-02-22 15:42:34 -0800115 unsigned long from,
116 unsigned long to,
117 unsigned long len)
118{
119}
Pavel Emelyanov05ce7722017-02-22 15:42:40 -0800120
Andrea Arcangeli70ccb922017-03-09 16:17:11 -0800121static inline bool userfaultfd_remove(struct vm_area_struct *vma,
Mike Rapoportd8119142017-02-24 14:56:02 -0800122 unsigned long start,
123 unsigned long end)
Pavel Emelyanov05ce7722017-02-22 15:42:40 -0800124{
Andrea Arcangeli70ccb922017-03-09 16:17:11 -0800125 return true;
Pavel Emelyanov05ce7722017-02-22 15:42:40 -0800126}
Mike Rapoport897ab3e2017-02-24 14:58:22 -0800127
128static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma,
129 unsigned long start, unsigned long end,
130 struct list_head *uf)
131{
132 return 0;
133}
134
135static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
136 struct list_head *uf)
137{
138}
Mike Rapoportca49ca72017-02-24 14:58:25 -0800139
Andrea Arcangeli932b18e2015-09-04 15:46:10 -0700140#endif /* CONFIG_USERFAULTFD */
141
142#endif /* _LINUX_USERFAULTFD_K_H */