Paul Mundt | 26ff6c1 | 2006-09-27 15:13:36 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Page fault handler for SH with an MMU. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright (C) 1999 Niibe Yutaka |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 5 | * Copyright (C) 2003 - 2009 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Based on linux/arch/i386/mm/fault.c: |
| 8 | * Copyright (C) 1995 Linus Torvalds |
Paul Mundt | 26ff6c1 | 2006-09-27 15:13:36 +0900 | [diff] [blame] | 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General Public |
| 11 | * License. See the file "COPYING" in the main directory of this archive |
| 12 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/mm.h> |
Paul Mundt | 0f08f33 | 2006-09-27 17:03:56 +0900 | [diff] [blame] | 16 | #include <linux/hardirq.h> |
| 17 | #include <linux/kprobes.h> |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 18 | #include <linux/perf_event.h> |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 19 | #include <asm/io_trapped.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/mmu_context.h> |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 22 | #include <asm/tlbflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 24 | static inline int notify_page_fault(struct pt_regs *regs, int trap) |
| 25 | { |
| 26 | int ret = 0; |
| 27 | |
Paul Mundt | c63c310 | 2009-07-05 02:50:10 +0900 | [diff] [blame] | 28 | if (kprobes_built_in() && !user_mode(regs)) { |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 29 | preempt_disable(); |
| 30 | if (kprobe_running() && kprobe_fault_handler(regs, trap)) |
| 31 | ret = 1; |
| 32 | preempt_enable(); |
| 33 | } |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 34 | |
| 35 | return ret; |
| 36 | } |
| 37 | |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 38 | static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) |
| 39 | { |
| 40 | unsigned index = pgd_index(address); |
| 41 | pgd_t *pgd_k; |
| 42 | pud_t *pud, *pud_k; |
| 43 | pmd_t *pmd, *pmd_k; |
| 44 | |
| 45 | pgd += index; |
| 46 | pgd_k = init_mm.pgd + index; |
| 47 | |
| 48 | if (!pgd_present(*pgd_k)) |
| 49 | return NULL; |
| 50 | |
| 51 | pud = pud_offset(pgd, address); |
| 52 | pud_k = pud_offset(pgd_k, address); |
| 53 | if (!pud_present(*pud_k)) |
| 54 | return NULL; |
| 55 | |
| 56 | pmd = pmd_offset(pud, address); |
| 57 | pmd_k = pmd_offset(pud_k, address); |
| 58 | if (!pmd_present(*pmd_k)) |
| 59 | return NULL; |
| 60 | |
| 61 | if (!pmd_present(*pmd)) |
| 62 | set_pmd(pmd, *pmd_k); |
Matt Fleming | 05dd2cd | 2009-07-13 11:38:04 +0000 | [diff] [blame] | 63 | else { |
| 64 | /* |
| 65 | * The page tables are fully synchronised so there must |
| 66 | * be another reason for the fault. Return NULL here to |
| 67 | * signal that we have not taken care of the fault. |
| 68 | */ |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 69 | BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k)); |
Matt Fleming | 05dd2cd | 2009-07-13 11:38:04 +0000 | [diff] [blame] | 70 | return NULL; |
| 71 | } |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 72 | |
| 73 | return pmd_k; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Handle a fault on the vmalloc or module mapping area |
| 78 | */ |
| 79 | static noinline int vmalloc_fault(unsigned long address) |
| 80 | { |
| 81 | pgd_t *pgd_k; |
| 82 | pmd_t *pmd_k; |
| 83 | pte_t *pte_k; |
| 84 | |
Paul Mundt | 0906a3a | 2009-09-03 17:21:10 +0900 | [diff] [blame] | 85 | /* Make sure we are in vmalloc/module/P3 area: */ |
| 86 | if (!(address >= VMALLOC_START && address < P3_ADDR_MAX)) |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 87 | return -1; |
| 88 | |
| 89 | /* |
| 90 | * Synchronize this task's top level page-table |
| 91 | * with the 'reference' page table. |
| 92 | * |
| 93 | * Do _not_ use "current" here. We might be inside |
| 94 | * an interrupt in the middle of a task switch.. |
| 95 | */ |
| 96 | pgd_k = get_TTB(); |
Matt Fleming | 05dd2cd | 2009-07-13 11:38:04 +0000 | [diff] [blame] | 97 | pmd_k = vmalloc_sync_one(pgd_k, address); |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 98 | if (!pmd_k) |
| 99 | return -1; |
| 100 | |
| 101 | pte_k = pte_offset_kernel(pmd_k, address); |
| 102 | if (!pte_present(*pte_k)) |
| 103 | return -1; |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int fault_in_kernel_space(unsigned long address) |
| 109 | { |
| 110 | return address >= TASK_SIZE; |
| 111 | } |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* |
| 114 | * This routine handles page faults. It determines the address, |
| 115 | * and the problem, and then passes it off to one of the appropriate |
| 116 | * routines. |
| 117 | */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 118 | asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, |
| 119 | unsigned long writeaccess, |
| 120 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 122 | unsigned long vec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | struct task_struct *tsk; |
| 124 | struct mm_struct *mm; |
| 125 | struct vm_area_struct * vma; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 126 | int si_code; |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 127 | int fault; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 128 | siginfo_t info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | tsk = current; |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 131 | mm = tsk->mm; |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 132 | si_code = SEGV_MAPERR; |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 133 | vec = lookup_exception_vector(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 135 | /* |
| 136 | * We fault-in kernel-space virtual memory on-demand. The |
| 137 | * 'reference' page table is init_mm.pgd. |
| 138 | * |
| 139 | * NOTE! We MUST NOT take any locks for this case. We may |
| 140 | * be in an interrupt or a critical region, and should |
| 141 | * only copy the information from the master page table, |
| 142 | * nothing more. |
| 143 | */ |
| 144 | if (unlikely(fault_in_kernel_space(address))) { |
| 145 | if (vmalloc_fault(address) >= 0) |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 146 | return; |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 147 | if (notify_page_fault(regs, vec)) |
Stuart Menefy | 96e14e5 | 2008-09-05 16:17:15 +0900 | [diff] [blame] | 148 | return; |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 149 | |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 150 | goto bad_area_nosemaphore; |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 151 | } |
| 152 | |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 153 | if (unlikely(notify_page_fault(regs, vec))) |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 154 | return; |
| 155 | |
| 156 | /* Only enable interrupts if they were on before the fault */ |
| 157 | if ((regs->sr & SR_IMASK) != SR_IMASK) |
| 158 | local_irq_enable(); |
| 159 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 160 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, 0, regs, address); |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 163 | * If we're in an interrupt, have no user context or are running |
| 164 | * in an atomic region then we must not take the fault: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | */ |
| 166 | if (in_atomic() || !mm) |
| 167 | goto no_context; |
| 168 | |
| 169 | down_read(&mm->mmap_sem); |
| 170 | |
| 171 | vma = find_vma(mm, address); |
| 172 | if (!vma) |
| 173 | goto bad_area; |
| 174 | if (vma->vm_start <= address) |
| 175 | goto good_area; |
| 176 | if (!(vma->vm_flags & VM_GROWSDOWN)) |
| 177 | goto bad_area; |
| 178 | if (expand_stack(vma, address)) |
| 179 | goto bad_area; |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * Ok, we have a good vm_area for this memory access, so |
| 183 | * we can handle it.. |
| 184 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | good_area: |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 186 | si_code = SEGV_ACCERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (writeaccess) { |
| 188 | if (!(vma->vm_flags & VM_WRITE)) |
| 189 | goto bad_area; |
| 190 | } else { |
Jason Baron | df67b3d | 2006-09-29 01:58:58 -0700 | [diff] [blame] | 191 | if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | goto bad_area; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * If for any reason at all we couldn't handle the fault, |
| 197 | * make sure we exit gracefully rather than endlessly redo |
| 198 | * the fault. |
| 199 | */ |
| 200 | survive: |
Linus Torvalds | d06063c | 2009-04-10 09:01:23 -0700 | [diff] [blame] | 201 | fault = handle_mm_fault(mm, vma, address, writeaccess ? FAULT_FLAG_WRITE : 0); |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 202 | if (unlikely(fault & VM_FAULT_ERROR)) { |
| 203 | if (fault & VM_FAULT_OOM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | goto out_of_memory; |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 205 | else if (fault & VM_FAULT_SIGBUS) |
| 206 | goto do_sigbus; |
| 207 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 209 | if (fault & VM_FAULT_MAJOR) { |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 210 | tsk->maj_flt++; |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 211 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0, |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 212 | regs, address); |
| 213 | } else { |
Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 214 | tsk->min_flt++; |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 215 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0, |
Paul Mundt | 7433ab770 | 2009-06-25 02:30:10 +0900 | [diff] [blame] | 216 | regs, address); |
| 217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | up_read(&mm->mmap_sem); |
| 220 | return; |
| 221 | |
Paul Mundt | 0f60bb2 | 2009-07-05 03:18:47 +0900 | [diff] [blame] | 222 | /* |
| 223 | * Something tried to access memory that isn't in our memory map.. |
| 224 | * Fix it, but check if it's kernel or user first.. |
| 225 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | bad_area: |
| 227 | up_read(&mm->mmap_sem); |
| 228 | |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 229 | bad_area_nosemaphore: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if (user_mode(regs)) { |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 231 | info.si_signo = SIGSEGV; |
| 232 | info.si_errno = 0; |
| 233 | info.si_code = si_code; |
| 234 | info.si_addr = (void *) address; |
| 235 | force_sig_info(SIGSEGV, &info, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | |
| 239 | no_context: |
| 240 | /* Are we prepared to handle this kernel fault? */ |
| 241 | if (fixup_exception(regs)) |
| 242 | return; |
| 243 | |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 244 | if (handle_trapped_io(regs, address)) |
| 245 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | /* |
| 247 | * Oops. The kernel tried to access some bad page. We'll have to |
| 248 | * terminate things with extreme prejudice. |
| 249 | * |
| 250 | */ |
Paul Mundt | 0630e45 | 2007-06-18 19:02:47 +0900 | [diff] [blame] | 251 | |
| 252 | bust_spinlocks(1); |
| 253 | |
| 254 | if (oops_may_print()) { |
Paul Mundt | b62ad83 | 2008-01-10 14:07:03 +0900 | [diff] [blame] | 255 | unsigned long page; |
Paul Mundt | 0630e45 | 2007-06-18 19:02:47 +0900 | [diff] [blame] | 256 | |
| 257 | if (address < PAGE_SIZE) |
| 258 | printk(KERN_ALERT "Unable to handle kernel NULL " |
| 259 | "pointer dereference"); |
| 260 | else |
| 261 | printk(KERN_ALERT "Unable to handle kernel paging " |
| 262 | "request"); |
| 263 | printk(" at virtual address %08lx\n", address); |
| 264 | printk(KERN_ALERT "pc = %08lx\n", regs->pc); |
| 265 | page = (unsigned long)get_TTB(); |
| 266 | if (page) { |
Paul Mundt | 06f862c | 2007-08-01 16:39:51 +0900 | [diff] [blame] | 267 | page = ((__typeof__(page) *)page)[address >> PGDIR_SHIFT]; |
Paul Mundt | 0630e45 | 2007-06-18 19:02:47 +0900 | [diff] [blame] | 268 | printk(KERN_ALERT "*pde = %08lx\n", page); |
| 269 | if (page & _PAGE_PRESENT) { |
| 270 | page &= PAGE_MASK; |
| 271 | address &= 0x003ff000; |
| 272 | page = ((__typeof__(page) *) |
| 273 | __va(page))[address >> |
| 274 | PAGE_SHIFT]; |
| 275 | printk(KERN_ALERT "*pte = %08lx\n", page); |
| 276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
Paul Mundt | 0630e45 | 2007-06-18 19:02:47 +0900 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | die("Oops", regs, writeaccess); |
Paul Mundt | 0630e45 | 2007-06-18 19:02:47 +0900 | [diff] [blame] | 281 | bust_spinlocks(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | do_exit(SIGKILL); |
| 283 | |
| 284 | /* |
| 285 | * We ran out of memory, or some other thing happened to us that made |
| 286 | * us unable to handle the page fault gracefully. |
| 287 | */ |
| 288 | out_of_memory: |
| 289 | up_read(&mm->mmap_sem); |
Serge E. Hallyn | b460cbc | 2007-10-18 23:39:52 -0700 | [diff] [blame] | 290 | if (is_global_init(current)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | yield(); |
| 292 | down_read(&mm->mmap_sem); |
| 293 | goto survive; |
| 294 | } |
| 295 | printk("VM: killing process %s\n", tsk->comm); |
| 296 | if (user_mode(regs)) |
Will Schmidt | dcca2bd | 2007-10-16 01:24:18 -0700 | [diff] [blame] | 297 | do_group_exit(SIGKILL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | goto no_context; |
| 299 | |
| 300 | do_sigbus: |
| 301 | up_read(&mm->mmap_sem); |
| 302 | |
| 303 | /* |
| 304 | * Send a sigbus, regardless of whether we were in kernel |
| 305 | * or user mode. |
| 306 | */ |
Stuart Menefy | b5a1bcb | 2006-11-21 13:34:04 +0900 | [diff] [blame] | 307 | info.si_signo = SIGBUS; |
| 308 | info.si_errno = 0; |
| 309 | info.si_code = BUS_ADRERR; |
| 310 | info.si_addr = (void *)address; |
| 311 | force_sig_info(SIGBUS, &info, tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | /* Kernel mode? Handle exceptions or die */ |
| 314 | if (!user_mode(regs)) |
| 315 | goto no_context; |
| 316 | } |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 317 | |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 318 | /* |
| 319 | * Called with interrupts disabled. |
| 320 | */ |
Paul Mundt | 112e584 | 2009-08-15 02:49:40 +0900 | [diff] [blame] | 321 | asmlinkage int __kprobes |
| 322 | handle_tlbmiss(struct pt_regs *regs, unsigned long writeaccess, |
| 323 | unsigned long address) |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 324 | { |
| 325 | pgd_t *pgd; |
| 326 | pud_t *pud; |
| 327 | pmd_t *pmd; |
| 328 | pte_t *pte; |
| 329 | pte_t entry; |
Paul Mundt | 3d58695 | 2008-09-21 13:56:39 +0900 | [diff] [blame] | 330 | |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 331 | /* |
| 332 | * We don't take page faults for P1, P2, and parts of P4, these |
| 333 | * are always mapped, whether it be due to legacy behaviour in |
| 334 | * 29-bit mode, or due to PMB configuration in 32-bit mode. |
| 335 | */ |
| 336 | if (address >= P3SEG && address < P3_ADDR_MAX) { |
| 337 | pgd = pgd_offset_k(address); |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 338 | } else { |
Paul Mundt | 0f1a394 | 2007-11-19 13:05:18 +0900 | [diff] [blame] | 339 | if (unlikely(address >= TASK_SIZE || !current->mm)) |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 340 | return 1; |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 341 | |
Paul Mundt | 0f1a394 | 2007-11-19 13:05:18 +0900 | [diff] [blame] | 342 | pgd = pgd_offset(current->mm, address); |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | pud = pud_offset(pgd, address); |
| 346 | if (pud_none_or_clear_bad(pud)) |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 347 | return 1; |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 348 | pmd = pmd_offset(pud, address); |
| 349 | if (pmd_none_or_clear_bad(pmd)) |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 350 | return 1; |
Paul Mundt | 0f1a394 | 2007-11-19 13:05:18 +0900 | [diff] [blame] | 351 | pte = pte_offset_kernel(pmd, address); |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 352 | entry = *pte; |
| 353 | if (unlikely(pte_none(entry) || pte_not_present(entry))) |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 354 | return 1; |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 355 | if (unlikely(writeaccess && !pte_write(entry))) |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 356 | return 1; |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 357 | |
| 358 | if (writeaccess) |
| 359 | entry = pte_mkdirty(entry); |
| 360 | entry = pte_mkyoung(entry); |
| 361 | |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 362 | set_pte(pte, entry); |
| 363 | |
Hideo Saito | a602cc0 | 2008-02-14 14:45:08 +0900 | [diff] [blame] | 364 | #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SMP) |
| 365 | /* |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 366 | * SH-4 does not set MMUCR.RC to the corresponding TLB entry in |
| 367 | * the case of an initial page write exception, so we need to |
| 368 | * flush it in order to avoid potential TLB entry duplication. |
Hideo Saito | a602cc0 | 2008-02-14 14:45:08 +0900 | [diff] [blame] | 369 | */ |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 370 | if (writeaccess == 2) |
| 371 | local_flush_tlb_one(get_asid(), address & PAGE_MASK); |
Hideo Saito | a602cc0 | 2008-02-14 14:45:08 +0900 | [diff] [blame] | 372 | #endif |
| 373 | |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 374 | update_mmu_cache(NULL, address, entry); |
Paul Mundt | 0f1a394 | 2007-11-19 13:05:18 +0900 | [diff] [blame] | 375 | |
Paul Mundt | 8010fbe | 2009-08-15 03:06:41 +0900 | [diff] [blame] | 376 | return 0; |
Paul Mundt | db2e1fa | 2007-02-14 14:13:10 +0900 | [diff] [blame] | 377 | } |