userfaultfd_k.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/linux/userfaultfd_k.h
  4. *
  5. * Copyright (C) 2015 Red Hat, Inc.
  6. *
  7. */
  8. #ifndef _LINUX_USERFAULTFD_K_H
  9. #define _LINUX_USERFAULTFD_K_H
  10. #ifdef CONFIG_USERFAULTFD
  11. #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */
  12. #include <linux/fcntl.h>
  13. /*
  14. * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
  15. * new flags, since they might collide with O_* ones. We want
  16. * to re-use O_* flags that couldn't possibly have a meaning
  17. * from userfaultfd, in order to leave a free define-space for
  18. * shared O_* flags.
  19. */
  20. #define UFFD_CLOEXEC O_CLOEXEC
  21. #define UFFD_NONBLOCK O_NONBLOCK
  22. #define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
  23. #define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS)
  24. extern vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason);
  25. extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start,
  26. unsigned long src_start, unsigned long len,
  27. bool *mmap_changing);
  28. extern ssize_t mfill_zeropage(struct mm_struct *dst_mm,
  29. unsigned long dst_start,
  30. unsigned long len,
  31. bool *mmap_changing);
  32. /* mm helpers */
  33. static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
  34. struct vm_userfaultfd_ctx vm_ctx)
  35. {
  36. return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx;
  37. }
  38. static inline bool userfaultfd_missing(struct vm_area_struct *vma)
  39. {
  40. return vma->vm_flags & VM_UFFD_MISSING;
  41. }
  42. static inline bool userfaultfd_armed(struct vm_area_struct *vma)
  43. {
  44. return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
  45. }
  46. extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
  47. extern void dup_userfaultfd_complete(struct list_head *);
  48. extern void mremap_userfaultfd_prep(struct vm_area_struct *,
  49. struct vm_userfaultfd_ctx *);
  50. extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *,
  51. unsigned long from, unsigned long to,
  52. unsigned long len);
  53. extern bool userfaultfd_remove(struct vm_area_struct *vma,
  54. unsigned long start,
  55. unsigned long end);
  56. extern int userfaultfd_unmap_prep(struct vm_area_struct *vma,
  57. unsigned long start, unsigned long end,
  58. struct list_head *uf);
  59. extern void userfaultfd_unmap_complete(struct mm_struct *mm,
  60. struct list_head *uf);
  61. #else /* CONFIG_USERFAULTFD */
  62. /* mm helpers */
  63. static inline vm_fault_t handle_userfault(struct vm_fault *vmf,
  64. unsigned long reason)
  65. {
  66. return VM_FAULT_SIGBUS;
  67. }
  68. static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
  69. struct vm_userfaultfd_ctx vm_ctx)
  70. {
  71. return true;
  72. }
  73. static inline bool userfaultfd_missing(struct vm_area_struct *vma)
  74. {
  75. return false;
  76. }
  77. static inline bool userfaultfd_armed(struct vm_area_struct *vma)
  78. {
  79. return false;
  80. }
  81. static inline int dup_userfaultfd(struct vm_area_struct *vma,
  82. struct list_head *l)
  83. {
  84. return 0;
  85. }
  86. static inline void dup_userfaultfd_complete(struct list_head *l)
  87. {
  88. }
  89. static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma,
  90. struct vm_userfaultfd_ctx *ctx)
  91. {
  92. }
  93. static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
  94. unsigned long from,
  95. unsigned long to,
  96. unsigned long len)
  97. {
  98. }
  99. static inline bool userfaultfd_remove(struct vm_area_struct *vma,
  100. unsigned long start,
  101. unsigned long end)
  102. {
  103. return true;
  104. }
  105. static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma,
  106. unsigned long start, unsigned long end,
  107. struct list_head *uf)
  108. {
  109. return 0;
  110. }
  111. static inline void userfaultfd_unmap_complete(struct mm_struct *mm,
  112. struct list_head *uf)
  113. {
  114. }
  115. #endif /* CONFIG_USERFAULTFD */
  116. #endif /* _LINUX_USERFAULTFD_K_H */