blob: 587480ad41b7b10c8dc9e71d921665ffddfb2c39 [file] [log] [blame]
Andrea Arcangeli932b18e2015-09-04 15:46:10 -07001/*
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
30extern int handle_userfault(struct vm_area_struct *vma, unsigned long address,
31 unsigned int flags, unsigned long reason);
32
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
56#else /* CONFIG_USERFAULTFD */
57
58/* mm helpers */
59static inline int handle_userfault(struct vm_area_struct *vma,
60 unsigned long address,
61 unsigned int flags,
62 unsigned long reason)
63{
64 return VM_FAULT_SIGBUS;
65}
66
67static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
68 struct vm_userfaultfd_ctx vm_ctx)
69{
70 return true;
71}
72
73static inline bool userfaultfd_missing(struct vm_area_struct *vma)
74{
75 return false;
76}
77
78static inline bool userfaultfd_armed(struct vm_area_struct *vma)
79{
80 return false;
81}
82
83#endif /* CONFIG_USERFAULTFD */
84
85#endif /* _LINUX_USERFAULTFD_K_H */