Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 1 | /* |
| 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 Kara | 82b0f8c | 2016-12-14 15:06:58 -0800 | [diff] [blame] | 30 | extern int handle_userfault(struct vm_fault *vmf, unsigned long reason); |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 31 | |
Andrea Arcangeli | c1a4de9 | 2015-09-04 15:47:04 -0700 | [diff] [blame] | 32 | extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start, |
| 33 | unsigned long src_start, unsigned long len); |
| 34 | extern ssize_t mfill_zeropage(struct mm_struct *dst_mm, |
| 35 | unsigned long dst_start, |
| 36 | unsigned long len); |
| 37 | |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 38 | /* mm helpers */ |
| 39 | static 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 | |
| 45 | static inline bool userfaultfd_missing(struct vm_area_struct *vma) |
| 46 | { |
| 47 | return vma->vm_flags & VM_UFFD_MISSING; |
| 48 | } |
| 49 | |
| 50 | static inline bool userfaultfd_armed(struct vm_area_struct *vma) |
| 51 | { |
| 52 | return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP); |
| 53 | } |
| 54 | |
Pavel Emelyanov | 893e26e | 2017-02-22 15:42:27 -0800 | [diff] [blame] | 55 | extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *); |
| 56 | extern void dup_userfaultfd_complete(struct list_head *); |
| 57 | |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 58 | extern void mremap_userfaultfd_prep(struct vm_area_struct *, |
| 59 | struct vm_userfaultfd_ctx *); |
Andrea Arcangeli | 90794bf | 2017-02-22 15:42:37 -0800 | [diff] [blame] | 60 | extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *, |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 61 | unsigned long from, unsigned long to, |
| 62 | unsigned long len); |
| 63 | |
Andrea Arcangeli | 70ccb92 | 2017-03-09 16:17:11 -0800 | [diff] [blame] | 64 | extern bool userfaultfd_remove(struct vm_area_struct *vma, |
Mike Rapoport | d811914 | 2017-02-24 14:56:02 -0800 | [diff] [blame] | 65 | unsigned long start, |
| 66 | unsigned long end); |
Pavel Emelyanov | 05ce772 | 2017-02-22 15:42:40 -0800 | [diff] [blame] | 67 | |
Mike Rapoport | 897ab3e | 2017-02-24 14:58:22 -0800 | [diff] [blame] | 68 | extern int userfaultfd_unmap_prep(struct vm_area_struct *vma, |
| 69 | unsigned long start, unsigned long end, |
| 70 | struct list_head *uf); |
| 71 | extern void userfaultfd_unmap_complete(struct mm_struct *mm, |
| 72 | struct list_head *uf); |
| 73 | |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 74 | #else /* CONFIG_USERFAULTFD */ |
| 75 | |
| 76 | /* mm helpers */ |
Jan Kara | 82b0f8c | 2016-12-14 15:06:58 -0800 | [diff] [blame] | 77 | static inline int handle_userfault(struct vm_fault *vmf, unsigned long reason) |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 78 | { |
| 79 | return VM_FAULT_SIGBUS; |
| 80 | } |
| 81 | |
| 82 | static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma, |
| 83 | struct vm_userfaultfd_ctx vm_ctx) |
| 84 | { |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | static inline bool userfaultfd_missing(struct vm_area_struct *vma) |
| 89 | { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | static inline bool userfaultfd_armed(struct vm_area_struct *vma) |
| 94 | { |
| 95 | return false; |
| 96 | } |
| 97 | |
Pavel Emelyanov | 893e26e | 2017-02-22 15:42:27 -0800 | [diff] [blame] | 98 | static inline int dup_userfaultfd(struct vm_area_struct *vma, |
| 99 | struct list_head *l) |
| 100 | { |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static inline void dup_userfaultfd_complete(struct list_head *l) |
| 105 | { |
| 106 | } |
| 107 | |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 108 | static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma, |
| 109 | struct vm_userfaultfd_ctx *ctx) |
| 110 | { |
| 111 | } |
| 112 | |
Andrea Arcangeli | 90794bf | 2017-02-22 15:42:37 -0800 | [diff] [blame] | 113 | static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx, |
Pavel Emelyanov | 72f8765 | 2017-02-22 15:42:34 -0800 | [diff] [blame] | 114 | unsigned long from, |
| 115 | unsigned long to, |
| 116 | unsigned long len) |
| 117 | { |
| 118 | } |
Pavel Emelyanov | 05ce772 | 2017-02-22 15:42:40 -0800 | [diff] [blame] | 119 | |
Andrea Arcangeli | 70ccb92 | 2017-03-09 16:17:11 -0800 | [diff] [blame] | 120 | static inline bool userfaultfd_remove(struct vm_area_struct *vma, |
Mike Rapoport | d811914 | 2017-02-24 14:56:02 -0800 | [diff] [blame] | 121 | unsigned long start, |
| 122 | unsigned long end) |
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 | return true; |
Pavel Emelyanov | 05ce772 | 2017-02-22 15:42:40 -0800 | [diff] [blame] | 125 | } |
Mike Rapoport | 897ab3e | 2017-02-24 14:58:22 -0800 | [diff] [blame] | 126 | |
| 127 | static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma, |
| 128 | unsigned long start, unsigned long end, |
| 129 | struct list_head *uf) |
| 130 | { |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static inline void userfaultfd_unmap_complete(struct mm_struct *mm, |
| 135 | struct list_head *uf) |
| 136 | { |
| 137 | } |
Mike Rapoport | ca49ca7 | 2017-02-24 14:58:25 -0800 | [diff] [blame] | 138 | |
Andrea Arcangeli | 932b18e | 2015-09-04 15:46:10 -0700 | [diff] [blame] | 139 | #endif /* CONFIG_USERFAULTFD */ |
| 140 | |
| 141 | #endif /* _LINUX_USERFAULTFD_K_H */ |