Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 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 | |
Souptick Joarder | 2b74030 | 2018-08-23 17:01:36 -0700 | [diff] [blame] | 31 | extern vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason); |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 32 | |
Andrea Arcangeli | c1a4de9 | 2015-09-04 15:47:04 -0700 | [diff] [blame] | 33 | extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start, |
Mike Rapoport | df2cc96 | 2018-06-07 17:09:25 -0700 | [diff] [blame] | 34 | unsigned long src_start, unsigned long len, |
| 35 | bool *mmap_changing); |
Andrea Arcangeli | c1a4de9 | 2015-09-04 15:47:04 -0700 | [diff] [blame] | 36 | extern ssize_t mfill_zeropage(struct mm_struct *dst_mm, |
| 37 | unsigned long dst_start, |
Mike Rapoport | df2cc96 | 2018-06-07 17:09:25 -0700 | [diff] [blame] | 38 | unsigned long len, |
| 39 | bool *mmap_changing); |
Andrea Arcangeli | c1a4de9 | 2015-09-04 15:47:04 -0700 | [diff] [blame] | 40 | |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 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 | |
Pavel Emelyanov | 893e26e | 2017-02-22 15:42:27 -0800 | [diff] [blame] | 58 | extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *); |
| 59 | extern void dup_userfaultfd_complete(struct list_head *); |
| 60 | |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 61 | extern void mremap_userfaultfd_prep(struct vm_area_struct *, |
| 62 | struct vm_userfaultfd_ctx *); |
Andrea Arcangeli | 90794bf | 2017-02-22 15:42:37 -0800 | [diff] [blame] | 63 | extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *, |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 64 | unsigned long from, unsigned long to, |
| 65 | unsigned long len); |
| 66 | |
Andrea Arcangeli | 70ccb92 | 2017-03-09 16:17:11 -0800 | [diff] [blame] | 67 | extern bool userfaultfd_remove(struct vm_area_struct *vma, |
Mike Rapoport | d811914 | 2017-02-24 14:56:02 -0800 | [diff] [blame] | 68 | unsigned long start, |
| 69 | unsigned long end); |
Pavel Emelyanov | 05ce772 | 2017-02-22 15:42:40 -0800 | [diff] [blame] | 70 | |
Mike Rapoport | 897ab3e | 2017-02-24 14:58:22 -0800 | [diff] [blame] | 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 | |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 77 | #else /* CONFIG_USERFAULTFD */ |
| 78 | |
| 79 | /* mm helpers */ |
Souptick Joarder | 2b74030 | 2018-08-23 17:01:36 -0700 | [diff] [blame] | 80 | static inline vm_fault_t handle_userfault(struct vm_fault *vmf, |
| 81 | unsigned long reason) |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 82 | { |
| 83 | return VM_FAULT_SIGBUS; |
| 84 | } |
| 85 | |
| 86 | static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma, |
| 87 | struct vm_userfaultfd_ctx vm_ctx) |
| 88 | { |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | static inline bool userfaultfd_missing(struct vm_area_struct *vma) |
| 93 | { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | static inline bool userfaultfd_armed(struct vm_area_struct *vma) |
| 98 | { |
| 99 | return false; |
| 100 | } |
| 101 | |
Pavel Emelyanov | 893e26e | 2017-02-22 15:42:27 -0800 | [diff] [blame] | 102 | static inline int dup_userfaultfd(struct vm_area_struct *vma, |
| 103 | struct list_head *l) |
| 104 | { |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static inline void dup_userfaultfd_complete(struct list_head *l) |
| 109 | { |
| 110 | } |
| 111 | |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 112 | static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma, |
| 113 | struct vm_userfaultfd_ctx *ctx) |
| 114 | { |
| 115 | } |
| 116 | |
Andrea Arcangeli | 90794bf | 2017-02-22 15:42:37 -0800 | [diff] [blame] | 117 | static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx, |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 118 | unsigned long from, |
| 119 | unsigned long to, |
| 120 | unsigned long len) |
| 121 | { |
| 122 | } |
Pavel Emelyanov | 05ce772 | 2017-02-22 15:42:40 -0800 | [diff] [blame] | 123 | |
Andrea Arcangeli | 70ccb92 | 2017-03-09 16:17:11 -0800 | [diff] [blame] | 124 | static inline bool userfaultfd_remove(struct vm_area_struct *vma, |
Mike Rapoport | d811914 | 2017-02-24 14:56:02 -0800 | [diff] [blame] | 125 | unsigned long start, |
| 126 | unsigned long end) |
Pavel Emelyanov | 05ce772 | 2017-02-22 15:42:40 -0800 | [diff] [blame] | 127 | { |
Andrea Arcangeli | 70ccb92 | 2017-03-09 16:17:11 -0800 | [diff] [blame] | 128 | return true; |
Pavel Emelyanov | 05ce772 | 2017-02-22 15:42:40 -0800 | [diff] [blame] | 129 | } |
Mike Rapoport | 897ab3e | 2017-02-24 14:58:22 -0800 | [diff] [blame] | 130 | |
| 131 | static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma, |
| 132 | unsigned long start, unsigned long end, |
| 133 | struct list_head *uf) |
| 134 | { |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static inline void userfaultfd_unmap_complete(struct mm_struct *mm, |
| 139 | struct list_head *uf) |
| 140 | { |
| 141 | } |
Mike Rapoport | ca49ca7 | 2017-02-24 14:58:25 -0800 | [diff] [blame] | 142 | |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 143 | #endif /* CONFIG_USERFAULTFD */ |
| 144 | |
| 145 | #endif /* _LINUX_USERFAULTFD_K_H */ |