Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * S390 version |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 3 | * Copyright IBM Corp. 1999, 2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Author(s): Hartmut Penner (hp@de.ibm.com) |
| 5 | * Ulrich Weigand (weigand@de.ibm.com) |
| 6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 7 | * |
| 8 | * Derived from "include/asm-i386/pgtable.h" |
| 9 | */ |
| 10 | |
| 11 | #ifndef _ASM_S390_PGTABLE_H |
| 12 | #define _ASM_S390_PGTABLE_H |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* |
| 15 | * The Linux memory management assumes a three-level page table setup. For |
| 16 | * s390 31 bit we "fold" the mid level into the top-level page table, so |
| 17 | * that we physically have the same two-level page table as the s390 mmu |
| 18 | * expects in 31 bit mode. For s390 64 bit we use three of the five levels |
| 19 | * the hardware provides (region first and region second tables are not |
| 20 | * used). |
| 21 | * |
| 22 | * The "pgd_xxx()" functions are trivial for a folded two-level |
| 23 | * setup: the pgd is never bad, and a pmd always exists (as it's folded |
| 24 | * into the pgd entry) |
| 25 | * |
| 26 | * This file contains the functions and defines necessary to modify and use |
| 27 | * the S390 page table tree. |
| 28 | */ |
| 29 | #ifndef __ASSEMBLY__ |
Heiko Carstens | 9789db0 | 2008-07-14 09:59:11 +0200 | [diff] [blame] | 30 | #include <linux/sched.h> |
Heiko Carstens | 2dcea57 | 2006-09-29 01:58:41 -0700 | [diff] [blame] | 31 | #include <linux/mm_types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/bug.h> |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 33 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096))); |
| 36 | extern void paging_init(void); |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 37 | extern void vmem_map_init(void); |
Martin Schwidefsky | 92f842e | 2010-10-25 16:10:13 +0200 | [diff] [blame] | 38 | extern void fault_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * The S390 doesn't have any external MMU info: the kernel page |
| 42 | * tables contain all the necessary information. |
| 43 | */ |
Russell King | 4b3073e | 2009-12-18 16:40:18 +0000 | [diff] [blame] | 44 | #define update_mmu_cache(vma, address, ptep) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
Martin Schwidefsky | 238ec4e | 2010-10-25 16:10:07 +0200 | [diff] [blame] | 47 | * ZERO_PAGE is a global shared page that is always zero; used |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | * for zero-mapped memory areas etc.. |
| 49 | */ |
Martin Schwidefsky | 238ec4e | 2010-10-25 16:10:07 +0200 | [diff] [blame] | 50 | |
| 51 | extern unsigned long empty_zero_page; |
| 52 | extern unsigned long zero_page_mask; |
| 53 | |
| 54 | #define ZERO_PAGE(vaddr) \ |
| 55 | (virt_to_page((void *)(empty_zero_page + \ |
| 56 | (((unsigned long)(vaddr)) &zero_page_mask)))) |
| 57 | |
| 58 | #define is_zero_pfn is_zero_pfn |
| 59 | static inline int is_zero_pfn(unsigned long pfn) |
| 60 | { |
| 61 | extern unsigned long zero_pfn; |
| 62 | unsigned long offset_from_zero_pfn = pfn - zero_pfn; |
| 63 | return offset_from_zero_pfn <= (zero_page_mask >> PAGE_SHIFT); |
| 64 | } |
| 65 | |
| 66 | #define my_zero_pfn(addr) page_to_pfn(ZERO_PAGE(addr)) |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #endif /* !__ASSEMBLY__ */ |
| 69 | |
| 70 | /* |
| 71 | * PMD_SHIFT determines the size of the area a second-level page |
| 72 | * table can map |
| 73 | * PGDIR_SHIFT determines what a third-level page table entry can map |
| 74 | */ |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 75 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 76 | # define PMD_SHIFT 20 |
| 77 | # define PUD_SHIFT 20 |
| 78 | # define PGDIR_SHIFT 20 |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 79 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 80 | # define PMD_SHIFT 20 |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 81 | # define PUD_SHIFT 31 |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 82 | # define PGDIR_SHIFT 42 |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 83 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | #define PMD_SIZE (1UL << PMD_SHIFT) |
| 86 | #define PMD_MASK (~(PMD_SIZE-1)) |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 87 | #define PUD_SIZE (1UL << PUD_SHIFT) |
| 88 | #define PUD_MASK (~(PUD_SIZE-1)) |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 89 | #define PGDIR_SIZE (1UL << PGDIR_SHIFT) |
| 90 | #define PGDIR_MASK (~(PGDIR_SIZE-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | * entries per page directory level: the S390 is two-level, so |
| 94 | * we don't really have any PMD directory physically. |
| 95 | * for S390 segment-table entries are combined to one PGD |
| 96 | * that leads to 1024 pte per pgd |
| 97 | */ |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 98 | #define PTRS_PER_PTE 256 |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 99 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 100 | #define PTRS_PER_PMD 1 |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 101 | #define PTRS_PER_PUD 1 |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 102 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 103 | #define PTRS_PER_PMD 2048 |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 104 | #define PTRS_PER_PUD 2048 |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 105 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 106 | #define PTRS_PER_PGD 2048 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Hugh Dickins | d455a36 | 2005-04-19 13:29:23 -0700 | [diff] [blame] | 108 | #define FIRST_USER_ADDRESS 0 |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #define pte_ERROR(e) \ |
| 111 | printk("%s:%d: bad pte %p.\n", __FILE__, __LINE__, (void *) pte_val(e)) |
| 112 | #define pmd_ERROR(e) \ |
| 113 | printk("%s:%d: bad pmd %p.\n", __FILE__, __LINE__, (void *) pmd_val(e)) |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 114 | #define pud_ERROR(e) \ |
| 115 | printk("%s:%d: bad pud %p.\n", __FILE__, __LINE__, (void *) pud_val(e)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #define pgd_ERROR(e) \ |
| 117 | printk("%s:%d: bad pgd %p.\n", __FILE__, __LINE__, (void *) pgd_val(e)) |
| 118 | |
| 119 | #ifndef __ASSEMBLY__ |
| 120 | /* |
Christian Borntraeger | 5fd9c6e | 2008-01-26 14:11:00 +0100 | [diff] [blame] | 121 | * The vmalloc area will always be on the topmost area of the kernel |
Martin Schwidefsky | 7d3f661 | 2010-04-09 13:43:02 +0200 | [diff] [blame] | 122 | * mapping. We reserve 96MB (31bit) / 128GB (64bit) for vmalloc, |
Christian Borntraeger | 5fd9c6e | 2008-01-26 14:11:00 +0100 | [diff] [blame] | 123 | * which should be enough for any sane case. |
| 124 | * By putting vmalloc at the top, we maximise the gap between physical |
| 125 | * memory and vmalloc to catch misplaced memory accesses. As a side |
| 126 | * effect, this also makes sure that 64 bit module code cannot be used |
| 127 | * as system call address. |
Heiko Carstens | 8b62bc9 | 2006-12-04 15:40:56 +0100 | [diff] [blame] | 128 | */ |
Heiko Carstens | 239a6425 | 2009-06-12 10:26:33 +0200 | [diff] [blame] | 129 | extern unsigned long VMALLOC_START; |
Martin Schwidefsky | 14045eb | 2011-12-27 11:27:07 +0100 | [diff] [blame] | 130 | extern unsigned long VMALLOC_END; |
| 131 | extern struct page *vmemmap; |
Heiko Carstens | 239a6425 | 2009-06-12 10:26:33 +0200 | [diff] [blame] | 132 | |
Martin Schwidefsky | 14045eb | 2011-12-27 11:27:07 +0100 | [diff] [blame] | 133 | #define VMEM_MAX_PHYS ((unsigned long) vmemmap) |
Christian Borntraeger | 5fd9c6e | 2008-01-26 14:11:00 +0100 | [diff] [blame] | 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /* |
| 136 | * A 31 bit pagetable entry of S390 has following format: |
| 137 | * | PFRA | | OS | |
| 138 | * 0 0IP0 |
| 139 | * 00000000001111111111222222222233 |
| 140 | * 01234567890123456789012345678901 |
| 141 | * |
| 142 | * I Page-Invalid Bit: Page is not available for address-translation |
| 143 | * P Page-Protection Bit: Store access not possible for page |
| 144 | * |
| 145 | * A 31 bit segmenttable entry of S390 has following format: |
| 146 | * | P-table origin | |PTL |
| 147 | * 0 IC |
| 148 | * 00000000001111111111222222222233 |
| 149 | * 01234567890123456789012345678901 |
| 150 | * |
| 151 | * I Segment-Invalid Bit: Segment is not available for address-translation |
| 152 | * C Common-Segment Bit: Segment is not private (PoP 3-30) |
| 153 | * PTL Page-Table-Length: Page-table length (PTL+1*16 entries -> up to 256) |
| 154 | * |
| 155 | * The 31 bit segmenttable origin of S390 has following format: |
| 156 | * |
| 157 | * |S-table origin | | STL | |
| 158 | * X **GPS |
| 159 | * 00000000001111111111222222222233 |
| 160 | * 01234567890123456789012345678901 |
| 161 | * |
| 162 | * X Space-Switch event: |
| 163 | * G Segment-Invalid Bit: * |
| 164 | * P Private-Space Bit: Segment is not private (PoP 3-30) |
| 165 | * S Storage-Alteration: |
| 166 | * STL Segment-Table-Length: Segment-table length (STL+1*16 entries -> up to 2048) |
| 167 | * |
| 168 | * A 64 bit pagetable entry of S390 has following format: |
Christian Borntraeger | 6a985c6 | 2009-12-07 12:52:11 +0100 | [diff] [blame] | 169 | * | PFRA |0IPC| OS | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | * 0000000000111111111122222222223333333333444444444455555555556666 |
| 171 | * 0123456789012345678901234567890123456789012345678901234567890123 |
| 172 | * |
| 173 | * I Page-Invalid Bit: Page is not available for address-translation |
| 174 | * P Page-Protection Bit: Store access not possible for page |
Christian Borntraeger | 6a985c6 | 2009-12-07 12:52:11 +0100 | [diff] [blame] | 175 | * C Change-bit override: HW is not required to set change bit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | * |
| 177 | * A 64 bit segmenttable entry of S390 has following format: |
| 178 | * | P-table origin | TT |
| 179 | * 0000000000111111111122222222223333333333444444444455555555556666 |
| 180 | * 0123456789012345678901234567890123456789012345678901234567890123 |
| 181 | * |
| 182 | * I Segment-Invalid Bit: Segment is not available for address-translation |
| 183 | * C Common-Segment Bit: Segment is not private (PoP 3-30) |
| 184 | * P Page-Protection Bit: Store access not possible for page |
| 185 | * TT Type 00 |
| 186 | * |
| 187 | * A 64 bit region table entry of S390 has following format: |
| 188 | * | S-table origin | TF TTTL |
| 189 | * 0000000000111111111122222222223333333333444444444455555555556666 |
| 190 | * 0123456789012345678901234567890123456789012345678901234567890123 |
| 191 | * |
| 192 | * I Segment-Invalid Bit: Segment is not available for address-translation |
| 193 | * TT Type 01 |
| 194 | * TF |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 195 | * TL Table length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * |
| 197 | * The 64 bit regiontable origin of S390 has following format: |
| 198 | * | region table origon | DTTL |
| 199 | * 0000000000111111111122222222223333333333444444444455555555556666 |
| 200 | * 0123456789012345678901234567890123456789012345678901234567890123 |
| 201 | * |
| 202 | * X Space-Switch event: |
| 203 | * G Segment-Invalid Bit: |
| 204 | * P Private-Space Bit: |
| 205 | * S Storage-Alteration: |
| 206 | * R Real space |
| 207 | * TL Table-Length: |
| 208 | * |
| 209 | * A storage key has the following format: |
| 210 | * | ACC |F|R|C|0| |
| 211 | * 0 3 4 5 6 7 |
| 212 | * ACC: access key |
| 213 | * F : fetch protection bit |
| 214 | * R : referenced bit |
| 215 | * C : changed bit |
| 216 | */ |
| 217 | |
| 218 | /* Hardware bits in the page table entry */ |
Christian Borntraeger | 6a985c6 | 2009-12-07 12:52:11 +0100 | [diff] [blame] | 219 | #define _PAGE_CO 0x100 /* HW Change-bit override */ |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 220 | #define _PAGE_RO 0x200 /* HW read-only bit */ |
| 221 | #define _PAGE_INVALID 0x400 /* HW invalid bit */ |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 222 | |
| 223 | /* Software bits in the page table entry */ |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 224 | #define _PAGE_SWT 0x001 /* SW pte type bit t */ |
| 225 | #define _PAGE_SWX 0x002 /* SW pte type bit x */ |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 226 | #define _PAGE_SWC 0x004 /* SW pte changed bit (for KVM) */ |
| 227 | #define _PAGE_SWR 0x008 /* SW pte referenced bit (for KVM) */ |
| 228 | #define _PAGE_SPECIAL 0x010 /* SW associated with special page */ |
Nick Piggin | a08cb62 | 2008-04-28 02:13:03 -0700 | [diff] [blame] | 229 | #define __HAVE_ARCH_PTE_SPECIAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Nick Piggin | 138c902 | 2008-07-08 11:31:06 +0200 | [diff] [blame] | 231 | /* Set of bits not changed in pte_modify */ |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 232 | #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL | _PAGE_SWC | _PAGE_SWR) |
Nick Piggin | 138c902 | 2008-07-08 11:31:06 +0200 | [diff] [blame] | 233 | |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 234 | /* Six different types of pages. */ |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 235 | #define _PAGE_TYPE_EMPTY 0x400 |
| 236 | #define _PAGE_TYPE_NONE 0x401 |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 237 | #define _PAGE_TYPE_SWAP 0x403 |
| 238 | #define _PAGE_TYPE_FILE 0x601 /* bit 0x002 is used for offset !! */ |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 239 | #define _PAGE_TYPE_RO 0x200 |
| 240 | #define _PAGE_TYPE_RW 0x000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 242 | /* |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 243 | * Only four types for huge pages, using the invalid bit and protection bit |
| 244 | * of a segment table entry. |
| 245 | */ |
| 246 | #define _HPAGE_TYPE_EMPTY 0x020 /* _SEGMENT_ENTRY_INV */ |
| 247 | #define _HPAGE_TYPE_NONE 0x220 |
| 248 | #define _HPAGE_TYPE_RO 0x200 /* _SEGMENT_ENTRY_RO */ |
| 249 | #define _HPAGE_TYPE_RW 0x000 |
| 250 | |
| 251 | /* |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 252 | * PTE type bits are rather complicated. handle_pte_fault uses pte_present, |
| 253 | * pte_none and pte_file to find out the pte type WITHOUT holding the page |
| 254 | * table lock. ptep_clear_flush on the other hand uses ptep_clear_flush to |
| 255 | * invalidate a given pte. ipte sets the hw invalid bit and clears all tlbs |
| 256 | * for the page. The page table entry is set to _PAGE_TYPE_EMPTY afterwards. |
| 257 | * This change is done while holding the lock, but the intermediate step |
| 258 | * of a previously valid pte with the hw invalid bit set can be observed by |
| 259 | * handle_pte_fault. That makes it necessary that all valid pte types with |
| 260 | * the hw invalid bit set must be distinguishable from the four pte types |
| 261 | * empty, none, swap and file. |
| 262 | * |
| 263 | * irxt ipte irxt |
| 264 | * _PAGE_TYPE_EMPTY 1000 -> 1000 |
| 265 | * _PAGE_TYPE_NONE 1001 -> 1001 |
| 266 | * _PAGE_TYPE_SWAP 1011 -> 1011 |
| 267 | * _PAGE_TYPE_FILE 11?1 -> 11?1 |
| 268 | * _PAGE_TYPE_RO 0100 -> 1100 |
| 269 | * _PAGE_TYPE_RW 0000 -> 1000 |
| 270 | * |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 271 | * pte_none is true for bits combinations 1000, 1010, 1100, 1110 |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 272 | * pte_present is true for bits combinations 0000, 0010, 0100, 0110, 1001 |
| 273 | * pte_file is true for bits combinations 1101, 1111 |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 274 | * swap pte is 1011 and 0001, 0011, 0101, 0111 are invalid. |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 275 | */ |
| 276 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 277 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 279 | /* Bits in the segment table address-space-control-element */ |
| 280 | #define _ASCE_SPACE_SWITCH 0x80000000UL /* space switch event */ |
| 281 | #define _ASCE_ORIGIN_MASK 0x7ffff000UL /* segment table origin */ |
| 282 | #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */ |
| 283 | #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */ |
| 284 | #define _ASCE_TABLE_LENGTH 0x7f /* 128 x 64 entries = 8k */ |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | /* Bits in the segment table entry */ |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 287 | #define _SEGMENT_ENTRY_ORIGIN 0x7fffffc0UL /* page table origin */ |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 288 | #define _SEGMENT_ENTRY_RO 0x200 /* page protection bit */ |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 289 | #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */ |
| 290 | #define _SEGMENT_ENTRY_COMMON 0x10 /* common segment bit */ |
| 291 | #define _SEGMENT_ENTRY_PTL 0x0f /* page table length */ |
| 292 | |
| 293 | #define _SEGMENT_ENTRY (_SEGMENT_ENTRY_PTL) |
| 294 | #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV) |
| 295 | |
Martin Schwidefsky | 6c61cfe | 2011-06-06 14:14:42 +0200 | [diff] [blame] | 296 | /* Page status table bits for virtualization */ |
| 297 | #define RCP_ACC_BITS 0xf0000000UL |
| 298 | #define RCP_FP_BIT 0x08000000UL |
| 299 | #define RCP_PCL_BIT 0x00800000UL |
| 300 | #define RCP_HR_BIT 0x00400000UL |
| 301 | #define RCP_HC_BIT 0x00200000UL |
| 302 | #define RCP_GR_BIT 0x00040000UL |
| 303 | #define RCP_GC_BIT 0x00020000UL |
| 304 | |
| 305 | /* User dirty / referenced bit for KVM's migration feature */ |
| 306 | #define KVM_UR_BIT 0x00008000UL |
| 307 | #define KVM_UC_BIT 0x00004000UL |
| 308 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 309 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 310 | |
| 311 | /* Bits in the segment/region table address-space-control-element */ |
| 312 | #define _ASCE_ORIGIN ~0xfffUL/* segment table origin */ |
| 313 | #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */ |
| 314 | #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */ |
| 315 | #define _ASCE_SPACE_SWITCH 0x40 /* space switch event */ |
| 316 | #define _ASCE_REAL_SPACE 0x20 /* real space control */ |
| 317 | #define _ASCE_TYPE_MASK 0x0c /* asce table type mask */ |
| 318 | #define _ASCE_TYPE_REGION1 0x0c /* region first table type */ |
| 319 | #define _ASCE_TYPE_REGION2 0x08 /* region second table type */ |
| 320 | #define _ASCE_TYPE_REGION3 0x04 /* region third table type */ |
| 321 | #define _ASCE_TYPE_SEGMENT 0x00 /* segment table type */ |
| 322 | #define _ASCE_TABLE_LENGTH 0x03 /* region table length */ |
| 323 | |
| 324 | /* Bits in the region table entry */ |
| 325 | #define _REGION_ENTRY_ORIGIN ~0xfffUL/* region/segment table origin */ |
| 326 | #define _REGION_ENTRY_INV 0x20 /* invalid region table entry */ |
| 327 | #define _REGION_ENTRY_TYPE_MASK 0x0c /* region/segment table type mask */ |
| 328 | #define _REGION_ENTRY_TYPE_R1 0x0c /* region first table type */ |
| 329 | #define _REGION_ENTRY_TYPE_R2 0x08 /* region second table type */ |
| 330 | #define _REGION_ENTRY_TYPE_R3 0x04 /* region third table type */ |
| 331 | #define _REGION_ENTRY_LENGTH 0x03 /* region third length */ |
| 332 | |
| 333 | #define _REGION1_ENTRY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_LENGTH) |
| 334 | #define _REGION1_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_INV) |
| 335 | #define _REGION2_ENTRY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_LENGTH) |
| 336 | #define _REGION2_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_INV) |
| 337 | #define _REGION3_ENTRY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_LENGTH) |
| 338 | #define _REGION3_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INV) |
| 339 | |
| 340 | /* Bits in the segment table entry */ |
| 341 | #define _SEGMENT_ENTRY_ORIGIN ~0x7ffUL/* segment table origin */ |
| 342 | #define _SEGMENT_ENTRY_RO 0x200 /* page protection bit */ |
| 343 | #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */ |
| 344 | |
| 345 | #define _SEGMENT_ENTRY (0) |
| 346 | #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV) |
| 347 | |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 348 | #define _SEGMENT_ENTRY_LARGE 0x400 /* STE-format control, large page */ |
| 349 | #define _SEGMENT_ENTRY_CO 0x100 /* change-recording override */ |
Gerald Schaefer | 75077af | 2012-10-08 16:30:15 -0700 | [diff] [blame^] | 350 | #define _SEGMENT_ENTRY_SPLIT_BIT 0 /* THP splitting bit number */ |
| 351 | #define _SEGMENT_ENTRY_SPLIT (1UL << _SEGMENT_ENTRY_SPLIT_BIT) |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 352 | |
Martin Schwidefsky | 6c61cfe | 2011-06-06 14:14:42 +0200 | [diff] [blame] | 353 | /* Page status table bits for virtualization */ |
| 354 | #define RCP_ACC_BITS 0xf000000000000000UL |
| 355 | #define RCP_FP_BIT 0x0800000000000000UL |
| 356 | #define RCP_PCL_BIT 0x0080000000000000UL |
| 357 | #define RCP_HR_BIT 0x0040000000000000UL |
| 358 | #define RCP_HC_BIT 0x0020000000000000UL |
| 359 | #define RCP_GR_BIT 0x0004000000000000UL |
| 360 | #define RCP_GC_BIT 0x0002000000000000UL |
| 361 | |
| 362 | /* User dirty / referenced bit for KVM's migration feature */ |
| 363 | #define KVM_UR_BIT 0x0000800000000000UL |
| 364 | #define KVM_UC_BIT 0x0000400000000000UL |
| 365 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 366 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * A user page table pointer has the space-switch-event bit, the |
| 370 | * private-space-control bit and the storage-alteration-event-control |
| 371 | * bit set. A kernel page table pointer doesn't need them. |
| 372 | */ |
| 373 | #define _ASCE_USER_BITS (_ASCE_SPACE_SWITCH | _ASCE_PRIVATE_SPACE | \ |
| 374 | _ASCE_ALT_EVENT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | /* |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 377 | * Page protection definitions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | */ |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 379 | #define PAGE_NONE __pgprot(_PAGE_TYPE_NONE) |
| 380 | #define PAGE_RO __pgprot(_PAGE_TYPE_RO) |
| 381 | #define PAGE_RW __pgprot(_PAGE_TYPE_RW) |
| 382 | |
| 383 | #define PAGE_KERNEL PAGE_RW |
| 384 | #define PAGE_COPY PAGE_RO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | /* |
Martin Schwidefsky | 043d070 | 2011-05-23 10:24:23 +0200 | [diff] [blame] | 387 | * On s390 the page table entry has an invalid bit and a read-only bit. |
| 388 | * Read permission implies execute permission and write permission |
| 389 | * implies read permission. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | */ |
| 391 | /*xwr*/ |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 392 | #define __P000 PAGE_NONE |
| 393 | #define __P001 PAGE_RO |
| 394 | #define __P010 PAGE_RO |
| 395 | #define __P011 PAGE_RO |
Martin Schwidefsky | 043d070 | 2011-05-23 10:24:23 +0200 | [diff] [blame] | 396 | #define __P100 PAGE_RO |
| 397 | #define __P101 PAGE_RO |
| 398 | #define __P110 PAGE_RO |
| 399 | #define __P111 PAGE_RO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 401 | #define __S000 PAGE_NONE |
| 402 | #define __S001 PAGE_RO |
| 403 | #define __S010 PAGE_RW |
| 404 | #define __S011 PAGE_RW |
Martin Schwidefsky | 043d070 | 2011-05-23 10:24:23 +0200 | [diff] [blame] | 405 | #define __S100 PAGE_RO |
| 406 | #define __S101 PAGE_RO |
| 407 | #define __S110 PAGE_RW |
| 408 | #define __S111 PAGE_RW |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 410 | static inline int mm_exclusive(struct mm_struct *mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 412 | return likely(mm == current->active_mm && |
| 413 | atomic_read(&mm->context.attach_count) <= 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 416 | static inline int mm_has_pgste(struct mm_struct *mm) |
| 417 | { |
| 418 | #ifdef CONFIG_PGSTE |
| 419 | if (unlikely(mm->context.has_pgste)) |
| 420 | return 1; |
| 421 | #endif |
| 422 | return 0; |
| 423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /* |
| 425 | * pgd/pmd/pte query functions |
| 426 | */ |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 427 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 429 | static inline int pgd_present(pgd_t pgd) { return 1; } |
| 430 | static inline int pgd_none(pgd_t pgd) { return 0; } |
| 431 | static inline int pgd_bad(pgd_t pgd) { return 0; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 433 | static inline int pud_present(pud_t pud) { return 1; } |
| 434 | static inline int pud_none(pud_t pud) { return 0; } |
| 435 | static inline int pud_bad(pud_t pud) { return 0; } |
| 436 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 437 | #else /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 439 | static inline int pgd_present(pgd_t pgd) |
| 440 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 441 | if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2) |
| 442 | return 1; |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 443 | return (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) != 0UL; |
| 444 | } |
| 445 | |
| 446 | static inline int pgd_none(pgd_t pgd) |
| 447 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 448 | if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2) |
| 449 | return 0; |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 450 | return (pgd_val(pgd) & _REGION_ENTRY_INV) != 0UL; |
| 451 | } |
| 452 | |
| 453 | static inline int pgd_bad(pgd_t pgd) |
| 454 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 455 | /* |
| 456 | * With dynamic page table levels the pgd can be a region table |
| 457 | * entry or a segment table entry. Check for the bit that are |
| 458 | * invalid for either table entry. |
| 459 | */ |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 460 | unsigned long mask = |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 461 | ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INV & |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 462 | ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH; |
| 463 | return (pgd_val(pgd) & mask) != 0; |
| 464 | } |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 465 | |
| 466 | static inline int pud_present(pud_t pud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 468 | if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3) |
| 469 | return 1; |
Martin Schwidefsky | 0d01792 | 2007-12-17 16:25:48 +0100 | [diff] [blame] | 470 | return (pud_val(pud) & _REGION_ENTRY_ORIGIN) != 0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 473 | static inline int pud_none(pud_t pud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 475 | if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3) |
| 476 | return 0; |
Martin Schwidefsky | 0d01792 | 2007-12-17 16:25:48 +0100 | [diff] [blame] | 477 | return (pud_val(pud) & _REGION_ENTRY_INV) != 0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 480 | static inline int pud_bad(pud_t pud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 482 | /* |
| 483 | * With dynamic page table levels the pud can be a region table |
| 484 | * entry or a segment table entry. Check for the bit that are |
| 485 | * invalid for either table entry. |
| 486 | */ |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 487 | unsigned long mask = |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 488 | ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INV & |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 489 | ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH; |
| 490 | return (pud_val(pud) & mask) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 493 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 494 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 495 | static inline int pmd_present(pmd_t pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
Martin Schwidefsky | 0d01792 | 2007-12-17 16:25:48 +0100 | [diff] [blame] | 497 | return (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN) != 0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 500 | static inline int pmd_none(pmd_t pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | { |
Martin Schwidefsky | 0d01792 | 2007-12-17 16:25:48 +0100 | [diff] [blame] | 502 | return (pmd_val(pmd) & _SEGMENT_ENTRY_INV) != 0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 505 | static inline int pmd_bad(pmd_t pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | { |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 507 | unsigned long mask = ~_SEGMENT_ENTRY_ORIGIN & ~_SEGMENT_ENTRY_INV; |
| 508 | return (pmd_val(pmd) & mask) != _SEGMENT_ENTRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Gerald Schaefer | 75077af | 2012-10-08 16:30:15 -0700 | [diff] [blame^] | 511 | #define __HAVE_ARCH_PMDP_SPLITTING_FLUSH |
| 512 | extern void pmdp_splitting_flush(struct vm_area_struct *vma, |
| 513 | unsigned long addr, pmd_t *pmdp); |
| 514 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 515 | static inline int pte_none(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 517 | return (pte_val(pte) & _PAGE_INVALID) && !(pte_val(pte) & _PAGE_SWT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 520 | static inline int pte_present(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 522 | unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT | _PAGE_SWX; |
| 523 | return (pte_val(pte) & mask) == _PAGE_TYPE_NONE || |
| 524 | (!(pte_val(pte) & _PAGE_INVALID) && |
| 525 | !(pte_val(pte) & _PAGE_SWT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 528 | static inline int pte_file(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | { |
Martin Schwidefsky | 8337748 | 2006-10-18 18:30:51 +0200 | [diff] [blame] | 530 | unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT; |
| 531 | return (pte_val(pte) & mask) == _PAGE_TYPE_FILE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Nick Piggin | 7e67513 | 2008-04-28 02:13:00 -0700 | [diff] [blame] | 534 | static inline int pte_special(pte_t pte) |
| 535 | { |
Nick Piggin | a08cb62 | 2008-04-28 02:13:03 -0700 | [diff] [blame] | 536 | return (pte_val(pte) & _PAGE_SPECIAL); |
Nick Piggin | 7e67513 | 2008-04-28 02:13:00 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 539 | #define __HAVE_ARCH_PTE_SAME |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 540 | static inline int pte_same(pte_t a, pte_t b) |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 541 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 542 | return pte_val(a) == pte_val(b); |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 545 | static inline pgste_t pgste_get_lock(pte_t *ptep) |
| 546 | { |
| 547 | unsigned long new = 0; |
| 548 | #ifdef CONFIG_PGSTE |
| 549 | unsigned long old; |
| 550 | |
| 551 | preempt_disable(); |
| 552 | asm( |
| 553 | " lg %0,%2\n" |
| 554 | "0: lgr %1,%0\n" |
| 555 | " nihh %0,0xff7f\n" /* clear RCP_PCL_BIT in old */ |
| 556 | " oihh %1,0x0080\n" /* set RCP_PCL_BIT in new */ |
| 557 | " csg %0,%1,%2\n" |
| 558 | " jl 0b\n" |
| 559 | : "=&d" (old), "=&d" (new), "=Q" (ptep[PTRS_PER_PTE]) |
| 560 | : "Q" (ptep[PTRS_PER_PTE]) : "cc"); |
| 561 | #endif |
| 562 | return __pgste(new); |
| 563 | } |
| 564 | |
| 565 | static inline void pgste_set_unlock(pte_t *ptep, pgste_t pgste) |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 566 | { |
| 567 | #ifdef CONFIG_PGSTE |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 568 | asm( |
| 569 | " nihh %1,0xff7f\n" /* clear RCP_PCL_BIT */ |
| 570 | " stg %1,%0\n" |
| 571 | : "=Q" (ptep[PTRS_PER_PTE]) |
| 572 | : "d" (pgste_val(pgste)), "Q" (ptep[PTRS_PER_PTE]) : "cc"); |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 573 | preempt_enable(); |
| 574 | #endif |
| 575 | } |
| 576 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 577 | static inline pgste_t pgste_update_all(pte_t *ptep, pgste_t pgste) |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 578 | { |
| 579 | #ifdef CONFIG_PGSTE |
Heiko Carstens | a43a9d9 | 2011-05-29 12:40:50 +0200 | [diff] [blame] | 580 | unsigned long address, bits; |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 581 | unsigned char skey; |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 582 | |
Martin Schwidefsky | 09b5388 | 2011-11-14 11:19:00 +0100 | [diff] [blame] | 583 | if (!pte_present(*ptep)) |
| 584 | return pgste; |
Heiko Carstens | a43a9d9 | 2011-05-29 12:40:50 +0200 | [diff] [blame] | 585 | address = pte_val(*ptep) & PAGE_MASK; |
| 586 | skey = page_get_storage_key(address); |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 587 | bits = skey & (_PAGE_CHANGED | _PAGE_REFERENCED); |
| 588 | /* Clear page changed & referenced bit in the storage key */ |
Carsten Otte | 7c81878 | 2011-12-01 13:32:16 +0100 | [diff] [blame] | 589 | if (bits & _PAGE_CHANGED) |
| 590 | page_set_storage_key(address, skey ^ bits, 1); |
| 591 | else if (bits) |
| 592 | page_reset_referenced(address); |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 593 | /* Transfer page changed & referenced bit to guest bits in pgste */ |
| 594 | pgste_val(pgste) |= bits << 48; /* RCP_GR_BIT & RCP_GC_BIT */ |
| 595 | /* Get host changed & referenced bits from pgste */ |
| 596 | bits |= (pgste_val(pgste) & (RCP_HR_BIT | RCP_HC_BIT)) >> 52; |
| 597 | /* Clear host bits in pgste. */ |
| 598 | pgste_val(pgste) &= ~(RCP_HR_BIT | RCP_HC_BIT); |
| 599 | pgste_val(pgste) &= ~(RCP_ACC_BITS | RCP_FP_BIT); |
| 600 | /* Copy page access key and fetch protection bit to pgste */ |
| 601 | pgste_val(pgste) |= |
| 602 | (unsigned long) (skey & (_PAGE_ACC_BITS | _PAGE_FP_BIT)) << 56; |
| 603 | /* Transfer changed and referenced to kvm user bits */ |
| 604 | pgste_val(pgste) |= bits << 45; /* KVM_UR_BIT & KVM_UC_BIT */ |
| 605 | /* Transfer changed & referenced to pte sofware bits */ |
| 606 | pte_val(*ptep) |= bits << 1; /* _PAGE_SWR & _PAGE_SWC */ |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 607 | #endif |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 608 | return pgste; |
| 609 | |
| 610 | } |
| 611 | |
| 612 | static inline pgste_t pgste_update_young(pte_t *ptep, pgste_t pgste) |
| 613 | { |
| 614 | #ifdef CONFIG_PGSTE |
| 615 | int young; |
| 616 | |
Martin Schwidefsky | 09b5388 | 2011-11-14 11:19:00 +0100 | [diff] [blame] | 617 | if (!pte_present(*ptep)) |
| 618 | return pgste; |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 619 | young = page_reset_referenced(pte_val(*ptep) & PAGE_MASK); |
| 620 | /* Transfer page referenced bit to pte software bit (host view) */ |
| 621 | if (young || (pgste_val(pgste) & RCP_HR_BIT)) |
| 622 | pte_val(*ptep) |= _PAGE_SWR; |
| 623 | /* Clear host referenced bit in pgste. */ |
| 624 | pgste_val(pgste) &= ~RCP_HR_BIT; |
| 625 | /* Transfer page referenced bit to guest bit in pgste */ |
| 626 | pgste_val(pgste) |= (unsigned long) young << 50; /* set RCP_GR_BIT */ |
| 627 | #endif |
| 628 | return pgste; |
| 629 | |
| 630 | } |
| 631 | |
Martin Schwidefsky | 09b5388 | 2011-11-14 11:19:00 +0100 | [diff] [blame] | 632 | static inline void pgste_set_pte(pte_t *ptep, pgste_t pgste, pte_t entry) |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 633 | { |
| 634 | #ifdef CONFIG_PGSTE |
Heiko Carstens | a43a9d9 | 2011-05-29 12:40:50 +0200 | [diff] [blame] | 635 | unsigned long address; |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 636 | unsigned long okey, nkey; |
| 637 | |
Martin Schwidefsky | 09b5388 | 2011-11-14 11:19:00 +0100 | [diff] [blame] | 638 | if (!pte_present(entry)) |
| 639 | return; |
| 640 | address = pte_val(entry) & PAGE_MASK; |
Heiko Carstens | a43a9d9 | 2011-05-29 12:40:50 +0200 | [diff] [blame] | 641 | okey = nkey = page_get_storage_key(address); |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 642 | nkey &= ~(_PAGE_ACC_BITS | _PAGE_FP_BIT); |
| 643 | /* Set page access key and fetch protection bit from pgste */ |
| 644 | nkey |= (pgste_val(pgste) & (RCP_ACC_BITS | RCP_FP_BIT)) >> 56; |
| 645 | if (okey != nkey) |
Heiko Carstens | a43a9d9 | 2011-05-29 12:40:50 +0200 | [diff] [blame] | 646 | page_set_storage_key(address, nkey, 1); |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 647 | #endif |
| 648 | } |
| 649 | |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 650 | /** |
| 651 | * struct gmap_struct - guest address space |
| 652 | * @mm: pointer to the parent mm_struct |
| 653 | * @table: pointer to the page directory |
Christian Borntraeger | 480e592 | 2011-09-20 17:07:28 +0200 | [diff] [blame] | 654 | * @asce: address space control element for gmap page table |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 655 | * @crst_list: list of all crst tables used in the guest address space |
| 656 | */ |
| 657 | struct gmap { |
| 658 | struct list_head list; |
| 659 | struct mm_struct *mm; |
| 660 | unsigned long *table; |
Christian Borntraeger | 480e592 | 2011-09-20 17:07:28 +0200 | [diff] [blame] | 661 | unsigned long asce; |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 662 | struct list_head crst_list; |
| 663 | }; |
| 664 | |
| 665 | /** |
| 666 | * struct gmap_rmap - reverse mapping for segment table entries |
| 667 | * @next: pointer to the next gmap_rmap structure in the list |
| 668 | * @entry: pointer to a segment table entry |
| 669 | */ |
| 670 | struct gmap_rmap { |
| 671 | struct list_head list; |
| 672 | unsigned long *entry; |
| 673 | }; |
| 674 | |
| 675 | /** |
| 676 | * struct gmap_pgtable - gmap information attached to a page table |
| 677 | * @vmaddr: address of the 1MB segment in the process virtual memory |
| 678 | * @mapper: list of segment table entries maping a page table |
| 679 | */ |
| 680 | struct gmap_pgtable { |
| 681 | unsigned long vmaddr; |
| 682 | struct list_head mapper; |
| 683 | }; |
| 684 | |
| 685 | struct gmap *gmap_alloc(struct mm_struct *mm); |
| 686 | void gmap_free(struct gmap *gmap); |
| 687 | void gmap_enable(struct gmap *gmap); |
| 688 | void gmap_disable(struct gmap *gmap); |
| 689 | int gmap_map_segment(struct gmap *gmap, unsigned long from, |
| 690 | unsigned long to, unsigned long length); |
| 691 | int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len); |
Carsten Otte | 499069e | 2011-10-30 15:17:02 +0100 | [diff] [blame] | 692 | unsigned long __gmap_fault(unsigned long address, struct gmap *); |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 693 | unsigned long gmap_fault(unsigned long address, struct gmap *); |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 694 | void gmap_discard(unsigned long from, unsigned long to, struct gmap *); |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 695 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 696 | /* |
| 697 | * Certain architectures need to do special things when PTEs |
| 698 | * within a page table are directly modified. Thus, the following |
| 699 | * hook is made available. |
| 700 | */ |
| 701 | static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 702 | pte_t *ptep, pte_t entry) |
| 703 | { |
| 704 | pgste_t pgste; |
| 705 | |
| 706 | if (mm_has_pgste(mm)) { |
| 707 | pgste = pgste_get_lock(ptep); |
Martin Schwidefsky | 09b5388 | 2011-11-14 11:19:00 +0100 | [diff] [blame] | 708 | pgste_set_pte(ptep, pgste, entry); |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 709 | *ptep = entry; |
| 710 | pgste_set_unlock(ptep, pgste); |
| 711 | } else |
| 712 | *ptep = entry; |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 713 | } |
| 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | /* |
| 716 | * query functions pte_write/pte_dirty/pte_young only work if |
| 717 | * pte_present() is true. Undefined behaviour if not.. |
| 718 | */ |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 719 | static inline int pte_write(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { |
| 721 | return (pte_val(pte) & _PAGE_RO) == 0; |
| 722 | } |
| 723 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 724 | static inline int pte_dirty(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 726 | #ifdef CONFIG_PGSTE |
| 727 | if (pte_val(pte) & _PAGE_SWC) |
| 728 | return 1; |
| 729 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | return 0; |
| 731 | } |
| 732 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 733 | static inline int pte_young(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 735 | #ifdef CONFIG_PGSTE |
| 736 | if (pte_val(pte) & _PAGE_SWR) |
| 737 | return 1; |
| 738 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | return 0; |
| 740 | } |
| 741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | /* |
| 743 | * pgd/pmd/pte modification functions |
| 744 | */ |
| 745 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 746 | static inline void pgd_clear(pgd_t *pgd) |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 747 | { |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 748 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 749 | if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2) |
| 750 | pgd_val(*pgd) = _REGION2_ENTRY_EMPTY; |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 751 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 754 | static inline void pud_clear(pud_t *pud) |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 755 | { |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 756 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 757 | if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) |
| 758 | pud_val(*pud) = _REGION3_ENTRY_EMPTY; |
| 759 | #endif |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 760 | } |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 761 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 762 | static inline void pmd_clear(pmd_t *pmdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 764 | pmd_val(*pmdp) = _SEGMENT_ENTRY_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 767 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 769 | pte_val(*ptep) = _PAGE_TYPE_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* |
| 773 | * The following pte modification functions only work if |
| 774 | * pte_present() is true. Undefined behaviour if not.. |
| 775 | */ |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 776 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Nick Piggin | 138c902 | 2008-07-08 11:31:06 +0200 | [diff] [blame] | 778 | pte_val(pte) &= _PAGE_CHG_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | pte_val(pte) |= pgprot_val(newprot); |
| 780 | return pte; |
| 781 | } |
| 782 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 783 | static inline pte_t pte_wrprotect(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 785 | /* Do not clobber _PAGE_TYPE_NONE pages! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | if (!(pte_val(pte) & _PAGE_INVALID)) |
| 787 | pte_val(pte) |= _PAGE_RO; |
| 788 | return pte; |
| 789 | } |
| 790 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 791 | static inline pte_t pte_mkwrite(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | { |
| 793 | pte_val(pte) &= ~_PAGE_RO; |
| 794 | return pte; |
| 795 | } |
| 796 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 797 | static inline pte_t pte_mkclean(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 799 | #ifdef CONFIG_PGSTE |
| 800 | pte_val(pte) &= ~_PAGE_SWC; |
| 801 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | return pte; |
| 803 | } |
| 804 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 805 | static inline pte_t pte_mkdirty(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | return pte; |
| 808 | } |
| 809 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 810 | static inline pte_t pte_mkold(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 812 | #ifdef CONFIG_PGSTE |
| 813 | pte_val(pte) &= ~_PAGE_SWR; |
| 814 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | return pte; |
| 816 | } |
| 817 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 818 | static inline pte_t pte_mkyoung(pte_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | return pte; |
| 821 | } |
| 822 | |
Nick Piggin | 7e67513 | 2008-04-28 02:13:00 -0700 | [diff] [blame] | 823 | static inline pte_t pte_mkspecial(pte_t pte) |
| 824 | { |
Nick Piggin | a08cb62 | 2008-04-28 02:13:03 -0700 | [diff] [blame] | 825 | pte_val(pte) |= _PAGE_SPECIAL; |
Nick Piggin | 7e67513 | 2008-04-28 02:13:00 -0700 | [diff] [blame] | 826 | return pte; |
| 827 | } |
| 828 | |
Heiko Carstens | 84afdce | 2010-10-25 16:10:36 +0200 | [diff] [blame] | 829 | #ifdef CONFIG_HUGETLB_PAGE |
| 830 | static inline pte_t pte_mkhuge(pte_t pte) |
| 831 | { |
| 832 | /* |
| 833 | * PROT_NONE needs to be remapped from the pte type to the ste type. |
| 834 | * The HW invalid bit is also different for pte and ste. The pte |
| 835 | * invalid bit happens to be the same as the ste _SEGMENT_ENTRY_LARGE |
| 836 | * bit, so we don't have to clear it. |
| 837 | */ |
| 838 | if (pte_val(pte) & _PAGE_INVALID) { |
| 839 | if (pte_val(pte) & _PAGE_SWT) |
| 840 | pte_val(pte) |= _HPAGE_TYPE_NONE; |
| 841 | pte_val(pte) |= _SEGMENT_ENTRY_INV; |
| 842 | } |
| 843 | /* |
| 844 | * Clear SW pte bits SWT and SWX, there are no SW bits in a segment |
| 845 | * table entry. |
| 846 | */ |
| 847 | pte_val(pte) &= ~(_PAGE_SWT | _PAGE_SWX); |
| 848 | /* |
| 849 | * Also set the change-override bit because we don't need dirty bit |
| 850 | * tracking for hugetlbfs pages. |
| 851 | */ |
| 852 | pte_val(pte) |= (_SEGMENT_ENTRY_LARGE | _SEGMENT_ENTRY_CO); |
| 853 | return pte; |
| 854 | } |
| 855 | #endif |
| 856 | |
Florian Funke | 15e86b0 | 2008-10-10 21:33:26 +0200 | [diff] [blame] | 857 | /* |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 858 | * Get (and clear) the user dirty bit for a pte. |
Florian Funke | 15e86b0 | 2008-10-10 21:33:26 +0200 | [diff] [blame] | 859 | */ |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 860 | static inline int ptep_test_and_clear_user_dirty(struct mm_struct *mm, |
| 861 | pte_t *ptep) |
Florian Funke | 15e86b0 | 2008-10-10 21:33:26 +0200 | [diff] [blame] | 862 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 863 | pgste_t pgste; |
| 864 | int dirty = 0; |
Florian Funke | 15e86b0 | 2008-10-10 21:33:26 +0200 | [diff] [blame] | 865 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 866 | if (mm_has_pgste(mm)) { |
| 867 | pgste = pgste_get_lock(ptep); |
| 868 | pgste = pgste_update_all(ptep, pgste); |
| 869 | dirty = !!(pgste_val(pgste) & KVM_UC_BIT); |
| 870 | pgste_val(pgste) &= ~KVM_UC_BIT; |
| 871 | pgste_set_unlock(ptep, pgste); |
| 872 | return dirty; |
Florian Funke | 15e86b0 | 2008-10-10 21:33:26 +0200 | [diff] [blame] | 873 | } |
Florian Funke | 15e86b0 | 2008-10-10 21:33:26 +0200 | [diff] [blame] | 874 | return dirty; |
| 875 | } |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 876 | |
| 877 | /* |
| 878 | * Get (and clear) the user referenced bit for a pte. |
| 879 | */ |
| 880 | static inline int ptep_test_and_clear_user_young(struct mm_struct *mm, |
| 881 | pte_t *ptep) |
| 882 | { |
| 883 | pgste_t pgste; |
| 884 | int young = 0; |
| 885 | |
| 886 | if (mm_has_pgste(mm)) { |
| 887 | pgste = pgste_get_lock(ptep); |
| 888 | pgste = pgste_update_young(ptep, pgste); |
| 889 | young = !!(pgste_val(pgste) & KVM_UR_BIT); |
| 890 | pgste_val(pgste) &= ~KVM_UR_BIT; |
| 891 | pgste_set_unlock(ptep, pgste); |
| 892 | } |
| 893 | return young; |
| 894 | } |
Florian Funke | 15e86b0 | 2008-10-10 21:33:26 +0200 | [diff] [blame] | 895 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 896 | #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG |
| 897 | static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, |
| 898 | unsigned long addr, pte_t *ptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 900 | pgste_t pgste; |
| 901 | pte_t pte; |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 902 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 903 | if (mm_has_pgste(vma->vm_mm)) { |
| 904 | pgste = pgste_get_lock(ptep); |
| 905 | pgste = pgste_update_young(ptep, pgste); |
| 906 | pte = *ptep; |
| 907 | *ptep = pte_mkold(pte); |
| 908 | pgste_set_unlock(ptep, pgste); |
| 909 | return pte_young(pte); |
| 910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 914 | #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH |
| 915 | static inline int ptep_clear_flush_young(struct vm_area_struct *vma, |
| 916 | unsigned long address, pte_t *ptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | { |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 918 | /* No need to flush TLB |
| 919 | * On s390 reference bits are in storage key and never in TLB |
| 920 | * With virtualization we handle the reference bit, without we |
| 921 | * we can simply return */ |
Christian Borntraeger | 5b7baf0 | 2008-03-25 18:47:12 +0100 | [diff] [blame] | 922 | return ptep_test_and_clear_young(vma, address, ptep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 925 | static inline void __ptep_ipte(unsigned long address, pte_t *ptep) |
| 926 | { |
| 927 | if (!(pte_val(*ptep) & _PAGE_INVALID)) { |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 928 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 929 | /* pto must point to the start of the segment table */ |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 930 | pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00); |
| 931 | #else |
| 932 | /* ipte in zarch mode can do the math */ |
| 933 | pte_t *pto = ptep; |
| 934 | #endif |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 935 | asm volatile( |
| 936 | " ipte %2,%3" |
| 937 | : "=m" (*ptep) : "m" (*ptep), |
| 938 | "a" (pto), "a" (address)); |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 939 | } |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 940 | } |
| 941 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 942 | /* |
| 943 | * This is hard to understand. ptep_get_and_clear and ptep_clear_flush |
| 944 | * both clear the TLB for the unmapped pte. The reason is that |
| 945 | * ptep_get_and_clear is used in common code (e.g. change_pte_range) |
| 946 | * to modify an active pte. The sequence is |
| 947 | * 1) ptep_get_and_clear |
| 948 | * 2) set_pte_at |
| 949 | * 3) flush_tlb_range |
| 950 | * On s390 the tlb needs to get flushed with the modification of the pte |
| 951 | * if the pte is active. The only way how this can be implemented is to |
| 952 | * have ptep_get_and_clear do the tlb flush. In exchange flush_tlb_range |
| 953 | * is a nop. |
| 954 | */ |
| 955 | #define __HAVE_ARCH_PTEP_GET_AND_CLEAR |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 956 | static inline pte_t ptep_get_and_clear(struct mm_struct *mm, |
| 957 | unsigned long address, pte_t *ptep) |
| 958 | { |
| 959 | pgste_t pgste; |
| 960 | pte_t pte; |
| 961 | |
| 962 | mm->context.flush_mm = 1; |
| 963 | if (mm_has_pgste(mm)) |
| 964 | pgste = pgste_get_lock(ptep); |
| 965 | |
| 966 | pte = *ptep; |
| 967 | if (!mm_exclusive(mm)) |
| 968 | __ptep_ipte(address, ptep); |
| 969 | pte_val(*ptep) = _PAGE_TYPE_EMPTY; |
| 970 | |
| 971 | if (mm_has_pgste(mm)) { |
| 972 | pgste = pgste_update_all(&pte, pgste); |
| 973 | pgste_set_unlock(ptep, pgste); |
| 974 | } |
| 975 | return pte; |
| 976 | } |
| 977 | |
| 978 | #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION |
| 979 | static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, |
| 980 | unsigned long address, |
| 981 | pte_t *ptep) |
| 982 | { |
| 983 | pte_t pte; |
| 984 | |
| 985 | mm->context.flush_mm = 1; |
| 986 | if (mm_has_pgste(mm)) |
| 987 | pgste_get_lock(ptep); |
| 988 | |
| 989 | pte = *ptep; |
| 990 | if (!mm_exclusive(mm)) |
| 991 | __ptep_ipte(address, ptep); |
| 992 | return pte; |
| 993 | } |
| 994 | |
| 995 | static inline void ptep_modify_prot_commit(struct mm_struct *mm, |
| 996 | unsigned long address, |
| 997 | pte_t *ptep, pte_t pte) |
| 998 | { |
| 999 | *ptep = pte; |
| 1000 | if (mm_has_pgste(mm)) |
| 1001 | pgste_set_unlock(ptep, *(pgste_t *)(ptep + PTRS_PER_PTE)); |
| 1002 | } |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 1003 | |
| 1004 | #define __HAVE_ARCH_PTEP_CLEAR_FLUSH |
Martin Schwidefsky | f0e47c2 | 2007-07-17 04:03:03 -0700 | [diff] [blame] | 1005 | static inline pte_t ptep_clear_flush(struct vm_area_struct *vma, |
| 1006 | unsigned long address, pte_t *ptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 1008 | pgste_t pgste; |
| 1009 | pte_t pte; |
| 1010 | |
| 1011 | if (mm_has_pgste(vma->vm_mm)) |
| 1012 | pgste = pgste_get_lock(ptep); |
| 1013 | |
| 1014 | pte = *ptep; |
| 1015 | __ptep_ipte(address, ptep); |
| 1016 | pte_val(*ptep) = _PAGE_TYPE_EMPTY; |
| 1017 | |
| 1018 | if (mm_has_pgste(vma->vm_mm)) { |
| 1019 | pgste = pgste_update_all(&pte, pgste); |
| 1020 | pgste_set_unlock(ptep, pgste); |
| 1021 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | return pte; |
| 1023 | } |
| 1024 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 1025 | /* |
| 1026 | * The batched pte unmap code uses ptep_get_and_clear_full to clear the |
| 1027 | * ptes. Here an optimization is possible. tlb_gather_mmu flushes all |
| 1028 | * tlbs of an mm if it can guarantee that the ptes of the mm_struct |
| 1029 | * cannot be accessed while the batched unmap is running. In this case |
| 1030 | * full==1 and a simple pte_clear is enough. See tlb.h. |
| 1031 | */ |
| 1032 | #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL |
| 1033 | static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 1034 | unsigned long address, |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 1035 | pte_t *ptep, int full) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | { |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 1037 | pgste_t pgste; |
| 1038 | pte_t pte; |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 1039 | |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 1040 | if (mm_has_pgste(mm)) |
| 1041 | pgste = pgste_get_lock(ptep); |
| 1042 | |
| 1043 | pte = *ptep; |
| 1044 | if (!full) |
| 1045 | __ptep_ipte(address, ptep); |
| 1046 | pte_val(*ptep) = _PAGE_TYPE_EMPTY; |
| 1047 | |
| 1048 | if (mm_has_pgste(mm)) { |
| 1049 | pgste = pgste_update_all(&pte, pgste); |
| 1050 | pgste_set_unlock(ptep, pgste); |
| 1051 | } |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 1052 | return pte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 1055 | #define __HAVE_ARCH_PTEP_SET_WRPROTECT |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 1056 | static inline pte_t ptep_set_wrprotect(struct mm_struct *mm, |
| 1057 | unsigned long address, pte_t *ptep) |
| 1058 | { |
| 1059 | pgste_t pgste; |
| 1060 | pte_t pte = *ptep; |
| 1061 | |
| 1062 | if (pte_write(pte)) { |
| 1063 | mm->context.flush_mm = 1; |
| 1064 | if (mm_has_pgste(mm)) |
| 1065 | pgste = pgste_get_lock(ptep); |
| 1066 | |
| 1067 | if (!mm_exclusive(mm)) |
| 1068 | __ptep_ipte(address, ptep); |
| 1069 | *ptep = pte_wrprotect(pte); |
| 1070 | |
| 1071 | if (mm_has_pgste(mm)) |
| 1072 | pgste_set_unlock(ptep, pgste); |
| 1073 | } |
| 1074 | return pte; |
| 1075 | } |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 1076 | |
| 1077 | #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS |
Martin Schwidefsky | b2fa47e | 2011-05-23 10:24:40 +0200 | [diff] [blame] | 1078 | static inline int ptep_set_access_flags(struct vm_area_struct *vma, |
| 1079 | unsigned long address, pte_t *ptep, |
| 1080 | pte_t entry, int dirty) |
| 1081 | { |
| 1082 | pgste_t pgste; |
| 1083 | |
| 1084 | if (pte_same(*ptep, entry)) |
| 1085 | return 0; |
| 1086 | if (mm_has_pgste(vma->vm_mm)) |
| 1087 | pgste = pgste_get_lock(ptep); |
| 1088 | |
| 1089 | __ptep_ipte(address, ptep); |
| 1090 | *ptep = entry; |
| 1091 | |
| 1092 | if (mm_has_pgste(vma->vm_mm)) |
| 1093 | pgste_set_unlock(ptep, pgste); |
| 1094 | return 1; |
| 1095 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | * Conversion functions: convert a page and protection to a page entry, |
| 1099 | * and a page entry and page directory to the page they refer to. |
| 1100 | */ |
| 1101 | static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot) |
| 1102 | { |
| 1103 | pte_t __pte; |
| 1104 | pte_val(__pte) = physpage + pgprot_val(pgprot); |
| 1105 | return __pte; |
| 1106 | } |
| 1107 | |
Heiko Carstens | 2dcea57 | 2006-09-29 01:58:41 -0700 | [diff] [blame] | 1108 | static inline pte_t mk_pte(struct page *page, pgprot_t pgprot) |
| 1109 | { |
Heiko Carstens | 0b2b6e1d | 2006-10-04 20:02:23 +0200 | [diff] [blame] | 1110 | unsigned long physpage = page_to_phys(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
Heiko Carstens | 2dcea57 | 2006-09-29 01:58:41 -0700 | [diff] [blame] | 1112 | return mk_pte_phys(physpage, pgprot); |
| 1113 | } |
| 1114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1)) |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1116 | #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1)) |
| 1117 | #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) |
| 1118 | #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1120 | #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | #define pgd_offset_k(address) pgd_offset(&init_mm, address) |
| 1122 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 1123 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1125 | #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN) |
| 1126 | #define pud_deref(pmd) ({ BUG(); 0UL; }) |
| 1127 | #define pgd_deref(pmd) ({ BUG(); 0UL; }) |
| 1128 | |
| 1129 | #define pud_offset(pgd, address) ((pud_t *) pgd) |
| 1130 | #define pmd_offset(pud, address) ((pmd_t *) pud + pmd_index(address)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 1132 | #else /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1134 | #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN) |
| 1135 | #define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN) |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 1136 | #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1137 | |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 1138 | static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address) |
| 1139 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 1140 | pud_t *pud = (pud_t *) pgd; |
| 1141 | if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2) |
| 1142 | pud = (pud_t *) pgd_deref(*pgd); |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 1143 | return pud + pud_index(address); |
| 1144 | } |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1145 | |
| 1146 | static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address) |
| 1147 | { |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 1148 | pmd_t *pmd = (pmd_t *) pud; |
| 1149 | if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) |
| 1150 | pmd = (pmd_t *) pud_deref(*pud); |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1151 | return pmd + pmd_index(address); |
| 1152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 1154 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 1156 | #define pfn_pte(pfn,pgprot) mk_pte_phys(__pa((pfn) << PAGE_SHIFT),(pgprot)) |
| 1157 | #define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT) |
| 1158 | #define pte_page(x) pfn_to_page(pte_pfn(x)) |
| 1159 | |
| 1160 | #define pmd_page(pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT) |
| 1161 | |
| 1162 | /* Find an entry in the lowest level page table.. */ |
| 1163 | #define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr)) |
| 1164 | #define pte_offset_kernel(pmd, address) pte_offset(pmd,address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | #define pte_unmap(pte) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Gerald Schaefer | 75077af | 2012-10-08 16:30:15 -0700 | [diff] [blame^] | 1168 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 1169 | static inline int pmd_trans_splitting(pmd_t pmd) |
| 1170 | { |
| 1171 | return pmd_val(pmd) & _SEGMENT_ENTRY_SPLIT; |
| 1172 | } |
| 1173 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 1174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | /* |
| 1176 | * 31 bit swap entry format: |
| 1177 | * A page-table entry has some bits we have to treat in a special way. |
| 1178 | * Bits 0, 20 and bit 23 have to be zero, otherwise an specification |
| 1179 | * exception will occur instead of a page translation exception. The |
| 1180 | * specifiation exception has the bad habit not to store necessary |
| 1181 | * information in the lowcore. |
| 1182 | * Bit 21 and bit 22 are the page invalid bit and the page protection |
| 1183 | * bit. We set both to indicate a swapped page. |
| 1184 | * Bit 30 and 31 are used to distinguish the different page types. For |
| 1185 | * a swapped page these bits need to be zero. |
| 1186 | * This leaves the bits 1-19 and bits 24-29 to store type and offset. |
| 1187 | * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19 |
| 1188 | * plus 24 for the offset. |
| 1189 | * 0| offset |0110|o|type |00| |
| 1190 | * 0 0000000001111111111 2222 2 22222 33 |
| 1191 | * 0 1234567890123456789 0123 4 56789 01 |
| 1192 | * |
| 1193 | * 64 bit swap entry format: |
| 1194 | * A page-table entry has some bits we have to treat in a special way. |
| 1195 | * Bits 52 and bit 55 have to be zero, otherwise an specification |
| 1196 | * exception will occur instead of a page translation exception. The |
| 1197 | * specifiation exception has the bad habit not to store necessary |
| 1198 | * information in the lowcore. |
| 1199 | * Bit 53 and bit 54 are the page invalid bit and the page protection |
| 1200 | * bit. We set both to indicate a swapped page. |
| 1201 | * Bit 62 and 63 are used to distinguish the different page types. For |
| 1202 | * a swapped page these bits need to be zero. |
| 1203 | * This leaves the bits 0-51 and bits 56-61 to store type and offset. |
| 1204 | * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51 |
| 1205 | * plus 56 for the offset. |
| 1206 | * | offset |0110|o|type |00| |
| 1207 | * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66 |
| 1208 | * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23 |
| 1209 | */ |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 1210 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | #define __SWP_OFFSET_MASK (~0UL >> 12) |
| 1212 | #else |
| 1213 | #define __SWP_OFFSET_MASK (~0UL >> 11) |
| 1214 | #endif |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 1215 | static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | { |
| 1217 | pte_t pte; |
| 1218 | offset &= __SWP_OFFSET_MASK; |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 1219 | pte_val(pte) = _PAGE_TYPE_SWAP | ((type & 0x1f) << 2) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | ((offset & 1UL) << 7) | ((offset & ~1UL) << 11); |
| 1221 | return pte; |
| 1222 | } |
| 1223 | |
| 1224 | #define __swp_type(entry) (((entry).val >> 2) & 0x1f) |
| 1225 | #define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1)) |
| 1226 | #define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) }) |
| 1227 | |
| 1228 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) |
| 1229 | #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) |
| 1230 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 1231 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | # define PTE_FILE_MAX_BITS 26 |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 1233 | #else /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | # define PTE_FILE_MAX_BITS 59 |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 1235 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
| 1237 | #define pte_to_pgoff(__pte) \ |
| 1238 | ((((__pte).pte >> 12) << 7) + (((__pte).pte >> 1) & 0x7f)) |
| 1239 | |
| 1240 | #define pgoff_to_pte(__off) \ |
| 1241 | ((pte_t) { ((((__off) & 0x7f) << 1) + (((__off) >> 7) << 12)) \ |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 1242 | | _PAGE_TYPE_FILE }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
| 1244 | #endif /* !__ASSEMBLY__ */ |
| 1245 | |
| 1246 | #define kern_addr_valid(addr) (1) |
| 1247 | |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 1248 | extern int vmem_add_mapping(unsigned long start, unsigned long size); |
| 1249 | extern int vmem_remove_mapping(unsigned long start, unsigned long size); |
Carsten Otte | 402b086 | 2008-03-25 18:47:10 +0100 | [diff] [blame] | 1250 | extern int s390_enable_sie(void); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 1251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | /* |
| 1253 | * No page table caches to initialise |
| 1254 | */ |
| 1255 | #define pgtable_cache_init() do { } while (0) |
| 1256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | #include <asm-generic/pgtable.h> |
| 1258 | |
| 1259 | #endif /* _S390_PAGE_H */ |