Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ |
| 2 | #define _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ |
Aneesh Kumar K.V | 2e87351 | 2016-04-29 23:25:47 +1000 | [diff] [blame] | 3 | |
Kirill A. Shutemov | 9849a56 | 2017-03-09 17:24:05 +0300 | [diff] [blame] | 4 | #include <asm-generic/5level-fixup.h> |
| 5 | |
Aneesh Kumar K.V | c137a27 | 2017-02-24 14:59:21 -0800 | [diff] [blame] | 6 | #ifndef __ASSEMBLY__ |
| 7 | #include <linux/mmdebug.h> |
Oliver O'Halloran | ebd3119 | 2017-06-28 11:32:34 +1000 | [diff] [blame] | 8 | #include <linux/bug.h> |
Aneesh Kumar K.V | c137a27 | 2017-02-24 14:59:21 -0800 | [diff] [blame] | 9 | #endif |
Kirill A. Shutemov | 9849a56 | 2017-03-09 17:24:05 +0300 | [diff] [blame] | 10 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 11 | /* |
Aneesh Kumar K.V | 2e87351 | 2016-04-29 23:25:47 +1000 | [diff] [blame] | 12 | * Common bits between hash and Radix page table |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 13 | */ |
Aneesh Kumar K.V | 2e87351 | 2016-04-29 23:25:47 +1000 | [diff] [blame] | 14 | #define _PAGE_BIT_SWAP_TYPE 0 |
| 15 | |
Christophe Leroy | 6b8cb66 | 2016-09-19 12:58:54 +0200 | [diff] [blame] | 16 | #define _PAGE_RO 0 |
Christophe Leroy | fd893fe | 2017-04-14 07:45:16 +0200 | [diff] [blame] | 17 | #define _PAGE_SHARED 0 |
Christophe Leroy | 6b8cb66 | 2016-09-19 12:58:54 +0200 | [diff] [blame] | 18 | |
Aneesh Kumar K.V | 2e87351 | 2016-04-29 23:25:47 +1000 | [diff] [blame] | 19 | #define _PAGE_EXEC 0x00001 /* execute permission */ |
| 20 | #define _PAGE_WRITE 0x00002 /* write access allowed */ |
| 21 | #define _PAGE_READ 0x00004 /* read access allowed */ |
| 22 | #define _PAGE_RW (_PAGE_READ | _PAGE_WRITE) |
| 23 | #define _PAGE_RWX (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC) |
| 24 | #define _PAGE_PRIVILEGED 0x00008 /* kernel access only */ |
| 25 | #define _PAGE_SAO 0x00010 /* Strong access order */ |
| 26 | #define _PAGE_NON_IDEMPOTENT 0x00020 /* non idempotent memory */ |
| 27 | #define _PAGE_TOLERANT 0x00030 /* tolerant memory, cache inhibited */ |
| 28 | #define _PAGE_DIRTY 0x00080 /* C: page changed */ |
| 29 | #define _PAGE_ACCESSED 0x00100 /* R: page referenced */ |
| 30 | /* |
| 31 | * Software bits |
| 32 | */ |
Aneesh Kumar K.V | 69dfbae | 2016-04-29 23:26:33 +1000 | [diff] [blame] | 33 | #define _RPAGE_SW0 0x2000000000000000UL |
| 34 | #define _RPAGE_SW1 0x00800 |
| 35 | #define _RPAGE_SW2 0x00400 |
| 36 | #define _RPAGE_SW3 0x00200 |
Aneesh Kumar K.V | 049d567 | 2016-11-28 11:47:00 +0530 | [diff] [blame] | 37 | #define _RPAGE_RSV1 0x1000000000000000UL |
| 38 | #define _RPAGE_RSV2 0x0800000000000000UL |
| 39 | #define _RPAGE_RSV3 0x0400000000000000UL |
| 40 | #define _RPAGE_RSV4 0x0200000000000000UL |
Aneesh Kumar K.V | 6aa59f5 | 2017-03-28 15:21:12 +1100 | [diff] [blame] | 41 | |
| 42 | #define _PAGE_PTE 0x4000000000000000UL /* distinguishes PTEs from pointers */ |
| 43 | #define _PAGE_PRESENT 0x8000000000000000UL /* pte contains a translation */ |
| 44 | |
| 45 | /* |
| 46 | * Top and bottom bits of RPN which can be used by hash |
| 47 | * translation mode, because we expect them to be zero |
| 48 | * otherwise. |
| 49 | */ |
Aneesh Kumar K.V | 32789d3 | 2017-03-21 22:59:58 +0530 | [diff] [blame] | 50 | #define _RPAGE_RPN0 0x01000 |
| 51 | #define _RPAGE_RPN1 0x02000 |
Aneesh Kumar K.V | 6aa59f5 | 2017-03-28 15:21:12 +1100 | [diff] [blame] | 52 | #define _RPAGE_RPN44 0x0100000000000000UL |
| 53 | #define _RPAGE_RPN43 0x0080000000000000UL |
| 54 | #define _RPAGE_RPN42 0x0040000000000000UL |
| 55 | #define _RPAGE_RPN41 0x0020000000000000UL |
Aneesh Kumar K.V | 049d567 | 2016-11-28 11:47:00 +0530 | [diff] [blame] | 56 | |
Aneesh Kumar K.V | 2f18d53 | 2017-03-21 22:59:59 +0530 | [diff] [blame] | 57 | /* Max physical address bit as per radix table */ |
| 58 | #define _RPAGE_PA_MAX 57 |
| 59 | |
| 60 | /* |
| 61 | * Max physical address bit we will use for now. |
| 62 | * |
| 63 | * This is mostly a hardware limitation and for now Power9 has |
| 64 | * a 51 bit limit. |
| 65 | * |
| 66 | * This is different from the number of physical bit required to address |
| 67 | * the last byte of memory. That is defined by MAX_PHYSMEM_BITS. |
| 68 | * MAX_PHYSMEM_BITS is a linux limitation imposed by the maximum |
| 69 | * number of sections we can support (SECTIONS_SHIFT). |
| 70 | * |
| 71 | * This is different from Radix page table limitation above and |
| 72 | * should always be less than that. The limit is done such that |
| 73 | * we can overload the bits between _RPAGE_PA_MAX and _PAGE_PA_MAX |
| 74 | * for hash linux page table specific bits. |
| 75 | * |
| 76 | * In order to be compatible with future hardware generations we keep |
| 77 | * some offsets and limit this for now to 53 |
| 78 | */ |
| 79 | #define _PAGE_PA_MAX 53 |
| 80 | |
Aneesh Kumar K.V | 69dfbae | 2016-04-29 23:26:33 +1000 | [diff] [blame] | 81 | #define _PAGE_SOFT_DIRTY _RPAGE_SW3 /* software: software dirty tracking */ |
Aneesh Kumar K.V | 69dfbae | 2016-04-29 23:26:33 +1000 | [diff] [blame] | 82 | #define _PAGE_SPECIAL _RPAGE_SW2 /* software: special page */ |
Oliver O'Halloran | ebd3119 | 2017-06-28 11:32:34 +1000 | [diff] [blame] | 83 | #define _PAGE_DEVMAP _RPAGE_SW1 /* software: ZONE_DEVICE page */ |
| 84 | #define __HAVE_ARCH_PTE_DEVMAP |
| 85 | |
Aneesh Kumar K.V | 2e87351 | 2016-04-29 23:25:47 +1000 | [diff] [blame] | 86 | /* |
| 87 | * Drivers request for cache inhibited pte mapping using _PAGE_NO_CACHE |
| 88 | * Instead of fixing all of them, add an alternate define which |
| 89 | * maps CI pte mapping. |
| 90 | */ |
| 91 | #define _PAGE_NO_CACHE _PAGE_TOLERANT |
| 92 | /* |
Aneesh Kumar K.V | 2f18d53 | 2017-03-21 22:59:59 +0530 | [diff] [blame] | 93 | * We support _RPAGE_PA_MAX bit real address in pte. On the linux side |
| 94 | * we are limited by _PAGE_PA_MAX. Clear everything above _PAGE_PA_MAX |
| 95 | * and every thing below PAGE_SHIFT; |
Aneesh Kumar K.V | 2e87351 | 2016-04-29 23:25:47 +1000 | [diff] [blame] | 96 | */ |
Aneesh Kumar K.V | 2f18d53 | 2017-03-21 22:59:59 +0530 | [diff] [blame] | 97 | #define PTE_RPN_MASK (((1UL << _PAGE_PA_MAX) - 1) & (PAGE_MASK)) |
Aneesh Kumar K.V | 2e87351 | 2016-04-29 23:25:47 +1000 | [diff] [blame] | 98 | /* |
| 99 | * set of bits not changed in pmd_modify. Even though we have hash specific bits |
| 100 | * in here, on radix we expect them to be zero. |
| 101 | */ |
| 102 | #define _HPAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ |
| 103 | _PAGE_ACCESSED | H_PAGE_THP_HUGE | _PAGE_PTE | \ |
| 104 | _PAGE_SOFT_DIRTY) |
| 105 | /* |
| 106 | * user access blocked by key |
| 107 | */ |
| 108 | #define _PAGE_KERNEL_RW (_PAGE_PRIVILEGED | _PAGE_RW | _PAGE_DIRTY) |
| 109 | #define _PAGE_KERNEL_RO (_PAGE_PRIVILEGED | _PAGE_READ) |
| 110 | #define _PAGE_KERNEL_RWX (_PAGE_PRIVILEGED | _PAGE_DIRTY | \ |
| 111 | _PAGE_RW | _PAGE_EXEC) |
| 112 | /* |
| 113 | * No page size encoding in the linux PTE |
| 114 | */ |
| 115 | #define _PAGE_PSIZE 0 |
| 116 | /* |
| 117 | * _PAGE_CHG_MASK masks of bits that are to be preserved across |
| 118 | * pgprot changes |
| 119 | */ |
| 120 | #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ |
| 121 | _PAGE_ACCESSED | _PAGE_SPECIAL | _PAGE_PTE | \ |
| 122 | _PAGE_SOFT_DIRTY) |
| 123 | /* |
| 124 | * Mask of bits returned by pte_pgprot() |
| 125 | */ |
| 126 | #define PAGE_PROT_BITS (_PAGE_SAO | _PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT | \ |
| 127 | H_PAGE_4K_PFN | _PAGE_PRIVILEGED | _PAGE_ACCESSED | \ |
| 128 | _PAGE_READ | _PAGE_WRITE | _PAGE_DIRTY | _PAGE_EXEC | \ |
| 129 | _PAGE_SOFT_DIRTY) |
| 130 | /* |
| 131 | * We define 2 sets of base prot bits, one for basic pages (ie, |
| 132 | * cacheable kernel and user pages) and one for non cacheable |
| 133 | * pages. We always set _PAGE_COHERENT when SMP is enabled or |
| 134 | * the processor might need it for DMA coherency. |
| 135 | */ |
| 136 | #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE) |
| 137 | #define _PAGE_BASE (_PAGE_BASE_NC) |
| 138 | |
| 139 | /* Permission masks used to generate the __P and __S table, |
| 140 | * |
| 141 | * Note:__pgprot is defined in arch/powerpc/include/asm/page.h |
| 142 | * |
| 143 | * Write permissions imply read permissions for now (we could make write-only |
| 144 | * pages on BookE but we don't bother for now). Execute permission control is |
| 145 | * possible on platforms that define _PAGE_EXEC |
| 146 | * |
| 147 | * Note due to the way vm flags are laid out, the bits are XWR |
| 148 | */ |
| 149 | #define PAGE_NONE __pgprot(_PAGE_BASE | _PAGE_PRIVILEGED) |
| 150 | #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_RW) |
| 151 | #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_EXEC) |
| 152 | #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_READ) |
| 153 | #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC) |
| 154 | #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_READ) |
| 155 | #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC) |
| 156 | |
| 157 | #define __P000 PAGE_NONE |
| 158 | #define __P001 PAGE_READONLY |
| 159 | #define __P010 PAGE_COPY |
| 160 | #define __P011 PAGE_COPY |
| 161 | #define __P100 PAGE_READONLY_X |
| 162 | #define __P101 PAGE_READONLY_X |
| 163 | #define __P110 PAGE_COPY_X |
| 164 | #define __P111 PAGE_COPY_X |
| 165 | |
| 166 | #define __S000 PAGE_NONE |
| 167 | #define __S001 PAGE_READONLY |
| 168 | #define __S010 PAGE_SHARED |
| 169 | #define __S011 PAGE_SHARED |
| 170 | #define __S100 PAGE_READONLY_X |
| 171 | #define __S101 PAGE_READONLY_X |
| 172 | #define __S110 PAGE_SHARED_X |
| 173 | #define __S111 PAGE_SHARED_X |
| 174 | |
| 175 | /* Permission masks used for kernel mappings */ |
| 176 | #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW) |
| 177 | #define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ |
| 178 | _PAGE_TOLERANT) |
| 179 | #define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ |
| 180 | _PAGE_NON_IDEMPOTENT) |
| 181 | #define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX) |
| 182 | #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO) |
| 183 | #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX) |
| 184 | |
| 185 | /* |
| 186 | * Protection used for kernel text. We want the debuggers to be able to |
| 187 | * set breakpoints anywhere, so don't write protect the kernel text |
| 188 | * on platforms where such control is possible. |
| 189 | */ |
| 190 | #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) || \ |
| 191 | defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE) |
| 192 | #define PAGE_KERNEL_TEXT PAGE_KERNEL_X |
| 193 | #else |
| 194 | #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX |
| 195 | #endif |
| 196 | |
| 197 | /* Make modules code happy. We don't set RO yet */ |
| 198 | #define PAGE_KERNEL_EXEC PAGE_KERNEL_X |
| 199 | #define PAGE_AGP (PAGE_KERNEL_NC) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 200 | |
Aneesh Kumar K.V | dd1842a | 2016-04-29 23:25:49 +1000 | [diff] [blame] | 201 | #ifndef __ASSEMBLY__ |
| 202 | /* |
| 203 | * page table defines |
| 204 | */ |
| 205 | extern unsigned long __pte_index_size; |
| 206 | extern unsigned long __pmd_index_size; |
| 207 | extern unsigned long __pud_index_size; |
| 208 | extern unsigned long __pgd_index_size; |
| 209 | extern unsigned long __pmd_cache_index; |
| 210 | #define PTE_INDEX_SIZE __pte_index_size |
| 211 | #define PMD_INDEX_SIZE __pmd_index_size |
| 212 | #define PUD_INDEX_SIZE __pud_index_size |
| 213 | #define PGD_INDEX_SIZE __pgd_index_size |
| 214 | #define PMD_CACHE_INDEX __pmd_cache_index |
| 215 | /* |
| 216 | * Because of use of pte fragments and THP, size of page table |
| 217 | * are not always derived out of index size above. |
| 218 | */ |
| 219 | extern unsigned long __pte_table_size; |
| 220 | extern unsigned long __pmd_table_size; |
| 221 | extern unsigned long __pud_table_size; |
| 222 | extern unsigned long __pgd_table_size; |
| 223 | #define PTE_TABLE_SIZE __pte_table_size |
| 224 | #define PMD_TABLE_SIZE __pmd_table_size |
| 225 | #define PUD_TABLE_SIZE __pud_table_size |
| 226 | #define PGD_TABLE_SIZE __pgd_table_size |
Aneesh Kumar K.V | a2f41eb | 2016-04-29 23:26:19 +1000 | [diff] [blame] | 227 | |
| 228 | extern unsigned long __pmd_val_bits; |
| 229 | extern unsigned long __pud_val_bits; |
| 230 | extern unsigned long __pgd_val_bits; |
| 231 | #define PMD_VAL_BITS __pmd_val_bits |
| 232 | #define PUD_VAL_BITS __pud_val_bits |
| 233 | #define PGD_VAL_BITS __pgd_val_bits |
Aneesh Kumar K.V | 5ed7ecd | 2016-04-29 23:26:23 +1000 | [diff] [blame] | 234 | |
| 235 | extern unsigned long __pte_frag_nr; |
| 236 | #define PTE_FRAG_NR __pte_frag_nr |
| 237 | extern unsigned long __pte_frag_size_shift; |
| 238 | #define PTE_FRAG_SIZE_SHIFT __pte_frag_size_shift |
| 239 | #define PTE_FRAG_SIZE (1UL << PTE_FRAG_SIZE_SHIFT) |
Aneesh Kumar K.V | dd1842a | 2016-04-29 23:25:49 +1000 | [diff] [blame] | 240 | |
| 241 | #define PTRS_PER_PTE (1 << PTE_INDEX_SIZE) |
| 242 | #define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) |
| 243 | #define PTRS_PER_PUD (1 << PUD_INDEX_SIZE) |
| 244 | #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) |
| 245 | |
| 246 | /* PMD_SHIFT determines what a second-level page table entry can map */ |
| 247 | #define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE) |
| 248 | #define PMD_SIZE (1UL << PMD_SHIFT) |
| 249 | #define PMD_MASK (~(PMD_SIZE-1)) |
| 250 | |
| 251 | /* PUD_SHIFT determines what a third-level page table entry can map */ |
| 252 | #define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE) |
| 253 | #define PUD_SIZE (1UL << PUD_SHIFT) |
| 254 | #define PUD_MASK (~(PUD_SIZE-1)) |
| 255 | |
| 256 | /* PGDIR_SHIFT determines what a fourth-level page table entry can map */ |
| 257 | #define PGDIR_SHIFT (PUD_SHIFT + PUD_INDEX_SIZE) |
| 258 | #define PGDIR_SIZE (1UL << PGDIR_SHIFT) |
| 259 | #define PGDIR_MASK (~(PGDIR_SIZE-1)) |
| 260 | |
| 261 | /* Bits to mask out from a PMD to get to the PTE page */ |
| 262 | #define PMD_MASKED_BITS 0xc0000000000000ffUL |
| 263 | /* Bits to mask out from a PUD to get to the PMD page */ |
| 264 | #define PUD_MASKED_BITS 0xc0000000000000ffUL |
| 265 | /* Bits to mask out from a PGD to get to the PUD page */ |
| 266 | #define PGD_MASKED_BITS 0xc0000000000000ffUL |
Aneesh Kumar K.V | d6a9996 | 2016-04-29 23:26:21 +1000 | [diff] [blame] | 267 | |
| 268 | extern unsigned long __vmalloc_start; |
| 269 | extern unsigned long __vmalloc_end; |
| 270 | #define VMALLOC_START __vmalloc_start |
| 271 | #define VMALLOC_END __vmalloc_end |
| 272 | |
| 273 | extern unsigned long __kernel_virt_start; |
| 274 | extern unsigned long __kernel_virt_size; |
| 275 | #define KERN_VIRT_START __kernel_virt_start |
| 276 | #define KERN_VIRT_SIZE __kernel_virt_size |
| 277 | extern struct page *vmemmap; |
| 278 | extern unsigned long ioremap_bot; |
Darren Stevens | bfa3708 | 2016-06-29 21:06:28 +0100 | [diff] [blame] | 279 | extern unsigned long pci_io_base; |
Aneesh Kumar K.V | dd1842a | 2016-04-29 23:25:49 +1000 | [diff] [blame] | 280 | #endif /* __ASSEMBLY__ */ |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 281 | |
Aneesh Kumar K.V | ab537dc | 2015-12-01 09:06:30 +0530 | [diff] [blame] | 282 | #include <asm/book3s/64/hash.h> |
Aneesh Kumar K.V | b0b5e9b | 2016-04-29 23:25:52 +1000 | [diff] [blame] | 283 | #include <asm/book3s/64/radix.h> |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 284 | |
Aneesh Kumar K.V | a9252aae | 2016-04-29 23:25:55 +1000 | [diff] [blame] | 285 | #ifdef CONFIG_PPC_64K_PAGES |
| 286 | #include <asm/book3s/64/pgtable-64k.h> |
| 287 | #else |
| 288 | #include <asm/book3s/64/pgtable-4k.h> |
| 289 | #endif |
| 290 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 291 | #include <asm/barrier.h> |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 292 | /* |
| 293 | * The second half of the kernel virtual space is used for IO mappings, |
| 294 | * it's itself carved into the PIO region (ISA and PHB IO space) and |
| 295 | * the ioremap space |
| 296 | * |
| 297 | * ISA_IO_BASE = KERN_IO_START, 64K reserved area |
| 298 | * PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces |
| 299 | * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE |
| 300 | */ |
| 301 | #define KERN_IO_START (KERN_VIRT_START + (KERN_VIRT_SIZE >> 1)) |
| 302 | #define FULL_IO_SIZE 0x80000000ul |
| 303 | #define ISA_IO_BASE (KERN_IO_START) |
| 304 | #define ISA_IO_END (KERN_IO_START + 0x10000ul) |
| 305 | #define PHB_IO_BASE (ISA_IO_END) |
| 306 | #define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE) |
| 307 | #define IOREMAP_BASE (PHB_IO_END) |
| 308 | #define IOREMAP_END (KERN_VIRT_START + KERN_VIRT_SIZE) |
| 309 | |
Aneesh Kumar K.V | b0412ea | 2015-12-01 09:06:33 +0530 | [diff] [blame] | 310 | /* Advertise special mapping type for AGP */ |
Aneesh Kumar K.V | b0412ea | 2015-12-01 09:06:33 +0530 | [diff] [blame] | 311 | #define HAVE_PAGE_AGP |
| 312 | |
| 313 | /* Advertise support for _PAGE_SPECIAL */ |
| 314 | #define __HAVE_ARCH_PTE_SPECIAL |
| 315 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 316 | #ifndef __ASSEMBLY__ |
| 317 | |
| 318 | /* |
| 319 | * This is the default implementation of various PTE accessors, it's |
| 320 | * used in all cases except Book3S with 64K pages where we have a |
| 321 | * concept of sub-pages |
| 322 | */ |
| 323 | #ifndef __real_pte |
| 324 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 325 | #define __real_pte(e,p) ((real_pte_t){(e)}) |
| 326 | #define __rpte_to_pte(r) ((r).pte) |
Aneesh Kumar K.V | 945537d | 2016-04-29 23:25:45 +1000 | [diff] [blame] | 327 | #define __rpte_to_hidx(r,index) (pte_val(__rpte_to_pte(r)) >> H_PAGE_F_GIX_SHIFT) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 328 | |
| 329 | #define pte_iterate_hashed_subpages(rpte, psize, va, index, shift) \ |
| 330 | do { \ |
| 331 | index = 0; \ |
| 332 | shift = mmu_psize_defs[psize].shift; \ |
| 333 | |
| 334 | #define pte_iterate_hashed_end() } while(0) |
| 335 | |
| 336 | /* |
| 337 | * We expect this to be called only for user addresses or kernel virtual |
| 338 | * addresses other than the linear mapping. |
| 339 | */ |
| 340 | #define pte_pagesize_index(mm, addr, pte) MMU_PAGE_4K |
| 341 | |
| 342 | #endif /* __real_pte */ |
| 343 | |
Aneesh Kumar K.V | ac94ac79 | 2016-04-29 23:25:54 +1000 | [diff] [blame] | 344 | static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr, |
| 345 | pte_t *ptep, unsigned long clr, |
| 346 | unsigned long set, int huge) |
| 347 | { |
| 348 | if (radix_enabled()) |
| 349 | return radix__pte_update(mm, addr, ptep, clr, set, huge); |
| 350 | return hash__pte_update(mm, addr, ptep, clr, set, huge); |
| 351 | } |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 352 | /* |
| 353 | * For hash even if we have _PAGE_ACCESSED = 0, we do a pte_update. |
| 354 | * We currently remove entries from the hashtable regardless of whether |
| 355 | * the entry was young or dirty. |
| 356 | * |
| 357 | * We should be more intelligent about this but for the moment we override |
| 358 | * these functions and force a tlb flush unconditionally |
| 359 | * For radix: H_PAGE_HASHPTE should be zero. Hence we can use the same |
| 360 | * function for both hash and radix. |
| 361 | */ |
| 362 | static inline int __ptep_test_and_clear_young(struct mm_struct *mm, |
| 363 | unsigned long addr, pte_t *ptep) |
| 364 | { |
| 365 | unsigned long old; |
| 366 | |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 367 | if ((pte_raw(*ptep) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0) |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 368 | return 0; |
| 369 | old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0); |
| 370 | return (old & _PAGE_ACCESSED) != 0; |
| 371 | } |
| 372 | |
| 373 | #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG |
| 374 | #define ptep_test_and_clear_young(__vma, __addr, __ptep) \ |
| 375 | ({ \ |
| 376 | int __r; \ |
| 377 | __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \ |
| 378 | __r; \ |
| 379 | }) |
| 380 | |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 381 | static inline int __pte_write(pte_t pte) |
Aneesh Kumar K.V | 52c50ca | 2017-03-09 16:16:36 -0800 | [diff] [blame] | 382 | { |
| 383 | return !!(pte_raw(pte) & cpu_to_be64(_PAGE_WRITE)); |
| 384 | } |
| 385 | |
| 386 | #ifdef CONFIG_NUMA_BALANCING |
| 387 | #define pte_savedwrite pte_savedwrite |
| 388 | static inline bool pte_savedwrite(pte_t pte) |
| 389 | { |
| 390 | /* |
| 391 | * Saved write ptes are prot none ptes that doesn't have |
| 392 | * privileged bit sit. We mark prot none as one which has |
| 393 | * present and pviliged bit set and RWX cleared. To mark |
| 394 | * protnone which used to have _PAGE_WRITE set we clear |
| 395 | * the privileged bit. |
| 396 | */ |
| 397 | return !(pte_raw(pte) & cpu_to_be64(_PAGE_RWX | _PAGE_PRIVILEGED)); |
| 398 | } |
| 399 | #else |
| 400 | #define pte_savedwrite pte_savedwrite |
| 401 | static inline bool pte_savedwrite(pte_t pte) |
| 402 | { |
| 403 | return false; |
| 404 | } |
| 405 | #endif |
| 406 | |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 407 | static inline int pte_write(pte_t pte) |
| 408 | { |
| 409 | return __pte_write(pte) || pte_savedwrite(pte); |
| 410 | } |
| 411 | |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 412 | #define __HAVE_ARCH_PTEP_SET_WRPROTECT |
| 413 | static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, |
| 414 | pte_t *ptep) |
| 415 | { |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 416 | if (__pte_write(*ptep)) |
Aneesh Kumar K.V | 52c50ca | 2017-03-09 16:16:36 -0800 | [diff] [blame] | 417 | pte_update(mm, addr, ptep, _PAGE_WRITE, 0, 0); |
| 418 | else if (unlikely(pte_savedwrite(*ptep))) |
| 419 | pte_update(mm, addr, ptep, 0, _PAGE_PRIVILEGED, 0); |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, |
| 423 | unsigned long addr, pte_t *ptep) |
| 424 | { |
Aneesh Kumar K.V | 52c50ca | 2017-03-09 16:16:36 -0800 | [diff] [blame] | 425 | /* |
| 426 | * We should not find protnone for hugetlb, but this complete the |
| 427 | * interface. |
| 428 | */ |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 429 | if (__pte_write(*ptep)) |
Aneesh Kumar K.V | 52c50ca | 2017-03-09 16:16:36 -0800 | [diff] [blame] | 430 | pte_update(mm, addr, ptep, _PAGE_WRITE, 0, 1); |
| 431 | else if (unlikely(pte_savedwrite(*ptep))) |
| 432 | pte_update(mm, addr, ptep, 0, _PAGE_PRIVILEGED, 1); |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | #define __HAVE_ARCH_PTEP_GET_AND_CLEAR |
| 436 | static inline pte_t ptep_get_and_clear(struct mm_struct *mm, |
| 437 | unsigned long addr, pte_t *ptep) |
| 438 | { |
| 439 | unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0, 0); |
| 440 | return __pte(old); |
| 441 | } |
| 442 | |
Aneesh Kumar K.V | f4894b8 | 2017-02-09 08:28:20 +0530 | [diff] [blame] | 443 | #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL |
| 444 | static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, |
| 445 | unsigned long addr, |
| 446 | pte_t *ptep, int full) |
| 447 | { |
| 448 | if (full && radix_enabled()) { |
| 449 | /* |
| 450 | * Let's skip the DD1 style pte update here. We know that |
| 451 | * this is a full mm pte clear and hence can be sure there is |
| 452 | * no parallel set_pte. |
| 453 | */ |
| 454 | return radix__ptep_get_and_clear_full(mm, addr, ptep, full); |
| 455 | } |
| 456 | return ptep_get_and_clear(mm, addr, ptep); |
| 457 | } |
| 458 | |
| 459 | |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 460 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, |
| 461 | pte_t * ptep) |
| 462 | { |
| 463 | pte_update(mm, addr, ptep, ~0UL, 0, 0); |
| 464 | } |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 465 | |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 466 | static inline int pte_dirty(pte_t pte) |
| 467 | { |
| 468 | return !!(pte_raw(pte) & cpu_to_be64(_PAGE_DIRTY)); |
| 469 | } |
| 470 | |
| 471 | static inline int pte_young(pte_t pte) |
| 472 | { |
| 473 | return !!(pte_raw(pte) & cpu_to_be64(_PAGE_ACCESSED)); |
| 474 | } |
| 475 | |
| 476 | static inline int pte_special(pte_t pte) |
| 477 | { |
| 478 | return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SPECIAL)); |
| 479 | } |
| 480 | |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 481 | static inline pgprot_t pte_pgprot(pte_t pte) { return __pgprot(pte_val(pte) & PAGE_PROT_BITS); } |
| 482 | |
| 483 | #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY |
| 484 | static inline bool pte_soft_dirty(pte_t pte) |
| 485 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 486 | return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SOFT_DIRTY)); |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 487 | } |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 488 | |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 489 | static inline pte_t pte_mksoft_dirty(pte_t pte) |
| 490 | { |
| 491 | return __pte(pte_val(pte) | _PAGE_SOFT_DIRTY); |
| 492 | } |
| 493 | |
| 494 | static inline pte_t pte_clear_soft_dirty(pte_t pte) |
| 495 | { |
| 496 | return __pte(pte_val(pte) & ~_PAGE_SOFT_DIRTY); |
| 497 | } |
| 498 | #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */ |
| 499 | |
| 500 | #ifdef CONFIG_NUMA_BALANCING |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 501 | static inline int pte_protnone(pte_t pte) |
| 502 | { |
Aneesh Kumar K.V | c137a27 | 2017-02-24 14:59:21 -0800 | [diff] [blame] | 503 | return (pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT | _PAGE_PTE | _PAGE_RWX)) == |
| 504 | cpu_to_be64(_PAGE_PRESENT | _PAGE_PTE); |
| 505 | } |
| 506 | |
| 507 | #define pte_mk_savedwrite pte_mk_savedwrite |
| 508 | static inline pte_t pte_mk_savedwrite(pte_t pte) |
| 509 | { |
| 510 | /* |
| 511 | * Used by Autonuma subsystem to preserve the write bit |
| 512 | * while marking the pte PROT_NONE. Only allow this |
| 513 | * on PROT_NONE pte |
| 514 | */ |
| 515 | VM_BUG_ON((pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT | _PAGE_RWX | _PAGE_PRIVILEGED)) != |
| 516 | cpu_to_be64(_PAGE_PRESENT | _PAGE_PRIVILEGED)); |
| 517 | return __pte(pte_val(pte) & ~_PAGE_PRIVILEGED); |
| 518 | } |
| 519 | |
| 520 | #define pte_clear_savedwrite pte_clear_savedwrite |
| 521 | static inline pte_t pte_clear_savedwrite(pte_t pte) |
| 522 | { |
| 523 | /* |
| 524 | * Used by KSM subsystem to make a protnone pte readonly. |
| 525 | */ |
| 526 | VM_BUG_ON(!pte_protnone(pte)); |
| 527 | return __pte(pte_val(pte) | _PAGE_PRIVILEGED); |
| 528 | } |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 529 | #else |
| 530 | #define pte_clear_savedwrite pte_clear_savedwrite |
| 531 | static inline pte_t pte_clear_savedwrite(pte_t pte) |
| 532 | { |
| 533 | VM_WARN_ON(1); |
| 534 | return __pte(pte_val(pte) & ~_PAGE_WRITE); |
| 535 | } |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 536 | #endif /* CONFIG_NUMA_BALANCING */ |
| 537 | |
| 538 | static inline int pte_present(pte_t pte) |
| 539 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 540 | return !!(pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT)); |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 541 | } |
| 542 | /* |
| 543 | * Conversion functions: convert a page and protection to a page entry, |
| 544 | * and a page entry and page directory to the page they refer to. |
| 545 | * |
| 546 | * Even if PTEs can be unsigned long long, a PFN is always an unsigned |
| 547 | * long for now. |
| 548 | */ |
| 549 | static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) |
| 550 | { |
| 551 | return __pte((((pte_basic_t)(pfn) << PAGE_SHIFT) & PTE_RPN_MASK) | |
| 552 | pgprot_val(pgprot)); |
| 553 | } |
| 554 | |
| 555 | static inline unsigned long pte_pfn(pte_t pte) |
| 556 | { |
| 557 | return (pte_val(pte) & PTE_RPN_MASK) >> PAGE_SHIFT; |
| 558 | } |
| 559 | |
| 560 | /* Generic modifiers for PTE bits */ |
| 561 | static inline pte_t pte_wrprotect(pte_t pte) |
| 562 | { |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 563 | if (unlikely(pte_savedwrite(pte))) |
| 564 | return pte_clear_savedwrite(pte); |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 565 | return __pte(pte_val(pte) & ~_PAGE_WRITE); |
| 566 | } |
| 567 | |
| 568 | static inline pte_t pte_mkclean(pte_t pte) |
| 569 | { |
| 570 | return __pte(pte_val(pte) & ~_PAGE_DIRTY); |
| 571 | } |
| 572 | |
| 573 | static inline pte_t pte_mkold(pte_t pte) |
| 574 | { |
| 575 | return __pte(pte_val(pte) & ~_PAGE_ACCESSED); |
| 576 | } |
| 577 | |
| 578 | static inline pte_t pte_mkwrite(pte_t pte) |
| 579 | { |
| 580 | /* |
| 581 | * write implies read, hence set both |
| 582 | */ |
| 583 | return __pte(pte_val(pte) | _PAGE_RW); |
| 584 | } |
| 585 | |
| 586 | static inline pte_t pte_mkdirty(pte_t pte) |
| 587 | { |
| 588 | return __pte(pte_val(pte) | _PAGE_DIRTY | _PAGE_SOFT_DIRTY); |
| 589 | } |
| 590 | |
| 591 | static inline pte_t pte_mkyoung(pte_t pte) |
| 592 | { |
| 593 | return __pte(pte_val(pte) | _PAGE_ACCESSED); |
| 594 | } |
| 595 | |
| 596 | static inline pte_t pte_mkspecial(pte_t pte) |
| 597 | { |
| 598 | return __pte(pte_val(pte) | _PAGE_SPECIAL); |
| 599 | } |
| 600 | |
| 601 | static inline pte_t pte_mkhuge(pte_t pte) |
| 602 | { |
| 603 | return pte; |
| 604 | } |
| 605 | |
Oliver O'Halloran | ebd3119 | 2017-06-28 11:32:34 +1000 | [diff] [blame] | 606 | static inline pte_t pte_mkdevmap(pte_t pte) |
| 607 | { |
| 608 | return __pte(pte_val(pte) | _PAGE_SPECIAL|_PAGE_DEVMAP); |
| 609 | } |
| 610 | |
Oliver O'Halloran | c9c98bc | 2017-07-28 01:35:53 +1000 | [diff] [blame] | 611 | /* |
| 612 | * This is potentially called with a pmd as the argument, in which case it's not |
| 613 | * safe to check _PAGE_DEVMAP unless we also confirm that _PAGE_PTE is set. |
| 614 | * That's because the bit we use for _PAGE_DEVMAP is not reserved for software |
| 615 | * use in page directory entries (ie. non-ptes). |
| 616 | */ |
Oliver O'Halloran | ebd3119 | 2017-06-28 11:32:34 +1000 | [diff] [blame] | 617 | static inline int pte_devmap(pte_t pte) |
| 618 | { |
Oliver O'Halloran | c9c98bc | 2017-07-28 01:35:53 +1000 | [diff] [blame] | 619 | u64 mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE); |
| 620 | |
| 621 | return (pte_raw(pte) & mask) == mask; |
Oliver O'Halloran | ebd3119 | 2017-06-28 11:32:34 +1000 | [diff] [blame] | 622 | } |
| 623 | |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 624 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
| 625 | { |
| 626 | /* FIXME!! check whether this need to be a conditional */ |
| 627 | return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)); |
| 628 | } |
| 629 | |
Aneesh Kumar K.V | 34fbadd | 2016-04-29 23:25:51 +1000 | [diff] [blame] | 630 | static inline bool pte_user(pte_t pte) |
| 631 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 632 | return !(pte_raw(pte) & cpu_to_be64(_PAGE_PRIVILEGED)); |
Aneesh Kumar K.V | 34fbadd | 2016-04-29 23:25:51 +1000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* Encode and de-code a swap entry */ |
| 636 | #define MAX_SWAPFILES_CHECK() do { \ |
| 637 | BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS); \ |
| 638 | /* \ |
| 639 | * Don't have overlapping bits with _PAGE_HPTEFLAGS \ |
| 640 | * We filter HPTEFLAGS on set_pte. \ |
| 641 | */ \ |
| 642 | BUILD_BUG_ON(_PAGE_HPTEFLAGS & (0x1f << _PAGE_BIT_SWAP_TYPE)); \ |
| 643 | BUILD_BUG_ON(_PAGE_HPTEFLAGS & _PAGE_SWP_SOFT_DIRTY); \ |
| 644 | } while (0) |
| 645 | /* |
| 646 | * on pte we don't need handle RADIX_TREE_EXCEPTIONAL_SHIFT; |
| 647 | */ |
| 648 | #define SWP_TYPE_BITS 5 |
| 649 | #define __swp_type(x) (((x).val >> _PAGE_BIT_SWAP_TYPE) \ |
| 650 | & ((1UL << SWP_TYPE_BITS) - 1)) |
| 651 | #define __swp_offset(x) (((x).val & PTE_RPN_MASK) >> PAGE_SHIFT) |
| 652 | #define __swp_entry(type, offset) ((swp_entry_t) { \ |
| 653 | ((type) << _PAGE_BIT_SWAP_TYPE) \ |
| 654 | | (((offset) << PAGE_SHIFT) & PTE_RPN_MASK)}) |
| 655 | /* |
| 656 | * swp_entry_t must be independent of pte bits. We build a swp_entry_t from |
| 657 | * swap type and offset we get from swap and convert that to pte to find a |
| 658 | * matching pte in linux page table. |
| 659 | * Clear bits not found in swap entries here. |
| 660 | */ |
| 661 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) & ~_PAGE_PTE }) |
| 662 | #define __swp_entry_to_pte(x) __pte((x).val | _PAGE_PTE) |
| 663 | |
| 664 | #ifdef CONFIG_MEM_SOFT_DIRTY |
| 665 | #define _PAGE_SWP_SOFT_DIRTY (1UL << (SWP_TYPE_BITS + _PAGE_BIT_SWAP_TYPE)) |
| 666 | #else |
| 667 | #define _PAGE_SWP_SOFT_DIRTY 0UL |
| 668 | #endif /* CONFIG_MEM_SOFT_DIRTY */ |
| 669 | |
| 670 | #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY |
| 671 | static inline pte_t pte_swp_mksoft_dirty(pte_t pte) |
| 672 | { |
| 673 | return __pte(pte_val(pte) | _PAGE_SWP_SOFT_DIRTY); |
| 674 | } |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 675 | |
Aneesh Kumar K.V | 34fbadd | 2016-04-29 23:25:51 +1000 | [diff] [blame] | 676 | static inline bool pte_swp_soft_dirty(pte_t pte) |
| 677 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 678 | return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SWP_SOFT_DIRTY)); |
Aneesh Kumar K.V | 34fbadd | 2016-04-29 23:25:51 +1000 | [diff] [blame] | 679 | } |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 680 | |
Aneesh Kumar K.V | 34fbadd | 2016-04-29 23:25:51 +1000 | [diff] [blame] | 681 | static inline pte_t pte_swp_clear_soft_dirty(pte_t pte) |
| 682 | { |
| 683 | return __pte(pte_val(pte) & ~_PAGE_SWP_SOFT_DIRTY); |
| 684 | } |
| 685 | #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */ |
| 686 | |
| 687 | static inline bool check_pte_access(unsigned long access, unsigned long ptev) |
| 688 | { |
| 689 | /* |
| 690 | * This check for _PAGE_RWX and _PAGE_PRESENT bits |
| 691 | */ |
| 692 | if (access & ~ptev) |
| 693 | return false; |
| 694 | /* |
| 695 | * This check for access to privilege space |
| 696 | */ |
| 697 | if ((access & _PAGE_PRIVILEGED) != (ptev & _PAGE_PRIVILEGED)) |
| 698 | return false; |
| 699 | |
| 700 | return true; |
| 701 | } |
Aneesh Kumar K.V | ac94ac79 | 2016-04-29 23:25:54 +1000 | [diff] [blame] | 702 | /* |
| 703 | * Generic functions with hash/radix callbacks |
| 704 | */ |
| 705 | |
Aneesh Kumar K.V | c6d1a76 | 2016-08-24 15:03:38 +0530 | [diff] [blame] | 706 | static inline void __ptep_set_access_flags(struct mm_struct *mm, |
Aneesh Kumar K.V | b3603e1 | 2016-11-28 11:47:02 +0530 | [diff] [blame] | 707 | pte_t *ptep, pte_t entry, |
| 708 | unsigned long address) |
Aneesh Kumar K.V | ac94ac79 | 2016-04-29 23:25:54 +1000 | [diff] [blame] | 709 | { |
| 710 | if (radix_enabled()) |
Aneesh Kumar K.V | b3603e1 | 2016-11-28 11:47:02 +0530 | [diff] [blame] | 711 | return radix__ptep_set_access_flags(mm, ptep, entry, address); |
Aneesh Kumar K.V | ac94ac79 | 2016-04-29 23:25:54 +1000 | [diff] [blame] | 712 | return hash__ptep_set_access_flags(ptep, entry); |
| 713 | } |
| 714 | |
| 715 | #define __HAVE_ARCH_PTE_SAME |
| 716 | static inline int pte_same(pte_t pte_a, pte_t pte_b) |
| 717 | { |
| 718 | if (radix_enabled()) |
| 719 | return radix__pte_same(pte_a, pte_b); |
| 720 | return hash__pte_same(pte_a, pte_b); |
| 721 | } |
| 722 | |
| 723 | static inline int pte_none(pte_t pte) |
| 724 | { |
| 725 | if (radix_enabled()) |
| 726 | return radix__pte_none(pte); |
| 727 | return hash__pte_none(pte); |
| 728 | } |
| 729 | |
| 730 | static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 731 | pte_t *ptep, pte_t pte, int percpu) |
| 732 | { |
| 733 | if (radix_enabled()) |
| 734 | return radix__set_pte_at(mm, addr, ptep, pte, percpu); |
| 735 | return hash__set_pte_at(mm, addr, ptep, pte, percpu); |
| 736 | } |
Aneesh Kumar K.V | 34fbadd | 2016-04-29 23:25:51 +1000 | [diff] [blame] | 737 | |
Aneesh Kumar K.V | 13f829a | 2016-04-29 23:25:48 +1000 | [diff] [blame] | 738 | #define _PAGE_CACHE_CTL (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT) |
| 739 | |
| 740 | #define pgprot_noncached pgprot_noncached |
| 741 | static inline pgprot_t pgprot_noncached(pgprot_t prot) |
| 742 | { |
| 743 | return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | |
| 744 | _PAGE_NON_IDEMPOTENT); |
| 745 | } |
| 746 | |
| 747 | #define pgprot_noncached_wc pgprot_noncached_wc |
| 748 | static inline pgprot_t pgprot_noncached_wc(pgprot_t prot) |
| 749 | { |
| 750 | return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | |
| 751 | _PAGE_TOLERANT); |
| 752 | } |
| 753 | |
| 754 | #define pgprot_cached pgprot_cached |
| 755 | static inline pgprot_t pgprot_cached(pgprot_t prot) |
| 756 | { |
| 757 | return __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL)); |
| 758 | } |
| 759 | |
| 760 | #define pgprot_writecombine pgprot_writecombine |
| 761 | static inline pgprot_t pgprot_writecombine(pgprot_t prot) |
| 762 | { |
| 763 | return pgprot_noncached_wc(prot); |
| 764 | } |
| 765 | /* |
| 766 | * check a pte mapping have cache inhibited property |
| 767 | */ |
| 768 | static inline bool pte_ci(pte_t pte) |
| 769 | { |
| 770 | unsigned long pte_v = pte_val(pte); |
| 771 | |
| 772 | if (((pte_v & _PAGE_CACHE_CTL) == _PAGE_TOLERANT) || |
| 773 | ((pte_v & _PAGE_CACHE_CTL) == _PAGE_NON_IDEMPOTENT)) |
| 774 | return true; |
| 775 | return false; |
| 776 | } |
| 777 | |
Aneesh Kumar K.V | f281b5d | 2015-12-01 09:06:35 +0530 | [diff] [blame] | 778 | static inline void pmd_set(pmd_t *pmdp, unsigned long val) |
| 779 | { |
| 780 | *pmdp = __pmd(val); |
| 781 | } |
| 782 | |
| 783 | static inline void pmd_clear(pmd_t *pmdp) |
| 784 | { |
| 785 | *pmdp = __pmd(0); |
| 786 | } |
| 787 | |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 788 | static inline int pmd_none(pmd_t pmd) |
| 789 | { |
| 790 | return !pmd_raw(pmd); |
| 791 | } |
| 792 | |
| 793 | static inline int pmd_present(pmd_t pmd) |
| 794 | { |
| 795 | |
| 796 | return !pmd_none(pmd); |
| 797 | } |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 798 | |
Aneesh Kumar K.V | ac94ac79 | 2016-04-29 23:25:54 +1000 | [diff] [blame] | 799 | static inline int pmd_bad(pmd_t pmd) |
| 800 | { |
| 801 | if (radix_enabled()) |
| 802 | return radix__pmd_bad(pmd); |
| 803 | return hash__pmd_bad(pmd); |
| 804 | } |
| 805 | |
Aneesh Kumar K.V | f281b5d | 2015-12-01 09:06:35 +0530 | [diff] [blame] | 806 | static inline void pud_set(pud_t *pudp, unsigned long val) |
| 807 | { |
| 808 | *pudp = __pud(val); |
| 809 | } |
| 810 | |
| 811 | static inline void pud_clear(pud_t *pudp) |
| 812 | { |
| 813 | *pudp = __pud(0); |
| 814 | } |
| 815 | |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 816 | static inline int pud_none(pud_t pud) |
| 817 | { |
| 818 | return !pud_raw(pud); |
| 819 | } |
| 820 | |
| 821 | static inline int pud_present(pud_t pud) |
| 822 | { |
| 823 | return !pud_none(pud); |
| 824 | } |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 825 | |
| 826 | extern struct page *pud_page(pud_t pud); |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 827 | extern struct page *pmd_page(pmd_t pmd); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 828 | static inline pte_t pud_pte(pud_t pud) |
| 829 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 830 | return __pte_raw(pud_raw(pud)); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | static inline pud_t pte_pud(pte_t pte) |
| 834 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 835 | return __pud_raw(pte_raw(pte)); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 836 | } |
| 837 | #define pud_write(pud) pte_write(pud_pte(pud)) |
Aneesh Kumar K.V | ac94ac79 | 2016-04-29 23:25:54 +1000 | [diff] [blame] | 838 | |
| 839 | static inline int pud_bad(pud_t pud) |
| 840 | { |
| 841 | if (radix_enabled()) |
| 842 | return radix__pud_bad(pud); |
| 843 | return hash__pud_bad(pud); |
| 844 | } |
| 845 | |
| 846 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 847 | #define pgd_write(pgd) pte_write(pgd_pte(pgd)) |
Aneesh Kumar K.V | f281b5d | 2015-12-01 09:06:35 +0530 | [diff] [blame] | 848 | static inline void pgd_set(pgd_t *pgdp, unsigned long val) |
| 849 | { |
| 850 | *pgdp = __pgd(val); |
| 851 | } |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 852 | |
Aneesh Kumar K.V | 368ced7 | 2016-03-01 09:45:13 +0530 | [diff] [blame] | 853 | static inline void pgd_clear(pgd_t *pgdp) |
| 854 | { |
| 855 | *pgdp = __pgd(0); |
| 856 | } |
| 857 | |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 858 | static inline int pgd_none(pgd_t pgd) |
| 859 | { |
| 860 | return !pgd_raw(pgd); |
| 861 | } |
| 862 | |
| 863 | static inline int pgd_present(pgd_t pgd) |
| 864 | { |
| 865 | return !pgd_none(pgd); |
| 866 | } |
Aneesh Kumar K.V | 368ced7 | 2016-03-01 09:45:13 +0530 | [diff] [blame] | 867 | |
| 868 | static inline pte_t pgd_pte(pgd_t pgd) |
| 869 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 870 | return __pte_raw(pgd_raw(pgd)); |
Aneesh Kumar K.V | 368ced7 | 2016-03-01 09:45:13 +0530 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static inline pgd_t pte_pgd(pte_t pte) |
| 874 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 875 | return __pgd_raw(pte_raw(pte)); |
Aneesh Kumar K.V | 368ced7 | 2016-03-01 09:45:13 +0530 | [diff] [blame] | 876 | } |
| 877 | |
Aneesh Kumar K.V | ac94ac79 | 2016-04-29 23:25:54 +1000 | [diff] [blame] | 878 | static inline int pgd_bad(pgd_t pgd) |
| 879 | { |
| 880 | if (radix_enabled()) |
| 881 | return radix__pgd_bad(pgd); |
| 882 | return hash__pgd_bad(pgd); |
| 883 | } |
| 884 | |
Aneesh Kumar K.V | 368ced7 | 2016-03-01 09:45:13 +0530 | [diff] [blame] | 885 | extern struct page *pgd_page(pgd_t pgd); |
| 886 | |
Aneesh Kumar K.V | aba480e | 2016-04-29 23:25:50 +1000 | [diff] [blame] | 887 | /* Pointers in the page table tree are physical addresses */ |
| 888 | #define __pgtable_ptr_val(ptr) __pa(ptr) |
| 889 | |
| 890 | #define pmd_page_vaddr(pmd) __va(pmd_val(pmd) & ~PMD_MASKED_BITS) |
| 891 | #define pud_page_vaddr(pud) __va(pud_val(pud) & ~PUD_MASKED_BITS) |
| 892 | #define pgd_page_vaddr(pgd) __va(pgd_val(pgd) & ~PGD_MASKED_BITS) |
| 893 | |
| 894 | #define pgd_index(address) (((address) >> (PGDIR_SHIFT)) & (PTRS_PER_PGD - 1)) |
| 895 | #define pud_index(address) (((address) >> (PUD_SHIFT)) & (PTRS_PER_PUD - 1)) |
| 896 | #define pmd_index(address) (((address) >> (PMD_SHIFT)) & (PTRS_PER_PMD - 1)) |
| 897 | #define pte_index(address) (((address) >> (PAGE_SHIFT)) & (PTRS_PER_PTE - 1)) |
| 898 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 899 | /* |
| 900 | * Find an entry in a page-table-directory. We combine the address region |
| 901 | * (the high order N bits) and the pgd portion of the address. |
| 902 | */ |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 903 | |
| 904 | #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address)) |
| 905 | |
Aneesh Kumar K.V | 368ced7 | 2016-03-01 09:45:13 +0530 | [diff] [blame] | 906 | #define pud_offset(pgdp, addr) \ |
| 907 | (((pud_t *) pgd_page_vaddr(*(pgdp))) + pud_index(addr)) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 908 | #define pmd_offset(pudp,addr) \ |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 909 | (((pmd_t *) pud_page_vaddr(*(pudp))) + pmd_index(addr)) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 910 | #define pte_offset_kernel(dir,addr) \ |
Aneesh Kumar K.V | 371352c | 2015-12-01 09:06:36 +0530 | [diff] [blame] | 911 | (((pte_t *) pmd_page_vaddr(*(dir))) + pte_index(addr)) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 912 | |
| 913 | #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr)) |
| 914 | #define pte_unmap(pte) do { } while(0) |
| 915 | |
| 916 | /* to find an entry in a kernel page-table-directory */ |
| 917 | /* This now only contains the vmalloc pages */ |
| 918 | #define pgd_offset_k(address) pgd_offset(&init_mm, address) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 919 | |
| 920 | #define pte_ERROR(e) \ |
| 921 | pr_err("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) |
| 922 | #define pmd_ERROR(e) \ |
| 923 | pr_err("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e)) |
Aneesh Kumar K.V | 368ced7 | 2016-03-01 09:45:13 +0530 | [diff] [blame] | 924 | #define pud_ERROR(e) \ |
| 925 | pr_err("%s:%d: bad pud %08lx.\n", __FILE__, __LINE__, pud_val(e)) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 926 | #define pgd_ERROR(e) \ |
| 927 | pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) |
| 928 | |
Aneesh Kumar K.V | 31a14fa | 2016-04-29 23:25:59 +1000 | [diff] [blame] | 929 | static inline int map_kernel_page(unsigned long ea, unsigned long pa, |
| 930 | unsigned long flags) |
| 931 | { |
Aneesh Kumar K.V | d9225ad | 2016-04-29 23:26:00 +1000 | [diff] [blame] | 932 | if (radix_enabled()) { |
| 933 | #if defined(CONFIG_PPC_RADIX_MMU) && defined(DEBUG_VM) |
| 934 | unsigned long page_size = 1 << mmu_psize_defs[mmu_io_psize].shift; |
| 935 | WARN((page_size != PAGE_SIZE), "I/O page size != PAGE_SIZE"); |
| 936 | #endif |
| 937 | return radix__map_kernel_page(ea, pa, __pgprot(flags), PAGE_SIZE); |
| 938 | } |
Aneesh Kumar K.V | 31a14fa | 2016-04-29 23:25:59 +1000 | [diff] [blame] | 939 | return hash__map_kernel_page(ea, pa, flags); |
| 940 | } |
| 941 | |
| 942 | static inline int __meminit vmemmap_create_mapping(unsigned long start, |
| 943 | unsigned long page_size, |
| 944 | unsigned long phys) |
| 945 | { |
Aneesh Kumar K.V | d9225ad | 2016-04-29 23:26:00 +1000 | [diff] [blame] | 946 | if (radix_enabled()) |
| 947 | return radix__vmemmap_create_mapping(start, page_size, phys); |
Aneesh Kumar K.V | 31a14fa | 2016-04-29 23:25:59 +1000 | [diff] [blame] | 948 | return hash__vmemmap_create_mapping(start, page_size, phys); |
| 949 | } |
| 950 | |
| 951 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 952 | static inline void vmemmap_remove_mapping(unsigned long start, |
| 953 | unsigned long page_size) |
| 954 | { |
Aneesh Kumar K.V | d9225ad | 2016-04-29 23:26:00 +1000 | [diff] [blame] | 955 | if (radix_enabled()) |
| 956 | return radix__vmemmap_remove_mapping(start, page_size); |
Aneesh Kumar K.V | 31a14fa | 2016-04-29 23:25:59 +1000 | [diff] [blame] | 957 | return hash__vmemmap_remove_mapping(start, page_size); |
| 958 | } |
| 959 | #endif |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 960 | struct page *realmode_pfn_to_page(unsigned long pfn); |
| 961 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 962 | static inline pte_t pmd_pte(pmd_t pmd) |
| 963 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 964 | return __pte_raw(pmd_raw(pmd)); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | static inline pmd_t pte_pmd(pte_t pte) |
| 968 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 969 | return __pmd_raw(pte_raw(pte)); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static inline pte_t *pmdp_ptep(pmd_t *pmd) |
| 973 | { |
| 974 | return (pte_t *)pmd; |
| 975 | } |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 976 | #define pmd_pfn(pmd) pte_pfn(pmd_pte(pmd)) |
| 977 | #define pmd_dirty(pmd) pte_dirty(pmd_pte(pmd)) |
| 978 | #define pmd_young(pmd) pte_young(pmd_pte(pmd)) |
| 979 | #define pmd_mkold(pmd) pte_pmd(pte_mkold(pmd_pte(pmd))) |
| 980 | #define pmd_wrprotect(pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd))) |
| 981 | #define pmd_mkdirty(pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd))) |
Minchan Kim | d5d6a44 | 2016-01-15 16:55:29 -0800 | [diff] [blame] | 982 | #define pmd_mkclean(pmd) pte_pmd(pte_mkclean(pmd_pte(pmd))) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 983 | #define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd))) |
| 984 | #define pmd_mkwrite(pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd))) |
Aneesh Kumar K.V | c137a27 | 2017-02-24 14:59:21 -0800 | [diff] [blame] | 985 | #define pmd_mk_savedwrite(pmd) pte_pmd(pte_mk_savedwrite(pmd_pte(pmd))) |
| 986 | #define pmd_clear_savedwrite(pmd) pte_pmd(pte_clear_savedwrite(pmd_pte(pmd))) |
Laurent Dufour | 7207f43 | 2015-12-03 11:29:19 +0100 | [diff] [blame] | 987 | |
| 988 | #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY |
| 989 | #define pmd_soft_dirty(pmd) pte_soft_dirty(pmd_pte(pmd)) |
| 990 | #define pmd_mksoft_dirty(pmd) pte_pmd(pte_mksoft_dirty(pmd_pte(pmd))) |
| 991 | #define pmd_clear_soft_dirty(pmd) pte_pmd(pte_clear_soft_dirty(pmd_pte(pmd))) |
| 992 | #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */ |
| 993 | |
Aneesh Kumar K.V | 1ca7212 | 2015-12-01 09:06:37 +0530 | [diff] [blame] | 994 | #ifdef CONFIG_NUMA_BALANCING |
| 995 | static inline int pmd_protnone(pmd_t pmd) |
| 996 | { |
| 997 | return pte_protnone(pmd_pte(pmd)); |
| 998 | } |
| 999 | #endif /* CONFIG_NUMA_BALANCING */ |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1000 | |
| 1001 | #define __HAVE_ARCH_PMD_WRITE |
| 1002 | #define pmd_write(pmd) pte_write(pmd_pte(pmd)) |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 1003 | #define __pmd_write(pmd) __pte_write(pmd_pte(pmd)) |
Aneesh Kumar K.V | c137a27 | 2017-02-24 14:59:21 -0800 | [diff] [blame] | 1004 | #define pmd_savedwrite(pmd) pte_savedwrite(pmd_pte(pmd)) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1005 | |
Aneesh Kumar K.V | 6a1ea36 | 2016-04-29 23:26:28 +1000 | [diff] [blame] | 1006 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 1007 | extern pmd_t pfn_pmd(unsigned long pfn, pgprot_t pgprot); |
| 1008 | extern pmd_t mk_pmd(struct page *page, pgprot_t pgprot); |
| 1009 | extern pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot); |
| 1010 | extern void set_pmd_at(struct mm_struct *mm, unsigned long addr, |
| 1011 | pmd_t *pmdp, pmd_t pmd); |
| 1012 | extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, |
| 1013 | pmd_t *pmd); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1014 | extern int hash__has_transparent_hugepage(void); |
| 1015 | static inline int has_transparent_hugepage(void) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1016 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1017 | if (radix_enabled()) |
| 1018 | return radix__has_transparent_hugepage(); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1019 | return hash__has_transparent_hugepage(); |
| 1020 | } |
Linus Torvalds | c04a588 | 2016-05-20 10:12:41 -0700 | [diff] [blame] | 1021 | #define has_transparent_hugepage has_transparent_hugepage |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1022 | |
| 1023 | static inline unsigned long |
| 1024 | pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, |
| 1025 | unsigned long clr, unsigned long set) |
| 1026 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1027 | if (radix_enabled()) |
| 1028 | return radix__pmd_hugepage_update(mm, addr, pmdp, clr, set); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1029 | return hash__pmd_hugepage_update(mm, addr, pmdp, clr, set); |
| 1030 | } |
| 1031 | |
| 1032 | static inline int pmd_large(pmd_t pmd) |
| 1033 | { |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 1034 | return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | static inline pmd_t pmd_mknotpresent(pmd_t pmd) |
| 1038 | { |
| 1039 | return __pmd(pmd_val(pmd) & ~_PAGE_PRESENT); |
| 1040 | } |
| 1041 | /* |
| 1042 | * For radix we should always find H_PAGE_HASHPTE zero. Hence |
| 1043 | * the below will work for radix too |
| 1044 | */ |
| 1045 | static inline int __pmdp_test_and_clear_young(struct mm_struct *mm, |
| 1046 | unsigned long addr, pmd_t *pmdp) |
| 1047 | { |
| 1048 | unsigned long old; |
| 1049 | |
Aneesh Kumar K.V | 66c570f | 2016-07-13 15:05:22 +0530 | [diff] [blame] | 1050 | if ((pmd_raw(*pmdp) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0) |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1051 | return 0; |
| 1052 | old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED, 0); |
| 1053 | return ((old & _PAGE_ACCESSED) != 0); |
| 1054 | } |
| 1055 | |
| 1056 | #define __HAVE_ARCH_PMDP_SET_WRPROTECT |
| 1057 | static inline void pmdp_set_wrprotect(struct mm_struct *mm, unsigned long addr, |
| 1058 | pmd_t *pmdp) |
| 1059 | { |
Aneesh Kumar K.V | d19469e | 2017-03-09 16:16:39 -0800 | [diff] [blame] | 1060 | if (__pmd_write((*pmdp))) |
Aneesh Kumar K.V | 52c50ca | 2017-03-09 16:16:36 -0800 | [diff] [blame] | 1061 | pmd_hugepage_update(mm, addr, pmdp, _PAGE_WRITE, 0); |
| 1062 | else if (unlikely(pmd_savedwrite(*pmdp))) |
| 1063 | pmd_hugepage_update(mm, addr, pmdp, 0, _PAGE_PRIVILEGED); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1064 | } |
| 1065 | |
Aneesh Kumar K.V | ab62476 | 2016-04-29 23:26:31 +1000 | [diff] [blame] | 1066 | static inline int pmd_trans_huge(pmd_t pmd) |
| 1067 | { |
| 1068 | if (radix_enabled()) |
| 1069 | return radix__pmd_trans_huge(pmd); |
| 1070 | return hash__pmd_trans_huge(pmd); |
| 1071 | } |
| 1072 | |
| 1073 | #define __HAVE_ARCH_PMD_SAME |
| 1074 | static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b) |
| 1075 | { |
| 1076 | if (radix_enabled()) |
| 1077 | return radix__pmd_same(pmd_a, pmd_b); |
| 1078 | return hash__pmd_same(pmd_a, pmd_b); |
| 1079 | } |
| 1080 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1081 | static inline pmd_t pmd_mkhuge(pmd_t pmd) |
| 1082 | { |
Aneesh Kumar K.V | ab62476 | 2016-04-29 23:26:31 +1000 | [diff] [blame] | 1083 | if (radix_enabled()) |
| 1084 | return radix__pmd_mkhuge(pmd); |
| 1085 | return hash__pmd_mkhuge(pmd); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1086 | } |
| 1087 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1088 | #define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS |
| 1089 | extern int pmdp_set_access_flags(struct vm_area_struct *vma, |
| 1090 | unsigned long address, pmd_t *pmdp, |
| 1091 | pmd_t entry, int dirty); |
| 1092 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1093 | #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG |
| 1094 | extern int pmdp_test_and_clear_young(struct vm_area_struct *vma, |
| 1095 | unsigned long address, pmd_t *pmdp); |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1096 | |
| 1097 | #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1098 | static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, |
| 1099 | unsigned long addr, pmd_t *pmdp) |
| 1100 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1101 | if (radix_enabled()) |
| 1102 | return radix__pmdp_huge_get_and_clear(mm, addr, pmdp); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1103 | return hash__pmdp_huge_get_and_clear(mm, addr, pmdp); |
| 1104 | } |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1105 | |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1106 | static inline pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, |
| 1107 | unsigned long address, pmd_t *pmdp) |
| 1108 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1109 | if (radix_enabled()) |
| 1110 | return radix__pmdp_collapse_flush(vma, address, pmdp); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1111 | return hash__pmdp_collapse_flush(vma, address, pmdp); |
| 1112 | } |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1113 | #define pmdp_collapse_flush pmdp_collapse_flush |
| 1114 | |
| 1115 | #define __HAVE_ARCH_PGTABLE_DEPOSIT |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1116 | static inline void pgtable_trans_huge_deposit(struct mm_struct *mm, |
| 1117 | pmd_t *pmdp, pgtable_t pgtable) |
| 1118 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1119 | if (radix_enabled()) |
| 1120 | return radix__pgtable_trans_huge_deposit(mm, pmdp, pgtable); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1121 | return hash__pgtable_trans_huge_deposit(mm, pmdp, pgtable); |
| 1122 | } |
| 1123 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1124 | #define __HAVE_ARCH_PGTABLE_WITHDRAW |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1125 | static inline pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, |
| 1126 | pmd_t *pmdp) |
| 1127 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1128 | if (radix_enabled()) |
| 1129 | return radix__pgtable_trans_huge_withdraw(mm, pmdp); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1130 | return hash__pgtable_trans_huge_withdraw(mm, pmdp); |
| 1131 | } |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1132 | |
| 1133 | #define __HAVE_ARCH_PMDP_INVALIDATE |
| 1134 | extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, |
| 1135 | pmd_t *pmdp); |
| 1136 | |
Aneesh Kumar K.V | c777e2a | 2016-02-09 06:50:31 +0530 | [diff] [blame] | 1137 | #define __HAVE_ARCH_PMDP_HUGE_SPLIT_PREPARE |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1138 | static inline void pmdp_huge_split_prepare(struct vm_area_struct *vma, |
| 1139 | unsigned long address, pmd_t *pmdp) |
| 1140 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1141 | if (radix_enabled()) |
| 1142 | return radix__pmdp_huge_split_prepare(vma, address, pmdp); |
Aneesh Kumar K.V | 3df33f1 | 2016-04-29 23:26:29 +1000 | [diff] [blame] | 1143 | return hash__pmdp_huge_split_prepare(vma, address, pmdp); |
| 1144 | } |
Aneesh Kumar K.V | c777e2a | 2016-02-09 06:50:31 +0530 | [diff] [blame] | 1145 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1146 | #define pmd_move_must_withdraw pmd_move_must_withdraw |
| 1147 | struct spinlock; |
| 1148 | static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl, |
Aneesh Kumar K.V | 1dd38b6 | 2016-12-12 16:44:29 -0800 | [diff] [blame] | 1149 | struct spinlock *old_pmd_ptl, |
| 1150 | struct vm_area_struct *vma) |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1151 | { |
Aneesh Kumar K.V | bde3eb6 | 2016-04-29 23:26:30 +1000 | [diff] [blame] | 1152 | if (radix_enabled()) |
| 1153 | return false; |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1154 | /* |
| 1155 | * Archs like ppc64 use pgtable to store per pmd |
| 1156 | * specific information. So when we switch the pmd, |
| 1157 | * we should also withdraw and deposit the pgtable |
| 1158 | */ |
| 1159 | return true; |
| 1160 | } |
Aneesh Kumar K.V | 953c66c | 2016-12-12 16:44:32 -0800 | [diff] [blame] | 1161 | |
| 1162 | |
| 1163 | #define arch_needs_pgtable_deposit arch_needs_pgtable_deposit |
| 1164 | static inline bool arch_needs_pgtable_deposit(void) |
| 1165 | { |
| 1166 | if (radix_enabled()) |
| 1167 | return false; |
| 1168 | return true; |
| 1169 | } |
| 1170 | |
Oliver O'Halloran | ebd3119 | 2017-06-28 11:32:34 +1000 | [diff] [blame] | 1171 | |
| 1172 | static inline pmd_t pmd_mkdevmap(pmd_t pmd) |
| 1173 | { |
| 1174 | return __pmd(pmd_val(pmd) | (_PAGE_PTE | _PAGE_DEVMAP)); |
| 1175 | } |
| 1176 | |
| 1177 | static inline int pmd_devmap(pmd_t pmd) |
| 1178 | { |
| 1179 | return pte_devmap(pmd_pte(pmd)); |
| 1180 | } |
| 1181 | |
| 1182 | static inline int pud_devmap(pud_t pud) |
| 1183 | { |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
| 1187 | static inline int pgd_devmap(pgd_t pgd) |
| 1188 | { |
| 1189 | return 0; |
| 1190 | } |
Aneesh Kumar K.V | 6a1ea36 | 2016-04-29 23:26:28 +1000 | [diff] [blame] | 1191 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
Oliver O'Halloran | ebd3119 | 2017-06-28 11:32:34 +1000 | [diff] [blame] | 1192 | |
| 1193 | static inline const int pud_pfn(pud_t pud) |
| 1194 | { |
| 1195 | /* |
| 1196 | * Currently all calls to pud_pfn() are gated around a pud_devmap() |
| 1197 | * check so this should never be used. If it grows another user we |
| 1198 | * want to know about it. |
| 1199 | */ |
| 1200 | BUILD_BUG(); |
| 1201 | return 0; |
| 1202 | } |
Michael Ellerman | 029d925 | 2017-07-14 16:51:23 +1000 | [diff] [blame] | 1203 | |
Aneesh Kumar K.V | 3dfcb315 | 2015-12-01 09:06:28 +0530 | [diff] [blame] | 1204 | #endif /* __ASSEMBLY__ */ |
| 1205 | #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */ |