diff options
author | Chris Zankel <chris@zankel.net> | 2013-05-20 14:09:13 -0400 |
---|---|---|
committer | Chris Zankel <chris@zankel.net> | 2013-05-20 14:09:13 -0400 |
commit | 7711ece9b31f0f3cf15ca16005dfd78988ea8f7e (patch) | |
tree | bb4ba7b6e3a48f6fbaebcc4109453722f0cd42ef | |
parent | f722406faae2d073cc1d01063d1123c35425939e (diff) |
xtensa: fix TLB multihit exceptions
- set _PAGE_USER in the pte_clear to avoid having TLB multihit exceptions
(see following threads for more details);
http://lists.linux-xtensa.org/pipermail/linux-xtensa/Week-of-Mon-20130401/
http://lists.linux-xtensa.org/pipermail/linux-xtensa/Week-of-Mon-20130408/
- improved documentation of the PTE layout
- fix PTE mapping for present and 'prot_none' pages for T1050 hw and earlier
- fix pte_file offset and size
- add check for the correct number of bits for swap type
CC: piet.delaney@gmail.com
CC: jcmvbkbc@gmail.com
Signed-off-by: Chris Zankel <chris@zankel.net>
-rw-r--r-- | arch/xtensa/include/asm/pgtable.h | 140 |
1 files changed, 83 insertions, 57 deletions
diff --git a/arch/xtensa/include/asm/pgtable.h b/arch/xtensa/include/asm/pgtable.h index d7546c94da52..7e09f7011370 100644 --- a/arch/xtensa/include/asm/pgtable.h +++ b/arch/xtensa/include/asm/pgtable.h | |||
@@ -5,7 +5,7 @@ | |||
5 | * it under the terms of the GNU General Public License version 2 as | 5 | * it under the terms of the GNU General Public License version 2 as |
6 | * published by the Free Software Foundation. | 6 | * published by the Free Software Foundation. |
7 | * | 7 | * |
8 | * Copyright (C) 2001 - 2007 Tensilica Inc. | 8 | * Copyright (C) 2001 - 2013 Tensilica Inc. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #ifndef _XTENSA_PGTABLE_H | 11 | #ifndef _XTENSA_PGTABLE_H |
@@ -64,41 +64,82 @@ | |||
64 | * Virtual memory area. We keep a distance to other memory regions to be | 64 | * Virtual memory area. We keep a distance to other memory regions to be |
65 | * on the safe side. We also use this area for cache aliasing. | 65 | * on the safe side. We also use this area for cache aliasing. |
66 | */ | 66 | */ |
67 | |||
68 | #define VMALLOC_START 0xC0000000 | 67 | #define VMALLOC_START 0xC0000000 |
69 | #define VMALLOC_END 0xC7FEFFFF | 68 | #define VMALLOC_END 0xC7FEFFFF |
70 | #define TLBTEMP_BASE_1 0xC7FF0000 | 69 | #define TLBTEMP_BASE_1 0xC7FF0000 |
71 | #define TLBTEMP_BASE_2 0xC7FF8000 | 70 | #define TLBTEMP_BASE_2 0xC7FF8000 |
72 | 71 | ||
73 | /* | 72 | /* |
74 | * Xtensa Linux config PTE layout (when present): | 73 | * For the Xtensa architecture, the PTE layout is as follows: |
75 | * 31-12: PPN | 74 | * |
76 | * 11-6: Software | 75 | * 31------12 11 10-9 8-6 5-4 3-2 1-0 |
77 | * 5-4: RING | 76 | * +-----------------------------------------+ |
78 | * 3-0: CA | 77 | * | | Software | HARDWARE | |
78 | * | PPN | ADW | RI |Attribute| | ||
79 | * +-----------------------------------------+ | ||
80 | * pte_none | MBZ | 01 | 11 | 00 | | ||
81 | * +-----------------------------------------+ | ||
82 | * present | PPN | 0 | 00 | ADW | RI | CA | wx | | ||
83 | * +- - - - - - - - - - - - - - - - - - - - -+ | ||
84 | * (PAGE_NONE)| PPN | 0 | 00 | ADW | 01 | 11 | 11 | | ||
85 | * +-----------------------------------------+ | ||
86 | * swap | index | type | 01 | 11 | 00 | | ||
87 | * +- - - - - - - - - - - - - - - - - - - - -+ | ||
88 | * file | file offset | 01 | 11 | 10 | | ||
89 | * +-----------------------------------------+ | ||
90 | * | ||
91 | * For T1050 hardware and earlier the layout differs for present and (PAGE_NONE) | ||
92 | * +-----------------------------------------+ | ||
93 | * present | PPN | 0 | 00 | ADW | RI | CA | w1 | | ||
94 | * +-----------------------------------------+ | ||
95 | * (PAGE_NONE)| PPN | 0 | 00 | ADW | 01 | 01 | 00 | | ||
96 | * +-----------------------------------------+ | ||
79 | * | 97 | * |
80 | * Similar to the Alpha and MIPS ports, we need to keep track of the ref | 98 | * Legend: |
81 | * and mod bits in software. We have a software "you can read | 99 | * PPN Physical Page Number |
82 | * from this page" bit, and a hardware one which actually lets the | 100 | * ADW software: accessed (young) / dirty / writable |
83 | * process read from the page. On the same token we have a software | 101 | * RI ring (0=privileged, 1=user, 2 and 3 are unused) |
84 | * writable bit and the real hardware one which actually lets the | 102 | * CA cache attribute: 00 bypass, 01 writeback, 10 writethrough |
85 | * process write to the page. | 103 | * (11 is invalid and used to mark pages that are not present) |
104 | * w page is writable (hw) | ||
105 | * x page is executable (hw) | ||
106 | * index swap offset / PAGE_SIZE (bit 11-31: 21 bits -> 8 GB) | ||
107 | * (note that the index is always non-zero) | ||
108 | * type swap type (5 bits -> 32 types) | ||
109 | * file offset 26-bit offset into the file, in increments of PAGE_SIZE | ||
86 | * | 110 | * |
87 | * See further below for PTE layout for swapped-out pages. | 111 | * Notes: |
112 | * - (PROT_NONE) is a special case of 'present' but causes an exception for | ||
113 | * any access (read, write, and execute). | ||
114 | * - 'multihit-exception' has the highest priority of all MMU exceptions, | ||
115 | * so the ring must be set to 'RING_USER' even for 'non-present' pages. | ||
116 | * - on older hardware, the exectuable flag was not supported and | ||
117 | * used as a 'valid' flag, so it needs to be always set. | ||
118 | * - we need to keep track of certain flags in software (dirty and young) | ||
119 | * to do this, we use write exceptions and have a separate software w-flag. | ||
120 | * - attribute value 1101 (and 1111 on T1050 and earlier) is reserved | ||
88 | */ | 121 | */ |
89 | 122 | ||
123 | #define _PAGE_ATTRIB_MASK 0xf | ||
124 | |||
90 | #define _PAGE_HW_EXEC (1<<0) /* hardware: page is executable */ | 125 | #define _PAGE_HW_EXEC (1<<0) /* hardware: page is executable */ |
91 | #define _PAGE_HW_WRITE (1<<1) /* hardware: page is writable */ | 126 | #define _PAGE_HW_WRITE (1<<1) /* hardware: page is writable */ |
92 | 127 | ||
93 | #define _PAGE_FILE (1<<1) /* non-linear mapping, if !present */ | ||
94 | #define _PAGE_PROTNONE (3<<0) /* special case for VM_PROT_NONE */ | ||
95 | |||
96 | /* None of these cache modes include MP coherency: */ | ||
97 | #define _PAGE_CA_BYPASS (0<<2) /* bypass, non-speculative */ | 128 | #define _PAGE_CA_BYPASS (0<<2) /* bypass, non-speculative */ |
98 | #define _PAGE_CA_WB (1<<2) /* write-back */ | 129 | #define _PAGE_CA_WB (1<<2) /* write-back */ |
99 | #define _PAGE_CA_WT (2<<2) /* write-through */ | 130 | #define _PAGE_CA_WT (2<<2) /* write-through */ |
100 | #define _PAGE_CA_MASK (3<<2) | 131 | #define _PAGE_CA_MASK (3<<2) |
101 | #define _PAGE_INVALID (3<<2) | 132 | #define _PAGE_CA_INVALID (3<<2) |
133 | |||
134 | /* We use invalid attribute values to distinguish special pte entries */ | ||
135 | #if XCHAL_HW_VERSION_MAJOR < 2000 | ||
136 | #define _PAGE_HW_VALID 0x01 /* older HW needed this bit set */ | ||
137 | #define _PAGE_NONE 0x04 | ||
138 | #else | ||
139 | #define _PAGE_HW_VALID 0x00 | ||
140 | #define _PAGE_NONE 0x0f | ||
141 | #endif | ||
142 | #define _PAGE_FILE (1<<1) /* file mapped page, only if !present */ | ||
102 | 143 | ||
103 | #define _PAGE_USER (1<<4) /* user access (ring=1) */ | 144 | #define _PAGE_USER (1<<4) /* user access (ring=1) */ |
104 | 145 | ||
@@ -108,19 +149,12 @@ | |||
108 | #define _PAGE_DIRTY (1<<7) /* software: page dirty */ | 149 | #define _PAGE_DIRTY (1<<7) /* software: page dirty */ |
109 | #define _PAGE_ACCESSED (1<<8) /* software: page accessed (read) */ | 150 | #define _PAGE_ACCESSED (1<<8) /* software: page accessed (read) */ |
110 | 151 | ||
111 | /* On older HW revisions, we always have to set bit 0 */ | ||
112 | #if XCHAL_HW_VERSION_MAJOR < 2000 | ||
113 | # define _PAGE_VALID (1<<0) | ||
114 | #else | ||
115 | # define _PAGE_VALID 0 | ||
116 | #endif | ||
117 | |||
118 | #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) | ||
119 | #define _PAGE_PRESENT (_PAGE_VALID | _PAGE_CA_WB | _PAGE_ACCESSED) | ||
120 | |||
121 | #ifdef CONFIG_MMU | 152 | #ifdef CONFIG_MMU |
122 | 153 | ||
123 | #define PAGE_NONE __pgprot(_PAGE_INVALID | _PAGE_USER | _PAGE_PROTNONE) | 154 | #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) |
155 | #define _PAGE_PRESENT (_PAGE_HW_VALID | _PAGE_CA_WB | _PAGE_ACCESSED) | ||
156 | |||
157 | #define PAGE_NONE __pgprot(_PAGE_NONE | _PAGE_USER) | ||
124 | #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER) | 158 | #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER) |
125 | #define PAGE_COPY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_HW_EXEC) | 159 | #define PAGE_COPY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_HW_EXEC) |
126 | #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER) | 160 | #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER) |
@@ -132,9 +166,9 @@ | |||
132 | #define PAGE_KERNEL_EXEC __pgprot(_PAGE_PRESENT|_PAGE_HW_WRITE|_PAGE_HW_EXEC) | 166 | #define PAGE_KERNEL_EXEC __pgprot(_PAGE_PRESENT|_PAGE_HW_WRITE|_PAGE_HW_EXEC) |
133 | 167 | ||
134 | #if (DCACHE_WAY_SIZE > PAGE_SIZE) | 168 | #if (DCACHE_WAY_SIZE > PAGE_SIZE) |
135 | # define _PAGE_DIRECTORY (_PAGE_VALID | _PAGE_ACCESSED) | 169 | # define _PAGE_DIRECTORY (_PAGE_HW_VALID | _PAGE_ACCESSED | _PAGE_CA_BYPASS) |
136 | #else | 170 | #else |
137 | # define _PAGE_DIRECTORY (_PAGE_VALID | _PAGE_ACCESSED | _PAGE_CA_WB) | 171 | # define _PAGE_DIRECTORY (_PAGE_HW_VALID | _PAGE_ACCESSED | _PAGE_CA_WB) |
138 | #endif | 172 | #endif |
139 | 173 | ||
140 | #else /* no mmu */ | 174 | #else /* no mmu */ |
@@ -202,12 +236,16 @@ static inline void pgtable_cache_init(void) { } | |||
202 | /* | 236 | /* |
203 | * pte status. | 237 | * pte status. |
204 | */ | 238 | */ |
205 | #define pte_none(pte) (pte_val(pte) == _PAGE_INVALID) | 239 | # define pte_none(pte) (pte_val(pte) == (_PAGE_CA_INVALID | _PAGE_USER)) |
206 | #define pte_present(pte) \ | 240 | #if XCHAL_HW_VERSION_MAJOR < 2000 |
207 | (((pte_val(pte) & _PAGE_CA_MASK) != _PAGE_INVALID) \ | 241 | # define pte_present(pte) ((pte_val(pte) & _PAGE_CA_MASK) != _PAGE_CA_INVALID) |
208 | || ((pte_val(pte) & _PAGE_PROTNONE) == _PAGE_PROTNONE)) | 242 | #else |
243 | # define pte_present(pte) \ | ||
244 | (((pte_val(pte) & _PAGE_CA_MASK) != _PAGE_CA_INVALID) \ | ||
245 | || ((pte_val(pte) & _PAGE_ATTRIB_MASK) == _PAGE_NONE)) | ||
246 | #endif | ||
209 | #define pte_clear(mm,addr,ptep) \ | 247 | #define pte_clear(mm,addr,ptep) \ |
210 | do { update_pte(ptep, __pte(_PAGE_INVALID)); } while(0) | 248 | do { update_pte(ptep, __pte(_PAGE_CA_INVALID | _PAGE_USER)); } while (0) |
211 | 249 | ||
212 | #define pmd_none(pmd) (!pmd_val(pmd)) | 250 | #define pmd_none(pmd) (!pmd_val(pmd)) |
213 | #define pmd_present(pmd) (pmd_val(pmd) & PAGE_MASK) | 251 | #define pmd_present(pmd) (pmd_val(pmd) & PAGE_MASK) |
@@ -328,35 +366,23 @@ ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) | |||
328 | 366 | ||
329 | 367 | ||
330 | /* | 368 | /* |
331 | * Encode and decode a swap entry. | 369 | * Encode and decode a swap and file entry. |
332 | * | ||
333 | * Format of swap pte: | ||
334 | * bit 0 MBZ | ||
335 | * bit 1 page-file (must be zero) | ||
336 | * bits 2 - 3 page hw access mode (must be 11: _PAGE_INVALID) | ||
337 | * bits 4 - 5 ring protection (must be 01: _PAGE_USER) | ||
338 | * bits 6 - 10 swap type (5 bits -> 32 types) | ||
339 | * bits 11 - 31 swap offset / PAGE_SIZE (21 bits -> 8GB) | ||
340 | |||
341 | * Format of file pte: | ||
342 | * bit 0 MBZ | ||
343 | * bit 1 page-file (must be one: _PAGE_FILE) | ||
344 | * bits 2 - 3 page hw access mode (must be 11: _PAGE_INVALID) | ||
345 | * bits 4 - 5 ring protection (must be 01: _PAGE_USER) | ||
346 | * bits 6 - 31 file offset / PAGE_SIZE | ||
347 | */ | 370 | */ |
371 | #define SWP_TYPE_BITS 5 | ||
372 | #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS) | ||
348 | 373 | ||
349 | #define __swp_type(entry) (((entry).val >> 6) & 0x1f) | 374 | #define __swp_type(entry) (((entry).val >> 6) & 0x1f) |
350 | #define __swp_offset(entry) ((entry).val >> 11) | 375 | #define __swp_offset(entry) ((entry).val >> 11) |
351 | #define __swp_entry(type,offs) \ | 376 | #define __swp_entry(type,offs) \ |
352 | ((swp_entry_t) {((type) << 6) | ((offs) << 11) | _PAGE_INVALID}) | 377 | ((swp_entry_t){((type) << 6) | ((offs) << 11) | \ |
378 | _PAGE_CA_INVALID | _PAGE_USER}) | ||
353 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) | 379 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) |
354 | #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) | 380 | #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) |
355 | 381 | ||
356 | #define PTE_FILE_MAX_BITS 28 | 382 | #define PTE_FILE_MAX_BITS 26 |
357 | #define pte_to_pgoff(pte) (pte_val(pte) >> 4) | 383 | #define pte_to_pgoff(pte) (pte_val(pte) >> 6) |
358 | #define pgoff_to_pte(off) \ | 384 | #define pgoff_to_pte(off) \ |
359 | ((pte_t) { ((off) << 4) | _PAGE_INVALID | _PAGE_FILE }) | 385 | ((pte_t) { ((off) << 6) | _PAGE_CA_INVALID | _PAGE_FILE | _PAGE_USER }) |
360 | 386 | ||
361 | #endif /* !defined (__ASSEMBLY__) */ | 387 | #endif /* !defined (__ASSEMBLY__) */ |
362 | 388 | ||