Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: fault.c,v 1.59 2002/02/09 19:49:31 davem Exp $ |
| 2 | * arch/sparc64/mm/fault.c: Page fault handlers for the 64-bit Sparc. |
| 3 | * |
| 4 | * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) |
| 5 | * Copyright (C) 1997, 1999 Jakub Jelinek (jj@ultra.linux.cz) |
| 6 | */ |
| 7 | |
| 8 | #include <asm/head.h> |
| 9 | |
| 10 | #include <linux/string.h> |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/ptrace.h> |
| 14 | #include <linux/mman.h> |
| 15 | #include <linux/signal.h> |
| 16 | #include <linux/mm.h> |
| 17 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/init.h> |
| 19 | #include <linux/interrupt.h> |
Prasanna S Panchamukhi | 05e14cb | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 20 | #include <linux/kprobes.h> |
David S. Miller | eb398d1 | 2006-07-22 01:12:09 -0700 | [diff] [blame] | 21 | #include <linux/kallsyms.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 22 | #include <linux/kdebug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <asm/page.h> |
| 25 | #include <asm/pgtable.h> |
| 26 | #include <asm/openprom.h> |
| 27 | #include <asm/oplib.h> |
| 28 | #include <asm/uaccess.h> |
| 29 | #include <asm/asi.h> |
| 30 | #include <asm/lsu.h> |
| 31 | #include <asm/sections.h> |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 32 | #include <asm/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Anil S Keshavamurthy | d98f8f0 | 2006-06-26 00:25:27 -0700 | [diff] [blame] | 34 | #ifdef CONFIG_KPROBES |
David S. Miller | 127cda1 | 2007-05-08 18:25:14 -0700 | [diff] [blame^] | 35 | static inline int notify_page_fault(struct pt_regs *regs) |
Anil S Keshavamurthy | d98f8f0 | 2006-06-26 00:25:27 -0700 | [diff] [blame] | 36 | { |
David S. Miller | 127cda1 | 2007-05-08 18:25:14 -0700 | [diff] [blame^] | 37 | int ret = 0; |
Anil S Keshavamurthy | d98f8f0 | 2006-06-26 00:25:27 -0700 | [diff] [blame] | 38 | |
David S. Miller | 127cda1 | 2007-05-08 18:25:14 -0700 | [diff] [blame^] | 39 | /* kprobe_running() needs smp_processor_id() */ |
| 40 | if (!user_mode(regs)) { |
| 41 | preempt_disable(); |
| 42 | if (kprobe_running() && kprobe_fault_handler(regs, 0)) |
| 43 | ret = 1; |
| 44 | preempt_enable(); |
| 45 | } |
| 46 | return ret; |
Anil S Keshavamurthy | d98f8f0 | 2006-06-26 00:25:27 -0700 | [diff] [blame] | 47 | } |
| 48 | #else |
David S. Miller | 127cda1 | 2007-05-08 18:25:14 -0700 | [diff] [blame^] | 49 | static inline int notify_page_fault(struct pt_regs *regs) |
Anil S Keshavamurthy | d98f8f0 | 2006-06-26 00:25:27 -0700 | [diff] [blame] | 50 | { |
David S. Miller | 127cda1 | 2007-05-08 18:25:14 -0700 | [diff] [blame^] | 51 | return 0; |
Anil S Keshavamurthy | d98f8f0 | 2006-06-26 00:25:27 -0700 | [diff] [blame] | 52 | } |
| 53 | #endif |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | * To debug kernel to catch accesses to certain virtual/physical addresses. |
| 57 | * Mode = 0 selects physical watchpoints, mode = 1 selects virtual watchpoints. |
| 58 | * flags = VM_READ watches memread accesses, flags = VM_WRITE watches memwrite accesses. |
| 59 | * Caller passes in a 64bit aligned addr, with mask set to the bytes that need to be |
| 60 | * watched. This is only useful on a single cpu machine for now. After the watchpoint |
| 61 | * is detected, the process causing it will be killed, thus preventing an infinite loop. |
| 62 | */ |
| 63 | void set_brkpt(unsigned long addr, unsigned char mask, int flags, int mode) |
| 64 | { |
| 65 | unsigned long lsubits; |
| 66 | |
| 67 | __asm__ __volatile__("ldxa [%%g0] %1, %0" |
| 68 | : "=r" (lsubits) |
| 69 | : "i" (ASI_LSU_CONTROL)); |
| 70 | lsubits &= ~(LSU_CONTROL_PM | LSU_CONTROL_VM | |
| 71 | LSU_CONTROL_PR | LSU_CONTROL_VR | |
| 72 | LSU_CONTROL_PW | LSU_CONTROL_VW); |
| 73 | |
| 74 | __asm__ __volatile__("stxa %0, [%1] %2\n\t" |
| 75 | "membar #Sync" |
| 76 | : /* no outputs */ |
| 77 | : "r" (addr), "r" (mode ? VIRT_WATCHPOINT : PHYS_WATCHPOINT), |
| 78 | "i" (ASI_DMMU)); |
| 79 | |
| 80 | lsubits |= ((unsigned long)mask << (mode ? 25 : 33)); |
| 81 | if (flags & VM_READ) |
| 82 | lsubits |= (mode ? LSU_CONTROL_VR : LSU_CONTROL_PR); |
| 83 | if (flags & VM_WRITE) |
| 84 | lsubits |= (mode ? LSU_CONTROL_VW : LSU_CONTROL_PW); |
| 85 | __asm__ __volatile__("stxa %0, [%%g0] %1\n\t" |
| 86 | "membar #Sync" |
| 87 | : /* no outputs */ |
| 88 | : "r" (lsubits), "i" (ASI_LSU_CONTROL) |
| 89 | : "memory"); |
| 90 | } |
| 91 | |
Prasanna S Panchamukhi | 05e14cb | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 92 | static void __kprobes unhandled_fault(unsigned long address, |
| 93 | struct task_struct *tsk, |
| 94 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | if ((unsigned long) address < PAGE_SIZE) { |
| 97 | printk(KERN_ALERT "Unable to handle kernel NULL " |
| 98 | "pointer dereference\n"); |
| 99 | } else { |
| 100 | printk(KERN_ALERT "Unable to handle kernel paging request " |
| 101 | "at virtual address %016lx\n", (unsigned long)address); |
| 102 | } |
| 103 | printk(KERN_ALERT "tsk->{mm,active_mm}->context = %016lx\n", |
| 104 | (tsk->mm ? |
| 105 | CTX_HWBITS(tsk->mm->context) : |
| 106 | CTX_HWBITS(tsk->active_mm->context))); |
| 107 | printk(KERN_ALERT "tsk->{mm,active_mm}->pgd = %016lx\n", |
| 108 | (tsk->mm ? (unsigned long) tsk->mm->pgd : |
| 109 | (unsigned long) tsk->active_mm->pgd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | die_if_kernel("Oops", regs); |
| 111 | } |
| 112 | |
David S. Miller | bf941d6 | 2006-02-13 18:07:45 -0800 | [diff] [blame] | 113 | static void bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 115 | unsigned long *ksp; |
| 116 | |
| 117 | printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n", |
| 118 | regs->tpc); |
David S. Miller | eb398d1 | 2006-07-22 01:12:09 -0700 | [diff] [blame] | 119 | printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]); |
| 120 | print_symbol("RPC: <%s>\n", regs->u_regs[15]); |
David S. Miller | bf941d6 | 2006-02-13 18:07:45 -0800 | [diff] [blame] | 121 | printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | __asm__("mov %%sp, %0" : "=r" (ksp)); |
| 123 | show_stack(current, ksp); |
| 124 | unhandled_fault(regs->tpc, current, regs); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * We now make sure that mmap_sem is held in all paths that call |
| 129 | * this. Additionally, to prevent kswapd from ripping ptes from |
| 130 | * under us, raise interrupts around the time that we look at the |
| 131 | * pte, kswapd will have to wait to get his smp ipi response from |
Hugh Dickins | da16054 | 2005-11-08 10:00:55 -0800 | [diff] [blame] | 132 | * us. vmtruncate likewise. This saves us having to get pte lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | */ |
| 134 | static unsigned int get_user_insn(unsigned long tpc) |
| 135 | { |
| 136 | pgd_t *pgdp = pgd_offset(current->mm, tpc); |
| 137 | pud_t *pudp; |
| 138 | pmd_t *pmdp; |
| 139 | pte_t *ptep, pte; |
| 140 | unsigned long pa; |
| 141 | u32 insn = 0; |
| 142 | unsigned long pstate; |
| 143 | |
| 144 | if (pgd_none(*pgdp)) |
| 145 | goto outret; |
| 146 | pudp = pud_offset(pgdp, tpc); |
| 147 | if (pud_none(*pudp)) |
| 148 | goto outret; |
| 149 | pmdp = pmd_offset(pudp, tpc); |
| 150 | if (pmd_none(*pmdp)) |
| 151 | goto outret; |
| 152 | |
| 153 | /* This disables preemption for us as well. */ |
| 154 | __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate)); |
| 155 | __asm__ __volatile__("wrpr %0, %1, %%pstate" |
| 156 | : : "r" (pstate), "i" (PSTATE_IE)); |
| 157 | ptep = pte_offset_map(pmdp, tpc); |
| 158 | pte = *ptep; |
| 159 | if (!pte_present(pte)) |
| 160 | goto out; |
| 161 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 162 | pa = (pte_pfn(pte) << PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | pa += (tpc & ~PAGE_MASK); |
| 164 | |
| 165 | /* Use phys bypass so we don't pollute dtlb/dcache. */ |
| 166 | __asm__ __volatile__("lduwa [%1] %2, %0" |
| 167 | : "=r" (insn) |
| 168 | : "r" (pa), "i" (ASI_PHYS_USE_EC)); |
| 169 | |
| 170 | out: |
| 171 | pte_unmap(ptep); |
| 172 | __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate)); |
| 173 | outret: |
| 174 | return insn; |
| 175 | } |
| 176 | |
| 177 | extern unsigned long compute_effective_address(struct pt_regs *, unsigned int, unsigned int); |
| 178 | |
| 179 | static void do_fault_siginfo(int code, int sig, struct pt_regs *regs, |
| 180 | unsigned int insn, int fault_code) |
| 181 | { |
| 182 | siginfo_t info; |
| 183 | |
| 184 | info.si_code = code; |
| 185 | info.si_signo = sig; |
| 186 | info.si_errno = 0; |
| 187 | if (fault_code & FAULT_CODE_ITLB) |
| 188 | info.si_addr = (void __user *) regs->tpc; |
| 189 | else |
| 190 | info.si_addr = (void __user *) |
| 191 | compute_effective_address(regs, insn, 0); |
| 192 | info.si_trapno = 0; |
| 193 | force_sig_info(sig, &info, current); |
| 194 | } |
| 195 | |
| 196 | extern int handle_ldf_stq(u32, struct pt_regs *); |
| 197 | extern int handle_ld_nf(u32, struct pt_regs *); |
| 198 | |
| 199 | static unsigned int get_fault_insn(struct pt_regs *regs, unsigned int insn) |
| 200 | { |
| 201 | if (!insn) { |
| 202 | if (!regs->tpc || (regs->tpc & 0x3)) |
| 203 | return 0; |
| 204 | if (regs->tstate & TSTATE_PRIV) { |
| 205 | insn = *(unsigned int *) regs->tpc; |
| 206 | } else { |
| 207 | insn = get_user_insn(regs->tpc); |
| 208 | } |
| 209 | } |
| 210 | return insn; |
| 211 | } |
| 212 | |
| 213 | static void do_kernel_fault(struct pt_regs *regs, int si_code, int fault_code, |
| 214 | unsigned int insn, unsigned long address) |
| 215 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | unsigned char asi = ASI_P; |
| 217 | |
| 218 | if ((!insn) && (regs->tstate & TSTATE_PRIV)) |
| 219 | goto cannot_handle; |
| 220 | |
| 221 | /* If user insn could be read (thus insn is zero), that |
| 222 | * is fine. We will just gun down the process with a signal |
| 223 | * in that case. |
| 224 | */ |
| 225 | |
| 226 | if (!(fault_code & (FAULT_CODE_WRITE|FAULT_CODE_ITLB)) && |
| 227 | (insn & 0xc0800000) == 0xc0800000) { |
| 228 | if (insn & 0x2000) |
| 229 | asi = (regs->tstate >> 24); |
| 230 | else |
| 231 | asi = (insn >> 5); |
| 232 | if ((asi & 0xf2) == 0x82) { |
| 233 | if (insn & 0x1000000) { |
| 234 | handle_ldf_stq(insn, regs); |
| 235 | } else { |
| 236 | /* This was a non-faulting load. Just clear the |
| 237 | * destination register(s) and continue with the next |
| 238 | * instruction. -jj |
| 239 | */ |
| 240 | handle_ld_nf(insn, regs); |
| 241 | } |
| 242 | return; |
| 243 | } |
| 244 | } |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | /* Is this in ex_table? */ |
| 247 | if (regs->tstate & TSTATE_PRIV) { |
David S. Miller | 8cf14af | 2005-09-28 20:21:11 -0700 | [diff] [blame] | 248 | const struct exception_table_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | if (asi == ASI_P && (insn & 0xc0800000) == 0xc0800000) { |
| 251 | if (insn & 0x2000) |
| 252 | asi = (regs->tstate >> 24); |
| 253 | else |
| 254 | asi = (insn >> 5); |
| 255 | } |
| 256 | |
| 257 | /* Look in asi.h: All _S asis have LS bit set */ |
| 258 | if ((asi & 0x1) && |
David S. Miller | 8cf14af | 2005-09-28 20:21:11 -0700 | [diff] [blame] | 259 | (entry = search_exception_tables(regs->tpc))) { |
| 260 | regs->tpc = entry->fixup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | regs->tnpc = regs->tpc + 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return; |
| 263 | } |
| 264 | } else { |
| 265 | /* The si_code was set to make clear whether |
| 266 | * this was a SEGV_MAPERR or SEGV_ACCERR fault. |
| 267 | */ |
| 268 | do_fault_siginfo(si_code, SIGSEGV, regs, insn, fault_code); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | cannot_handle: |
| 273 | unhandled_fault (address, current, regs); |
| 274 | } |
| 275 | |
Prasanna S Panchamukhi | 05e14cb | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 276 | asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | struct mm_struct *mm = current->mm; |
| 279 | struct vm_area_struct *vma; |
| 280 | unsigned int insn = 0; |
| 281 | int si_code, fault_code; |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 282 | unsigned long address, mm_rss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | fault_code = get_thread_fault_code(); |
| 285 | |
David S. Miller | 127cda1 | 2007-05-08 18:25:14 -0700 | [diff] [blame^] | 286 | if (notify_page_fault(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return; |
| 288 | |
| 289 | si_code = SEGV_MAPERR; |
| 290 | address = current_thread_info()->fault_address; |
| 291 | |
| 292 | if ((fault_code & FAULT_CODE_ITLB) && |
| 293 | (fault_code & FAULT_CODE_DTLB)) |
| 294 | BUG(); |
| 295 | |
| 296 | if (regs->tstate & TSTATE_PRIV) { |
| 297 | unsigned long tpc = regs->tpc; |
| 298 | |
| 299 | /* Sanity check the PC. */ |
| 300 | if ((tpc >= KERNBASE && tpc < (unsigned long) _etext) || |
| 301 | (tpc >= MODULES_VADDR && tpc < MODULES_END)) { |
| 302 | /* Valid, no problems... */ |
| 303 | } else { |
David S. Miller | bf941d6 | 2006-02-13 18:07:45 -0800 | [diff] [blame] | 304 | bad_kernel_pc(regs, address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * If we're in an interrupt or have no user |
| 311 | * context, we must not take the fault.. |
| 312 | */ |
| 313 | if (in_atomic() || !mm) |
| 314 | goto intr_or_no_mm; |
| 315 | |
| 316 | if (test_thread_flag(TIF_32BIT)) { |
| 317 | if (!(regs->tstate & TSTATE_PRIV)) |
| 318 | regs->tpc &= 0xffffffff; |
| 319 | address &= 0xffffffff; |
| 320 | } |
| 321 | |
| 322 | if (!down_read_trylock(&mm->mmap_sem)) { |
| 323 | if ((regs->tstate & TSTATE_PRIV) && |
| 324 | !search_exception_tables(regs->tpc)) { |
| 325 | insn = get_fault_insn(regs, insn); |
| 326 | goto handle_kernel_fault; |
| 327 | } |
| 328 | down_read(&mm->mmap_sem); |
| 329 | } |
| 330 | |
| 331 | vma = find_vma(mm, address); |
| 332 | if (!vma) |
| 333 | goto bad_area; |
| 334 | |
| 335 | /* Pure DTLB misses do not tell us whether the fault causing |
| 336 | * load/store/atomic was a write or not, it only says that there |
| 337 | * was no match. So in such a case we (carefully) read the |
| 338 | * instruction to try and figure this out. It's an optimization |
| 339 | * so it's ok if we can't do this. |
| 340 | * |
| 341 | * Special hack, window spill/fill knows the exact fault type. |
| 342 | */ |
| 343 | if (((fault_code & |
| 344 | (FAULT_CODE_DTLB | FAULT_CODE_WRITE | FAULT_CODE_WINFIXUP)) == FAULT_CODE_DTLB) && |
| 345 | (vma->vm_flags & VM_WRITE) != 0) { |
| 346 | insn = get_fault_insn(regs, 0); |
| 347 | if (!insn) |
| 348 | goto continue_fault; |
David S. Miller | 73c50a2 | 2006-03-28 13:32:24 -0800 | [diff] [blame] | 349 | /* All loads, stores and atomics have bits 30 and 31 both set |
| 350 | * in the instruction. Bit 21 is set in all stores, but we |
| 351 | * have to avoid prefetches which also have bit 21 set. |
| 352 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if ((insn & 0xc0200000) == 0xc0200000 && |
David S. Miller | 73c50a2 | 2006-03-28 13:32:24 -0800 | [diff] [blame] | 354 | (insn & 0x01780000) != 0x01680000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | /* Don't bother updating thread struct value, |
| 356 | * because update_mmu_cache only cares which tlb |
| 357 | * the access came from. |
| 358 | */ |
| 359 | fault_code |= FAULT_CODE_WRITE; |
| 360 | } |
| 361 | } |
| 362 | continue_fault: |
| 363 | |
| 364 | if (vma->vm_start <= address) |
| 365 | goto good_area; |
| 366 | if (!(vma->vm_flags & VM_GROWSDOWN)) |
| 367 | goto bad_area; |
| 368 | if (!(fault_code & FAULT_CODE_WRITE)) { |
| 369 | /* Non-faulting loads shouldn't expand stack. */ |
| 370 | insn = get_fault_insn(regs, insn); |
| 371 | if ((insn & 0xc0800000) == 0xc0800000) { |
| 372 | unsigned char asi; |
| 373 | |
| 374 | if (insn & 0x2000) |
| 375 | asi = (regs->tstate >> 24); |
| 376 | else |
| 377 | asi = (insn >> 5); |
| 378 | if ((asi & 0xf2) == 0x82) |
| 379 | goto bad_area; |
| 380 | } |
| 381 | } |
| 382 | if (expand_stack(vma, address)) |
| 383 | goto bad_area; |
| 384 | /* |
| 385 | * Ok, we have a good vm_area for this memory access, so |
| 386 | * we can handle it.. |
| 387 | */ |
| 388 | good_area: |
| 389 | si_code = SEGV_ACCERR; |
| 390 | |
| 391 | /* If we took a ITLB miss on a non-executable page, catch |
| 392 | * that here. |
| 393 | */ |
| 394 | if ((fault_code & FAULT_CODE_ITLB) && !(vma->vm_flags & VM_EXEC)) { |
| 395 | BUG_ON(address != regs->tpc); |
| 396 | BUG_ON(regs->tstate & TSTATE_PRIV); |
| 397 | goto bad_area; |
| 398 | } |
| 399 | |
| 400 | if (fault_code & FAULT_CODE_WRITE) { |
| 401 | if (!(vma->vm_flags & VM_WRITE)) |
| 402 | goto bad_area; |
| 403 | |
| 404 | /* Spitfire has an icache which does not snoop |
| 405 | * processor stores. Later processors do... |
| 406 | */ |
| 407 | if (tlb_type == spitfire && |
| 408 | (vma->vm_flags & VM_EXEC) != 0 && |
| 409 | vma->vm_file != NULL) |
| 410 | set_thread_fault_code(fault_code | |
| 411 | FAULT_CODE_BLKCOMMIT); |
| 412 | } else { |
| 413 | /* Allow reads even for write-only mappings */ |
| 414 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) |
| 415 | goto bad_area; |
| 416 | } |
| 417 | |
| 418 | switch (handle_mm_fault(mm, vma, address, (fault_code & FAULT_CODE_WRITE))) { |
| 419 | case VM_FAULT_MINOR: |
| 420 | current->min_flt++; |
| 421 | break; |
| 422 | case VM_FAULT_MAJOR: |
| 423 | current->maj_flt++; |
| 424 | break; |
| 425 | case VM_FAULT_SIGBUS: |
| 426 | goto do_sigbus; |
| 427 | case VM_FAULT_OOM: |
| 428 | goto out_of_memory; |
| 429 | default: |
| 430 | BUG(); |
| 431 | } |
| 432 | |
| 433 | up_read(&mm->mmap_sem); |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 434 | |
| 435 | mm_rss = get_mm_rss(mm); |
David S. Miller | dcc1e8d | 2006-03-22 00:49:59 -0800 | [diff] [blame] | 436 | #ifdef CONFIG_HUGETLB_PAGE |
| 437 | mm_rss -= (mm->context.huge_pte_count * (HPAGE_SIZE / PAGE_SIZE)); |
| 438 | #endif |
David S. Miller | 7bebd83 | 2006-03-27 01:07:55 -0800 | [diff] [blame] | 439 | if (unlikely(mm_rss > |
David S. Miller | dcc1e8d | 2006-03-22 00:49:59 -0800 | [diff] [blame] | 440 | mm->context.tsb_block[MM_TSB_BASE].tsb_rss_limit)) |
| 441 | tsb_grow(mm, MM_TSB_BASE, mm_rss); |
| 442 | #ifdef CONFIG_HUGETLB_PAGE |
| 443 | mm_rss = mm->context.huge_pte_count; |
David S. Miller | 7bebd83 | 2006-03-27 01:07:55 -0800 | [diff] [blame] | 444 | if (unlikely(mm_rss > |
David S. Miller | dcc1e8d | 2006-03-22 00:49:59 -0800 | [diff] [blame] | 445 | mm->context.tsb_block[MM_TSB_HUGE].tsb_rss_limit)) |
| 446 | tsb_grow(mm, MM_TSB_HUGE, mm_rss); |
| 447 | #endif |
David S. Miller | efdc1e2 | 2005-09-28 21:06:47 -0700 | [diff] [blame] | 448 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | /* |
| 451 | * Something tried to access memory that isn't in our memory map.. |
| 452 | * Fix it, but check if it's kernel or user first.. |
| 453 | */ |
| 454 | bad_area: |
| 455 | insn = get_fault_insn(regs, insn); |
| 456 | up_read(&mm->mmap_sem); |
| 457 | |
| 458 | handle_kernel_fault: |
| 459 | do_kernel_fault(regs, si_code, fault_code, insn, address); |
David S. Miller | efdc1e2 | 2005-09-28 21:06:47 -0700 | [diff] [blame] | 460 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
| 462 | /* |
| 463 | * We ran out of memory, or some other thing happened to us that made |
| 464 | * us unable to handle the page fault gracefully. |
| 465 | */ |
| 466 | out_of_memory: |
| 467 | insn = get_fault_insn(regs, insn); |
| 468 | up_read(&mm->mmap_sem); |
| 469 | printk("VM: killing process %s\n", current->comm); |
| 470 | if (!(regs->tstate & TSTATE_PRIV)) |
| 471 | do_exit(SIGKILL); |
| 472 | goto handle_kernel_fault; |
| 473 | |
| 474 | intr_or_no_mm: |
| 475 | insn = get_fault_insn(regs, 0); |
| 476 | goto handle_kernel_fault; |
| 477 | |
| 478 | do_sigbus: |
| 479 | insn = get_fault_insn(regs, insn); |
| 480 | up_read(&mm->mmap_sem); |
| 481 | |
| 482 | /* |
| 483 | * Send a sigbus, regardless of whether we were in kernel |
| 484 | * or user mode. |
| 485 | */ |
| 486 | do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, insn, fault_code); |
| 487 | |
| 488 | /* Kernel mode? Handle exceptions or die */ |
| 489 | if (regs->tstate & TSTATE_PRIV) |
| 490 | goto handle_kernel_fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |