Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 2 | #ifndef _ASM_GENERIC_HUGETLB_H |
| 3 | #define _ASM_GENERIC_HUGETLB_H |
| 4 | |
Peter Xu | 679d103 | 2022-05-12 20:22:52 -0700 | [diff] [blame] | 5 | #include <linux/swap.h> |
| 6 | #include <linux/swapops.h> |
| 7 | |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 8 | static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot) |
| 9 | { |
| 10 | return mk_pte(page, pgprot); |
| 11 | } |
| 12 | |
David Miller | 2679494 | 2013-10-02 14:25:09 -0400 | [diff] [blame] | 13 | static inline unsigned long huge_pte_write(pte_t pte) |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 14 | { |
| 15 | return pte_write(pte); |
| 16 | } |
| 17 | |
David Miller | 2679494 | 2013-10-02 14:25:09 -0400 | [diff] [blame] | 18 | static inline unsigned long huge_pte_dirty(pte_t pte) |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 19 | { |
| 20 | return pte_dirty(pte); |
| 21 | } |
| 22 | |
| 23 | static inline pte_t huge_pte_mkwrite(pte_t pte) |
| 24 | { |
Rick Edgecombe | 2f0584f | 2023-06-12 17:10:27 -0700 | [diff] [blame] | 25 | return pte_mkwrite_novma(pte); |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Peter Xu | f1eb1ba | 2022-12-14 15:15:33 -0500 | [diff] [blame] | 28 | #ifndef __HAVE_ARCH_HUGE_PTE_WRPROTECT |
| 29 | static inline pte_t huge_pte_wrprotect(pte_t pte) |
| 30 | { |
| 31 | return pte_wrprotect(pte); |
| 32 | } |
| 33 | #endif |
| 34 | |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 35 | static inline pte_t huge_pte_mkdirty(pte_t pte) |
| 36 | { |
| 37 | return pte_mkdirty(pte); |
| 38 | } |
| 39 | |
| 40 | static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot) |
| 41 | { |
| 42 | return pte_modify(pte, newprot); |
| 43 | } |
| 44 | |
Peter Xu | 229f3fa | 2022-05-12 20:22:54 -0700 | [diff] [blame] | 45 | static inline pte_t huge_pte_mkuffd_wp(pte_t pte) |
| 46 | { |
Peter Xu | f1eb1ba | 2022-12-14 15:15:33 -0500 | [diff] [blame] | 47 | return huge_pte_wrprotect(pte_mkuffd_wp(pte)); |
Peter Xu | 229f3fa | 2022-05-12 20:22:54 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) |
| 51 | { |
| 52 | return pte_clear_uffd_wp(pte); |
| 53 | } |
| 54 | |
| 55 | static inline int huge_pte_uffd_wp(pte_t pte) |
| 56 | { |
| 57 | return pte_uffd_wp(pte); |
| 58 | } |
| 59 | |
Alexandre Ghiti | d018498 | 2018-10-26 15:07:59 -0700 | [diff] [blame] | 60 | #ifndef __HAVE_ARCH_HUGE_PTE_CLEAR |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 61 | static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, |
Punit Agrawal | 9386fac | 2017-07-06 15:39:46 -0700 | [diff] [blame] | 62 | pte_t *ptep, unsigned long sz) |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 63 | { |
| 64 | pte_clear(mm, addr, ptep); |
| 65 | } |
Punit Agrawal | 9386fac | 2017-07-06 15:39:46 -0700 | [diff] [blame] | 66 | #endif |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 67 | |
Alexandre Ghiti | 1e5f50f | 2018-10-26 15:08:03 -0700 | [diff] [blame] | 68 | #ifndef __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE |
| 69 | static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb, |
| 70 | unsigned long addr, unsigned long end, |
| 71 | unsigned long floor, unsigned long ceiling) |
| 72 | { |
| 73 | free_pgd_range(tlb, addr, end, floor, ceiling); |
| 74 | } |
Alexandre Ghiti | cea685d | 2018-10-26 15:08:07 -0700 | [diff] [blame] | 75 | #endif |
Alexandre Ghiti | 1e5f50f | 2018-10-26 15:08:03 -0700 | [diff] [blame] | 76 | |
Alexandre Ghiti | cea685d | 2018-10-26 15:08:07 -0700 | [diff] [blame] | 77 | #ifndef __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT |
| 78 | static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, |
Ryan Roberts | 935d4f0 | 2023-09-22 12:58:03 +0100 | [diff] [blame] | 79 | pte_t *ptep, pte_t pte, unsigned long sz) |
Alexandre Ghiti | cea685d | 2018-10-26 15:08:07 -0700 | [diff] [blame] | 80 | { |
| 81 | set_pte_at(mm, addr, ptep, pte); |
| 82 | } |
Alexandre Ghiti | 1e5f50f | 2018-10-26 15:08:03 -0700 | [diff] [blame] | 83 | #endif |
| 84 | |
Alexandre Ghiti | a4d8385 | 2018-10-26 15:08:12 -0700 | [diff] [blame] | 85 | #ifndef __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR |
| 86 | static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, |
| 87 | unsigned long addr, pte_t *ptep) |
| 88 | { |
| 89 | return ptep_get_and_clear(mm, addr, ptep); |
| 90 | } |
| 91 | #endif |
| 92 | |
Alexandre Ghiti | fe63222 | 2018-10-26 15:08:17 -0700 | [diff] [blame] | 93 | #ifndef __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH |
Baolin Wang | ae07562 | 2022-05-13 16:48:55 -0700 | [diff] [blame] | 94 | static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, |
Alexandre Ghiti | fe63222 | 2018-10-26 15:08:17 -0700 | [diff] [blame] | 95 | unsigned long addr, pte_t *ptep) |
| 96 | { |
Baolin Wang | ae07562 | 2022-05-13 16:48:55 -0700 | [diff] [blame] | 97 | return ptep_clear_flush(vma, addr, ptep); |
Alexandre Ghiti | fe63222 | 2018-10-26 15:08:17 -0700 | [diff] [blame] | 98 | } |
| 99 | #endif |
| 100 | |
Alexandre Ghiti | cae72ab | 2018-10-26 15:08:22 -0700 | [diff] [blame] | 101 | #ifndef __HAVE_ARCH_HUGE_PTE_NONE |
| 102 | static inline int huge_pte_none(pte_t pte) |
| 103 | { |
| 104 | return pte_none(pte); |
| 105 | } |
| 106 | #endif |
| 107 | |
Peter Xu | 679d103 | 2022-05-12 20:22:52 -0700 | [diff] [blame] | 108 | /* Please refer to comments above pte_none_mostly() for the usage */ |
| 109 | static inline int huge_pte_none_mostly(pte_t pte) |
| 110 | { |
| 111 | return huge_pte_none(pte) || is_pte_marker(pte); |
| 112 | } |
| 113 | |
Alexandre Ghiti | 78d6e4e | 2018-10-26 15:08:31 -0700 | [diff] [blame] | 114 | #ifndef __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE |
| 115 | static inline int prepare_hugepage_range(struct file *file, |
| 116 | unsigned long addr, unsigned long len) |
| 117 | { |
| 118 | struct hstate *h = hstate_file(file); |
| 119 | |
| 120 | if (len & ~huge_page_mask(h)) |
| 121 | return -EINVAL; |
| 122 | if (addr & ~huge_page_mask(h)) |
| 123 | return -EINVAL; |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | #endif |
| 128 | |
Alexandre Ghiti | 8e581d4 | 2018-10-26 15:08:35 -0700 | [diff] [blame] | 129 | #ifndef __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT |
| 130 | static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, |
| 131 | unsigned long addr, pte_t *ptep) |
| 132 | { |
| 133 | ptep_set_wrprotect(mm, addr, ptep); |
| 134 | } |
| 135 | #endif |
| 136 | |
Alexandre Ghiti | facf6d5 | 2018-10-26 15:08:39 -0700 | [diff] [blame] | 137 | #ifndef __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS |
| 138 | static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, |
| 139 | unsigned long addr, pte_t *ptep, |
| 140 | pte_t pte, int dirty) |
| 141 | { |
| 142 | return ptep_set_access_flags(vma, addr, ptep, pte, dirty); |
| 143 | } |
| 144 | #endif |
| 145 | |
Alexandre Ghiti | 544db75 | 2018-10-26 15:08:43 -0700 | [diff] [blame] | 146 | #ifndef __HAVE_ARCH_HUGE_PTEP_GET |
| 147 | static inline pte_t huge_ptep_get(pte_t *ptep) |
| 148 | { |
Christophe Leroy | 481e980 | 2020-06-15 12:57:58 +0000 | [diff] [blame] | 149 | return ptep_get(ptep); |
Alexandre Ghiti | 544db75 | 2018-10-26 15:08:43 -0700 | [diff] [blame] | 150 | } |
| 151 | #endif |
| 152 | |
Alexandre Ghiti | 4eb0716 | 2019-05-13 17:19:04 -0700 | [diff] [blame] | 153 | #ifndef __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED |
| 154 | static inline bool gigantic_page_runtime_supported(void) |
| 155 | { |
| 156 | return IS_ENABLED(CONFIG_ARCH_HAS_GIGANTIC_PAGE); |
| 157 | } |
| 158 | #endif /* __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED */ |
| 159 | |
Gerald Schaefer | 106c992 | 2013-04-29 15:07:23 -0700 | [diff] [blame] | 160 | #endif /* _ASM_GENERIC_HUGETLB_H */ |