diff options
Diffstat (limited to 'arch/powerpc/mm/pgtable.c')
-rw-r--r-- | arch/powerpc/mm/pgtable.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index 6d94116fdea1..a27ded3adac5 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * This file contains common routines for dealing with free of page tables | 2 | * This file contains common routines for dealing with free of page tables |
3 | * Along with common page table handling code | ||
3 | * | 4 | * |
4 | * Derived from arch/powerpc/mm/tlb_64.c: | 5 | * Derived from arch/powerpc/mm/tlb_64.c: |
5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | 6 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
@@ -115,3 +116,133 @@ void pte_free_finish(void) | |||
115 | pte_free_submit(*batchp); | 116 | pte_free_submit(*batchp); |
116 | *batchp = NULL; | 117 | *batchp = NULL; |
117 | } | 118 | } |
119 | |||
120 | /* | ||
121 | * Handle i/d cache flushing, called from set_pte_at() or ptep_set_access_flags() | ||
122 | */ | ||
123 | static pte_t do_dcache_icache_coherency(pte_t pte) | ||
124 | { | ||
125 | unsigned long pfn = pte_pfn(pte); | ||
126 | struct page *page; | ||
127 | |||
128 | if (unlikely(!pfn_valid(pfn))) | ||
129 | return pte; | ||
130 | page = pfn_to_page(pfn); | ||
131 | |||
132 | if (!PageReserved(page) && !test_bit(PG_arch_1, &page->flags)) { | ||
133 | pr_debug("do_dcache_icache_coherency... flushing\n"); | ||
134 | flush_dcache_icache_page(page); | ||
135 | set_bit(PG_arch_1, &page->flags); | ||
136 | } | ||
137 | else | ||
138 | pr_debug("do_dcache_icache_coherency... already clean\n"); | ||
139 | return __pte(pte_val(pte) | _PAGE_HWEXEC); | ||
140 | } | ||
141 | |||
142 | static inline int is_exec_fault(void) | ||
143 | { | ||
144 | return current->thread.regs && TRAP(current->thread.regs) == 0x400; | ||
145 | } | ||
146 | |||
147 | /* We only try to do i/d cache coherency on stuff that looks like | ||
148 | * reasonably "normal" PTEs. We currently require a PTE to be present | ||
149 | * and we avoid _PAGE_SPECIAL and _PAGE_NO_CACHE | ||
150 | */ | ||
151 | static inline int pte_looks_normal(pte_t pte) | ||
152 | { | ||
153 | return (pte_val(pte) & | ||
154 | (_PAGE_PRESENT | _PAGE_SPECIAL | _PAGE_NO_CACHE)) == | ||
155 | (_PAGE_PRESENT); | ||
156 | } | ||
157 | |||
158 | #if defined(CONFIG_PPC_STD_MMU) | ||
159 | /* Server-style MMU handles coherency when hashing if HW exec permission | ||
160 | * is supposed per page (currently 64-bit only). Else, we always flush | ||
161 | * valid PTEs in set_pte. | ||
162 | */ | ||
163 | static inline int pte_need_exec_flush(pte_t pte, int set_pte) | ||
164 | { | ||
165 | return set_pte && pte_looks_normal(pte) && | ||
166 | !(cpu_has_feature(CPU_FTR_COHERENT_ICACHE) || | ||
167 | cpu_has_feature(CPU_FTR_NOEXECUTE)); | ||
168 | } | ||
169 | #elif _PAGE_HWEXEC == 0 | ||
170 | /* Embedded type MMU without HW exec support (8xx only so far), we flush | ||
171 | * the cache for any present PTE | ||
172 | */ | ||
173 | static inline int pte_need_exec_flush(pte_t pte, int set_pte) | ||
174 | { | ||
175 | return set_pte && pte_looks_normal(pte); | ||
176 | } | ||
177 | #else | ||
178 | /* Other embedded CPUs with HW exec support per-page, we flush on exec | ||
179 | * fault if HWEXEC is not set | ||
180 | */ | ||
181 | static inline int pte_need_exec_flush(pte_t pte, int set_pte) | ||
182 | { | ||
183 | return pte_looks_normal(pte) && is_exec_fault() && | ||
184 | !(pte_val(pte) & _PAGE_HWEXEC); | ||
185 | } | ||
186 | #endif | ||
187 | |||
188 | /* | ||
189 | * set_pte stores a linux PTE into the linux page table. | ||
190 | */ | ||
191 | void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) | ||
192 | { | ||
193 | #ifdef CONFIG_DEBUG_VM | ||
194 | WARN_ON(pte_present(*ptep)); | ||
195 | #endif | ||
196 | /* Note: mm->context.id might not yet have been assigned as | ||
197 | * this context might not have been activated yet when this | ||
198 | * is called. | ||
199 | */ | ||
200 | pte = __pte(pte_val(pte) & ~_PAGE_HPTEFLAGS); | ||
201 | if (pte_need_exec_flush(pte, 1)) | ||
202 | pte = do_dcache_icache_coherency(pte); | ||
203 | |||
204 | /* Perform the setting of the PTE */ | ||
205 | __set_pte_at(mm, addr, ptep, pte, 0); | ||
206 | } | ||
207 | |||
208 | /* | ||
209 | * This is called when relaxing access to a PTE. It's also called in the page | ||
210 | * fault path when we don't hit any of the major fault cases, ie, a minor | ||
211 | * update of _PAGE_ACCESSED, _PAGE_DIRTY, etc... The generic code will have | ||
212 | * handled those two for us, we additionally deal with missing execute | ||
213 | * permission here on some processors | ||
214 | */ | ||
215 | int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, | ||
216 | pte_t *ptep, pte_t entry, int dirty) | ||
217 | { | ||
218 | int changed; | ||
219 | if (!dirty && pte_need_exec_flush(entry, 0)) | ||
220 | entry = do_dcache_icache_coherency(entry); | ||
221 | changed = !pte_same(*(ptep), entry); | ||
222 | if (changed) { | ||
223 | assert_pte_locked(vma->vm_mm, address); | ||
224 | __ptep_set_access_flags(ptep, entry); | ||
225 | flush_tlb_page_nohash(vma, address); | ||
226 | } | ||
227 | return changed; | ||
228 | } | ||
229 | |||
230 | #ifdef CONFIG_DEBUG_VM | ||
231 | void assert_pte_locked(struct mm_struct *mm, unsigned long addr) | ||
232 | { | ||
233 | pgd_t *pgd; | ||
234 | pud_t *pud; | ||
235 | pmd_t *pmd; | ||
236 | |||
237 | if (mm == &init_mm) | ||
238 | return; | ||
239 | pgd = mm->pgd + pgd_index(addr); | ||
240 | BUG_ON(pgd_none(*pgd)); | ||
241 | pud = pud_offset(pgd, addr); | ||
242 | BUG_ON(pud_none(*pud)); | ||
243 | pmd = pmd_offset(pud, addr); | ||
244 | BUG_ON(!pmd_present(*pmd)); | ||
245 | BUG_ON(!spin_is_locked(pte_lockptr(mm, pmd))); | ||
246 | } | ||
247 | #endif /* CONFIG_DEBUG_VM */ | ||
248 | |||