| 1 | #ifndef _ASM_GENERIC_PGTABLE_UFFD_H |
| 2 | #define _ASM_GENERIC_PGTABLE_UFFD_H |
| 3 | |
| 4 | /* |
| 5 | * Some platforms can customize the uffd-wp bit, making it unavailable |
| 6 | * even if the architecture provides the resource. |
| 7 | * Adding this API allows architectures to add their own checks for the |
| 8 | * devices on which the kernel is running. |
| 9 | * Note: When overriding it, please make sure the |
| 10 | * CONFIG_HAVE_ARCH_USERFAULTFD_WP is part of this macro. |
| 11 | */ |
| 12 | #ifndef pgtable_supports_uffd_wp |
| 13 | #define pgtable_supports_uffd_wp() IS_ENABLED(CONFIG_HAVE_ARCH_USERFAULTFD_WP) |
| 14 | #endif |
| 15 | |
| 16 | static inline bool uffd_supports_wp_marker(void) |
| 17 | { |
| 18 | return pgtable_supports_uffd_wp() && IS_ENABLED(CONFIG_PTE_MARKER_UFFD_WP); |
| 19 | } |
| 20 | |
| 21 | #ifndef CONFIG_HAVE_ARCH_USERFAULTFD_WP |
| 22 | static __always_inline int pte_uffd_wp(pte_t pte) |
| 23 | { |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | static __always_inline int pmd_uffd_wp(pmd_t pmd) |
| 28 | { |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static __always_inline pte_t pte_mkuffd_wp(pte_t pte) |
| 33 | { |
| 34 | return pte; |
| 35 | } |
| 36 | |
| 37 | static __always_inline pmd_t pmd_mkuffd_wp(pmd_t pmd) |
| 38 | { |
| 39 | return pmd; |
| 40 | } |
| 41 | |
| 42 | static __always_inline pte_t pte_clear_uffd_wp(pte_t pte) |
| 43 | { |
| 44 | return pte; |
| 45 | } |
| 46 | |
| 47 | static __always_inline pmd_t pmd_clear_uffd_wp(pmd_t pmd) |
| 48 | { |
| 49 | return pmd; |
| 50 | } |
| 51 | |
| 52 | static __always_inline pte_t pte_swp_mkuffd_wp(pte_t pte) |
| 53 | { |
| 54 | return pte; |
| 55 | } |
| 56 | |
| 57 | static __always_inline int pte_swp_uffd_wp(pte_t pte) |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static __always_inline pte_t pte_swp_clear_uffd_wp(pte_t pte) |
| 63 | { |
| 64 | return pte; |
| 65 | } |
| 66 | |
| 67 | static inline pmd_t pmd_swp_mkuffd_wp(pmd_t pmd) |
| 68 | { |
| 69 | return pmd; |
| 70 | } |
| 71 | |
| 72 | static inline int pmd_swp_uffd_wp(pmd_t pmd) |
| 73 | { |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd) |
| 78 | { |
| 79 | return pmd; |
| 80 | } |
| 81 | #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ |
| 82 | |
| 83 | #endif /* _ASM_GENERIC_PGTABLE_UFFD_H */ |
| 84 | |