userfaultfd_k.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * include/linux/userfaultfd_k.h
  3. *
  4. * Copyright (C) 2015 Red Hat, Inc.
  5. *
  6. */
  7. #ifndef _LINUX_USERFAULTFD_K_H
  8. #define _LINUX_USERFAULTFD_K_H
  9. #ifdef CONFIG_USERFAULTFD
  10. #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */
  11. #include <linux/fcntl.h>
  12. /*
  13. * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
  14. * new flags, since they might collide with O_* ones. We want
  15. * to re-use O_* flags that couldn't possibly have a meaning
  16. * from userfaultfd, in order to leave a free define-space for
  17. * shared O_* flags.
  18. */
  19. #define UFFD_CLOEXEC O_CLOEXEC
  20. #define UFFD_NONBLOCK O_NONBLOCK
  21. #define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
  22. #define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS)
  23. extern int handle_userfault(struct vm_area_struct *vma, unsigned long address,
  24. unsigned int flags, 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. extern ssize_t mfill_zeropage(struct mm_struct *dst_mm,
  28. unsigned long dst_start,
  29. unsigned long len);
  30. /* mm helpers */
  31. static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
  32. struct vm_userfaultfd_ctx vm_ctx)
  33. {
  34. return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx;
  35. }
  36. static inline bool userfaultfd_missing(struct vm_area_struct *vma)
  37. {
  38. return vma->vm_flags & VM_UFFD_MISSING;
  39. }
  40. static inline bool userfaultfd_armed(struct vm_area_struct *vma)
  41. {
  42. return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP);
  43. }
  44. #else /* CONFIG_USERFAULTFD */
  45. /* mm helpers */
  46. static inline int handle_userfault(struct vm_area_struct *vma,
  47. unsigned long address,
  48. unsigned int flags,
  49. unsigned long reason)
  50. {
  51. return VM_FAULT_SIGBUS;
  52. }
  53. static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
  54. struct vm_userfaultfd_ctx vm_ctx)
  55. {
  56. return true;
  57. }
  58. static inline bool userfaultfd_missing(struct vm_area_struct *vma)
  59. {
  60. return false;
  61. }
  62. static inline bool userfaultfd_armed(struct vm_area_struct *vma)
  63. {
  64. return false;
  65. }
  66. #endif /* CONFIG_USERFAULTFD */
  67. #endif /* _LINUX_USERFAULTFD_K_H */