Commit 6e346228c76506e07e297744a28464022c6806ad
1 parent
968002166c
Exists in
master
and in
7 other branches
It wasn't just x86-64 that had hardcoded VM_FAULT_xxx numbers
Fix up arm26, cris, frv, m68k, parisc and sh64 too..
Showing 6 changed files with 25 additions and 28 deletions Inline Diff
arch/arm26/mm/fault.c
1 | /* | 1 | /* |
2 | * linux/arch/arm26/mm/fault.c | 2 | * linux/arch/arm26/mm/fault.c |
3 | * | 3 | * |
4 | * Copyright (C) 1995 Linus Torvalds | 4 | * Copyright (C) 1995 Linus Torvalds |
5 | * Modifications for ARM processor (c) 1995-2001 Russell King | 5 | * Modifications for ARM processor (c) 1995-2001 Russell King |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | #include <linux/config.h> | 11 | #include <linux/config.h> |
12 | #include <linux/signal.h> | 12 | #include <linux/signal.h> |
13 | #include <linux/sched.h> | 13 | #include <linux/sched.h> |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/types.h> | 17 | #include <linux/types.h> |
18 | #include <linux/ptrace.h> | 18 | #include <linux/ptrace.h> |
19 | #include <linux/mman.h> | 19 | #include <linux/mman.h> |
20 | #include <linux/mm.h> | 20 | #include <linux/mm.h> |
21 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
22 | #include <linux/proc_fs.h> | 22 | #include <linux/proc_fs.h> |
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | 24 | ||
25 | #include <asm/system.h> | 25 | #include <asm/system.h> |
26 | #include <asm/pgtable.h> | 26 | #include <asm/pgtable.h> |
27 | #include <asm/uaccess.h> //FIXME this header may be bogusly included | 27 | #include <asm/uaccess.h> //FIXME this header may be bogusly included |
28 | 28 | ||
29 | #include "fault.h" | 29 | #include "fault.h" |
30 | 30 | ||
31 | #define FAULT_CODE_LDRSTRPOST 0x80 | 31 | #define FAULT_CODE_LDRSTRPOST 0x80 |
32 | #define FAULT_CODE_LDRSTRPRE 0x40 | 32 | #define FAULT_CODE_LDRSTRPRE 0x40 |
33 | #define FAULT_CODE_LDRSTRREG 0x20 | 33 | #define FAULT_CODE_LDRSTRREG 0x20 |
34 | #define FAULT_CODE_LDMSTM 0x10 | 34 | #define FAULT_CODE_LDMSTM 0x10 |
35 | #define FAULT_CODE_LDCSTC 0x08 | 35 | #define FAULT_CODE_LDCSTC 0x08 |
36 | #define FAULT_CODE_PREFETCH 0x04 | 36 | #define FAULT_CODE_PREFETCH 0x04 |
37 | #define FAULT_CODE_WRITE 0x02 | 37 | #define FAULT_CODE_WRITE 0x02 |
38 | #define FAULT_CODE_FORCECOW 0x01 | 38 | #define FAULT_CODE_FORCECOW 0x01 |
39 | 39 | ||
40 | #define DO_COW(m) ((m) & (FAULT_CODE_WRITE|FAULT_CODE_FORCECOW)) | 40 | #define DO_COW(m) ((m) & (FAULT_CODE_WRITE|FAULT_CODE_FORCECOW)) |
41 | #define READ_FAULT(m) (!((m) & FAULT_CODE_WRITE)) | 41 | #define READ_FAULT(m) (!((m) & FAULT_CODE_WRITE)) |
42 | #define DEBUG | 42 | #define DEBUG |
43 | /* | 43 | /* |
44 | * This is useful to dump out the page tables associated with | 44 | * This is useful to dump out the page tables associated with |
45 | * 'addr' in mm 'mm'. | 45 | * 'addr' in mm 'mm'. |
46 | */ | 46 | */ |
47 | void show_pte(struct mm_struct *mm, unsigned long addr) | 47 | void show_pte(struct mm_struct *mm, unsigned long addr) |
48 | { | 48 | { |
49 | pgd_t *pgd; | 49 | pgd_t *pgd; |
50 | 50 | ||
51 | if (!mm) | 51 | if (!mm) |
52 | mm = &init_mm; | 52 | mm = &init_mm; |
53 | 53 | ||
54 | printk(KERN_ALERT "pgd = %p\n", mm->pgd); | 54 | printk(KERN_ALERT "pgd = %p\n", mm->pgd); |
55 | pgd = pgd_offset(mm, addr); | 55 | pgd = pgd_offset(mm, addr); |
56 | printk(KERN_ALERT "[%08lx] *pgd=%08lx", addr, pgd_val(*pgd)); | 56 | printk(KERN_ALERT "[%08lx] *pgd=%08lx", addr, pgd_val(*pgd)); |
57 | 57 | ||
58 | do { | 58 | do { |
59 | pmd_t *pmd; | 59 | pmd_t *pmd; |
60 | pte_t *pte; | 60 | pte_t *pte; |
61 | 61 | ||
62 | pmd = pmd_offset(pgd, addr); | 62 | pmd = pmd_offset(pgd, addr); |
63 | 63 | ||
64 | if (pmd_none(*pmd)) | 64 | if (pmd_none(*pmd)) |
65 | break; | 65 | break; |
66 | 66 | ||
67 | if (pmd_bad(*pmd)) { | 67 | if (pmd_bad(*pmd)) { |
68 | printk("(bad)"); | 68 | printk("(bad)"); |
69 | break; | 69 | break; |
70 | } | 70 | } |
71 | 71 | ||
72 | /* We must not map this if we have highmem enabled */ | 72 | /* We must not map this if we have highmem enabled */ |
73 | /* FIXME */ | 73 | /* FIXME */ |
74 | pte = pte_offset_map(pmd, addr); | 74 | pte = pte_offset_map(pmd, addr); |
75 | printk(", *pte=%08lx", pte_val(*pte)); | 75 | printk(", *pte=%08lx", pte_val(*pte)); |
76 | pte_unmap(pte); | 76 | pte_unmap(pte); |
77 | } while(0); | 77 | } while(0); |
78 | 78 | ||
79 | printk("\n"); | 79 | printk("\n"); |
80 | } | 80 | } |
81 | 81 | ||
82 | /* | 82 | /* |
83 | * Oops. The kernel tried to access some page that wasn't present. | 83 | * Oops. The kernel tried to access some page that wasn't present. |
84 | */ | 84 | */ |
85 | static void | 85 | static void |
86 | __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, | 86 | __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, |
87 | struct pt_regs *regs) | 87 | struct pt_regs *regs) |
88 | { | 88 | { |
89 | /* | 89 | /* |
90 | * Are we prepared to handle this kernel fault? | 90 | * Are we prepared to handle this kernel fault? |
91 | */ | 91 | */ |
92 | if (fixup_exception(regs)) | 92 | if (fixup_exception(regs)) |
93 | return; | 93 | return; |
94 | 94 | ||
95 | /* | 95 | /* |
96 | * No handler, we'll have to terminate things with extreme prejudice. | 96 | * No handler, we'll have to terminate things with extreme prejudice. |
97 | */ | 97 | */ |
98 | bust_spinlocks(1); | 98 | bust_spinlocks(1); |
99 | printk(KERN_ALERT | 99 | printk(KERN_ALERT |
100 | "Unable to handle kernel %s at virtual address %08lx\n", | 100 | "Unable to handle kernel %s at virtual address %08lx\n", |
101 | (addr < PAGE_SIZE) ? "NULL pointer dereference" : | 101 | (addr < PAGE_SIZE) ? "NULL pointer dereference" : |
102 | "paging request", addr); | 102 | "paging request", addr); |
103 | 103 | ||
104 | show_pte(mm, addr); | 104 | show_pte(mm, addr); |
105 | die("Oops", regs, fsr); | 105 | die("Oops", regs, fsr); |
106 | bust_spinlocks(0); | 106 | bust_spinlocks(0); |
107 | do_exit(SIGKILL); | 107 | do_exit(SIGKILL); |
108 | } | 108 | } |
109 | 109 | ||
110 | /* | 110 | /* |
111 | * Something tried to access memory that isn't in our memory map.. | 111 | * Something tried to access memory that isn't in our memory map.. |
112 | * User mode accesses just cause a SIGSEGV | 112 | * User mode accesses just cause a SIGSEGV |
113 | */ | 113 | */ |
114 | static void | 114 | static void |
115 | __do_user_fault(struct task_struct *tsk, unsigned long addr, | 115 | __do_user_fault(struct task_struct *tsk, unsigned long addr, |
116 | unsigned int fsr, int code, struct pt_regs *regs) | 116 | unsigned int fsr, int code, struct pt_regs *regs) |
117 | { | 117 | { |
118 | struct siginfo si; | 118 | struct siginfo si; |
119 | 119 | ||
120 | #ifdef CONFIG_DEBUG_USER | 120 | #ifdef CONFIG_DEBUG_USER |
121 | printk("%s: unhandled page fault at 0x%08lx, code 0x%03x\n", | 121 | printk("%s: unhandled page fault at 0x%08lx, code 0x%03x\n", |
122 | tsk->comm, addr, fsr); | 122 | tsk->comm, addr, fsr); |
123 | show_pte(tsk->mm, addr); | 123 | show_pte(tsk->mm, addr); |
124 | show_regs(regs); | 124 | show_regs(regs); |
125 | //dump_backtrace(regs, tsk); // FIXME ARM32 dropped this - why? | 125 | //dump_backtrace(regs, tsk); // FIXME ARM32 dropped this - why? |
126 | while(1); //FIXME - hack to stop debug going nutso | 126 | while(1); //FIXME - hack to stop debug going nutso |
127 | #endif | 127 | #endif |
128 | 128 | ||
129 | tsk->thread.address = addr; | 129 | tsk->thread.address = addr; |
130 | tsk->thread.error_code = fsr; | 130 | tsk->thread.error_code = fsr; |
131 | tsk->thread.trap_no = 14; | 131 | tsk->thread.trap_no = 14; |
132 | si.si_signo = SIGSEGV; | 132 | si.si_signo = SIGSEGV; |
133 | si.si_errno = 0; | 133 | si.si_errno = 0; |
134 | si.si_code = code; | 134 | si.si_code = code; |
135 | si.si_addr = (void *)addr; | 135 | si.si_addr = (void *)addr; |
136 | force_sig_info(SIGSEGV, &si, tsk); | 136 | force_sig_info(SIGSEGV, &si, tsk); |
137 | } | 137 | } |
138 | 138 | ||
139 | static int | 139 | static int |
140 | __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, | 140 | __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, |
141 | struct task_struct *tsk) | 141 | struct task_struct *tsk) |
142 | { | 142 | { |
143 | struct vm_area_struct *vma; | 143 | struct vm_area_struct *vma; |
144 | int fault, mask; | 144 | int fault, mask; |
145 | 145 | ||
146 | vma = find_vma(mm, addr); | 146 | vma = find_vma(mm, addr); |
147 | fault = -2; /* bad map area */ | 147 | fault = -2; /* bad map area */ |
148 | if (!vma) | 148 | if (!vma) |
149 | goto out; | 149 | goto out; |
150 | if (vma->vm_start > addr) | 150 | if (vma->vm_start > addr) |
151 | goto check_stack; | 151 | goto check_stack; |
152 | 152 | ||
153 | /* | 153 | /* |
154 | * Ok, we have a good vm_area for this | 154 | * Ok, we have a good vm_area for this |
155 | * memory access, so we can handle it. | 155 | * memory access, so we can handle it. |
156 | */ | 156 | */ |
157 | good_area: | 157 | good_area: |
158 | if (READ_FAULT(fsr)) /* read? */ | 158 | if (READ_FAULT(fsr)) /* read? */ |
159 | mask = VM_READ|VM_EXEC; | 159 | mask = VM_READ|VM_EXEC; |
160 | else | 160 | else |
161 | mask = VM_WRITE; | 161 | mask = VM_WRITE; |
162 | 162 | ||
163 | fault = -1; /* bad access type */ | 163 | fault = -1; /* bad access type */ |
164 | if (!(vma->vm_flags & mask)) | 164 | if (!(vma->vm_flags & mask)) |
165 | goto out; | 165 | goto out; |
166 | 166 | ||
167 | /* | 167 | /* |
168 | * If for any reason at all we couldn't handle | 168 | * If for any reason at all we couldn't handle |
169 | * the fault, make sure we exit gracefully rather | 169 | * the fault, make sure we exit gracefully rather |
170 | * than endlessly redo the fault. | 170 | * than endlessly redo the fault. |
171 | */ | 171 | */ |
172 | survive: | 172 | survive: |
173 | fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, DO_COW(fsr)); | 173 | fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, DO_COW(fsr)); |
174 | 174 | ||
175 | /* | 175 | /* |
176 | * Handle the "normal" cases first - successful and sigbus | 176 | * Handle the "normal" cases first - successful and sigbus |
177 | */ | 177 | */ |
178 | switch (fault) { | 178 | switch (fault) { |
179 | case 2: | 179 | case VM_FAULT_MAJOR: |
180 | tsk->maj_flt++; | 180 | tsk->maj_flt++; |
181 | return fault; | 181 | return fault; |
182 | case 1: | 182 | case VM_FAULT_MINOR: |
183 | tsk->min_flt++; | 183 | tsk->min_flt++; |
184 | case 0: | 184 | case VM_FAULT_SIGBUS: |
185 | return fault; | 185 | return fault; |
186 | } | 186 | } |
187 | 187 | ||
188 | fault = -3; /* out of memory */ | 188 | fault = -3; /* out of memory */ |
189 | if (tsk->pid != 1) | 189 | if (tsk->pid != 1) |
190 | goto out; | 190 | goto out; |
191 | 191 | ||
192 | /* | 192 | /* |
193 | * If we are out of memory for pid1, | 193 | * If we are out of memory for pid1, |
194 | * sleep for a while and retry | 194 | * sleep for a while and retry |
195 | */ | 195 | */ |
196 | yield(); | 196 | yield(); |
197 | goto survive; | 197 | goto survive; |
198 | 198 | ||
199 | check_stack: | 199 | check_stack: |
200 | if (vma->vm_flags & VM_GROWSDOWN && !expand_stack(vma, addr)) | 200 | if (vma->vm_flags & VM_GROWSDOWN && !expand_stack(vma, addr)) |
201 | goto good_area; | 201 | goto good_area; |
202 | out: | 202 | out: |
203 | return fault; | 203 | return fault; |
204 | } | 204 | } |
205 | 205 | ||
206 | int do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) | 206 | int do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) |
207 | { | 207 | { |
208 | struct task_struct *tsk; | 208 | struct task_struct *tsk; |
209 | struct mm_struct *mm; | 209 | struct mm_struct *mm; |
210 | int fault; | 210 | int fault; |
211 | 211 | ||
212 | tsk = current; | 212 | tsk = current; |
213 | mm = tsk->mm; | 213 | mm = tsk->mm; |
214 | 214 | ||
215 | /* | 215 | /* |
216 | * If we're in an interrupt or have no user | 216 | * If we're in an interrupt or have no user |
217 | * context, we must not take the fault.. | 217 | * context, we must not take the fault.. |
218 | */ | 218 | */ |
219 | if (in_interrupt() || !mm) | 219 | if (in_interrupt() || !mm) |
220 | goto no_context; | 220 | goto no_context; |
221 | 221 | ||
222 | down_read(&mm->mmap_sem); | 222 | down_read(&mm->mmap_sem); |
223 | fault = __do_page_fault(mm, addr, fsr, tsk); | 223 | fault = __do_page_fault(mm, addr, fsr, tsk); |
224 | up_read(&mm->mmap_sem); | 224 | up_read(&mm->mmap_sem); |
225 | 225 | ||
226 | /* | 226 | /* |
227 | * Handle the "normal" case first | 227 | * Handle the "normal" case first |
228 | */ | 228 | */ |
229 | if (fault > 0) | 229 | switch (fault) { |
230 | case VM_FAULT_MINOR: | ||
231 | case VM_FAULT_MAJOR: | ||
230 | return 0; | 232 | return 0; |
231 | 233 | case VM_FAULT_SIGBUS: | |
232 | /* | ||
233 | * We had some memory, but were unable to | ||
234 | * successfully fix up this page fault. | ||
235 | */ | ||
236 | if (fault == 0){ | ||
237 | goto do_sigbus; | 234 | goto do_sigbus; |
238 | } | 235 | } |
239 | 236 | ||
240 | /* | 237 | /* |
241 | * If we are in kernel mode at this point, we | 238 | * If we are in kernel mode at this point, we |
242 | * have no context to handle this fault with. | 239 | * have no context to handle this fault with. |
243 | * FIXME - is this test right? | 240 | * FIXME - is this test right? |
244 | */ | 241 | */ |
245 | if (!user_mode(regs)){ | 242 | if (!user_mode(regs)){ |
246 | goto no_context; | 243 | goto no_context; |
247 | } | 244 | } |
248 | 245 | ||
249 | if (fault == -3) { | 246 | if (fault == -3) { |
250 | /* | 247 | /* |
251 | * We ran out of memory, or some other thing happened to | 248 | * We ran out of memory, or some other thing happened to |
252 | * us that made us unable to handle the page fault gracefully. | 249 | * us that made us unable to handle the page fault gracefully. |
253 | */ | 250 | */ |
254 | printk("VM: killing process %s\n", tsk->comm); | 251 | printk("VM: killing process %s\n", tsk->comm); |
255 | do_exit(SIGKILL); | 252 | do_exit(SIGKILL); |
256 | } | 253 | } |
257 | else{ | 254 | else{ |
258 | __do_user_fault(tsk, addr, fsr, fault == -1 ? SEGV_ACCERR : SEGV_MAPERR, regs); | 255 | __do_user_fault(tsk, addr, fsr, fault == -1 ? SEGV_ACCERR : SEGV_MAPERR, regs); |
259 | } | 256 | } |
260 | 257 | ||
261 | return 0; | 258 | return 0; |
262 | 259 | ||
263 | 260 | ||
264 | /* | 261 | /* |
265 | * We ran out of memory, or some other thing happened to us that made | 262 | * We ran out of memory, or some other thing happened to us that made |
266 | * us unable to handle the page fault gracefully. | 263 | * us unable to handle the page fault gracefully. |
267 | */ | 264 | */ |
268 | do_sigbus: | 265 | do_sigbus: |
269 | /* | 266 | /* |
270 | * Send a sigbus, regardless of whether we were in kernel | 267 | * Send a sigbus, regardless of whether we were in kernel |
271 | * or user mode. | 268 | * or user mode. |
272 | */ | 269 | */ |
273 | tsk->thread.address = addr; //FIXME - need other bits setting? | 270 | tsk->thread.address = addr; //FIXME - need other bits setting? |
274 | tsk->thread.error_code = fsr; | 271 | tsk->thread.error_code = fsr; |
275 | tsk->thread.trap_no = 14; | 272 | tsk->thread.trap_no = 14; |
276 | force_sig(SIGBUS, tsk); | 273 | force_sig(SIGBUS, tsk); |
277 | #ifdef CONFIG_DEBUG_USER | 274 | #ifdef CONFIG_DEBUG_USER |
278 | printk(KERN_DEBUG "%s: sigbus at 0x%08lx, pc=0x%08lx\n", | 275 | printk(KERN_DEBUG "%s: sigbus at 0x%08lx, pc=0x%08lx\n", |
279 | current->comm, addr, instruction_pointer(regs)); | 276 | current->comm, addr, instruction_pointer(regs)); |
280 | #endif | 277 | #endif |
281 | 278 | ||
282 | /* Kernel mode? Handle exceptions or die */ | 279 | /* Kernel mode? Handle exceptions or die */ |
283 | if (user_mode(regs)) | 280 | if (user_mode(regs)) |
284 | return 0; | 281 | return 0; |
285 | 282 | ||
286 | no_context: | 283 | no_context: |
287 | __do_kernel_fault(mm, addr, fsr, regs); | 284 | __do_kernel_fault(mm, addr, fsr, regs); |
288 | return 0; | 285 | return 0; |
289 | } | 286 | } |
290 | 287 | ||
291 | /* | 288 | /* |
292 | * Handle a data abort. Note that we have to handle a range of addresses | 289 | * Handle a data abort. Note that we have to handle a range of addresses |
293 | * on ARM2/3 for ldm. If both pages are zero-mapped, then we have to force | 290 | * on ARM2/3 for ldm. If both pages are zero-mapped, then we have to force |
294 | * a copy-on-write. However, on the second page, we always force COW. | 291 | * a copy-on-write. However, on the second page, we always force COW. |
295 | */ | 292 | */ |
296 | asmlinkage void | 293 | asmlinkage void |
297 | do_DataAbort(unsigned long min_addr, unsigned long max_addr, int mode, struct pt_regs *regs) | 294 | do_DataAbort(unsigned long min_addr, unsigned long max_addr, int mode, struct pt_regs *regs) |
298 | { | 295 | { |
299 | do_page_fault(min_addr, mode, regs); | 296 | do_page_fault(min_addr, mode, regs); |
300 | 297 | ||
301 | if ((min_addr ^ max_addr) >> PAGE_SHIFT){ | 298 | if ((min_addr ^ max_addr) >> PAGE_SHIFT){ |
302 | do_page_fault(max_addr, mode | FAULT_CODE_FORCECOW, regs); | 299 | do_page_fault(max_addr, mode | FAULT_CODE_FORCECOW, regs); |
303 | } | 300 | } |
304 | } | 301 | } |
305 | 302 | ||
306 | asmlinkage int | 303 | asmlinkage int |
307 | do_PrefetchAbort(unsigned long addr, struct pt_regs *regs) | 304 | do_PrefetchAbort(unsigned long addr, struct pt_regs *regs) |
308 | { | 305 | { |
309 | #if 0 | 306 | #if 0 |
310 | if (the memc mapping for this page exists) { | 307 | if (the memc mapping for this page exists) { |
311 | printk ("Page in, but got abort (undefined instruction?)\n"); | 308 | printk ("Page in, but got abort (undefined instruction?)\n"); |
312 | return 0; | 309 | return 0; |
313 | } | 310 | } |
314 | #endif | 311 | #endif |
315 | do_page_fault(addr, FAULT_CODE_PREFETCH, regs); | 312 | do_page_fault(addr, FAULT_CODE_PREFETCH, regs); |
316 | return 1; | 313 | return 1; |
317 | } | 314 | } |
arch/cris/mm/fault.c
1 | /* | 1 | /* |
2 | * linux/arch/cris/mm/fault.c | 2 | * linux/arch/cris/mm/fault.c |
3 | * | 3 | * |
4 | * Copyright (C) 2000, 2001 Axis Communications AB | 4 | * Copyright (C) 2000, 2001 Axis Communications AB |
5 | * | 5 | * |
6 | * Authors: Bjorn Wesen | 6 | * Authors: Bjorn Wesen |
7 | * | 7 | * |
8 | * $Log: fault.c,v $ | 8 | * $Log: fault.c,v $ |
9 | * Revision 1.20 2005/03/04 08:16:18 starvik | 9 | * Revision 1.20 2005/03/04 08:16:18 starvik |
10 | * Merge of Linux 2.6.11. | 10 | * Merge of Linux 2.6.11. |
11 | * | 11 | * |
12 | * Revision 1.19 2005/01/14 10:07:59 starvik | 12 | * Revision 1.19 2005/01/14 10:07:59 starvik |
13 | * Fixed warning. | 13 | * Fixed warning. |
14 | * | 14 | * |
15 | * Revision 1.18 2005/01/12 08:10:14 starvik | 15 | * Revision 1.18 2005/01/12 08:10:14 starvik |
16 | * Readded the change of frametype when handling kernel page fault fixup | 16 | * Readded the change of frametype when handling kernel page fault fixup |
17 | * for v10. This is necessary to avoid that the CPU remakes the faulting | 17 | * for v10. This is necessary to avoid that the CPU remakes the faulting |
18 | * access. | 18 | * access. |
19 | * | 19 | * |
20 | * Revision 1.17 2005/01/11 13:53:05 starvik | 20 | * Revision 1.17 2005/01/11 13:53:05 starvik |
21 | * Use raw_printk. | 21 | * Use raw_printk. |
22 | * | 22 | * |
23 | * Revision 1.16 2004/12/17 11:39:41 starvik | 23 | * Revision 1.16 2004/12/17 11:39:41 starvik |
24 | * SMP support. | 24 | * SMP support. |
25 | * | 25 | * |
26 | * Revision 1.15 2004/11/23 18:36:18 starvik | 26 | * Revision 1.15 2004/11/23 18:36:18 starvik |
27 | * Stack is now non-executable. | 27 | * Stack is now non-executable. |
28 | * Signal handler trampolines are placed in a reserved page mapped into all | 28 | * Signal handler trampolines are placed in a reserved page mapped into all |
29 | * processes. | 29 | * processes. |
30 | * | 30 | * |
31 | * Revision 1.14 2004/11/23 07:10:21 starvik | 31 | * Revision 1.14 2004/11/23 07:10:21 starvik |
32 | * Moved find_fixup_code to generic code. | 32 | * Moved find_fixup_code to generic code. |
33 | * | 33 | * |
34 | * Revision 1.13 2004/11/23 07:00:54 starvik | 34 | * Revision 1.13 2004/11/23 07:00:54 starvik |
35 | * Actually use the execute permission bit in the MMU. This makes it possible | 35 | * Actually use the execute permission bit in the MMU. This makes it possible |
36 | * to prevent e.g. attacks where executable code is put on the stack. | 36 | * to prevent e.g. attacks where executable code is put on the stack. |
37 | * | 37 | * |
38 | * Revision 1.12 2004/09/29 06:16:04 starvik | 38 | * Revision 1.12 2004/09/29 06:16:04 starvik |
39 | * Use instruction_pointer | 39 | * Use instruction_pointer |
40 | * | 40 | * |
41 | * Revision 1.11 2004/05/14 07:58:05 starvik | 41 | * Revision 1.11 2004/05/14 07:58:05 starvik |
42 | * Merge of changes from 2.4 | 42 | * Merge of changes from 2.4 |
43 | * | 43 | * |
44 | * Revision 1.10 2003/10/27 14:51:24 starvik | 44 | * Revision 1.10 2003/10/27 14:51:24 starvik |
45 | * Removed debugcode | 45 | * Removed debugcode |
46 | * | 46 | * |
47 | * Revision 1.9 2003/10/27 14:50:42 starvik | 47 | * Revision 1.9 2003/10/27 14:50:42 starvik |
48 | * Changed do_page_fault signature | 48 | * Changed do_page_fault signature |
49 | * | 49 | * |
50 | * Revision 1.8 2003/07/04 13:02:48 tobiasa | 50 | * Revision 1.8 2003/07/04 13:02:48 tobiasa |
51 | * Moved code snippet from arch/cris/mm/fault.c that searches for fixup code | 51 | * Moved code snippet from arch/cris/mm/fault.c that searches for fixup code |
52 | * to seperate function in arch-specific files. | 52 | * to seperate function in arch-specific files. |
53 | * | 53 | * |
54 | * Revision 1.7 2003/01/22 06:48:38 starvik | 54 | * Revision 1.7 2003/01/22 06:48:38 starvik |
55 | * Fixed warnings issued by GCC 3.2.1 | 55 | * Fixed warnings issued by GCC 3.2.1 |
56 | * | 56 | * |
57 | * Revision 1.6 2003/01/09 14:42:52 starvik | 57 | * Revision 1.6 2003/01/09 14:42:52 starvik |
58 | * Merge of Linux 2.5.55 | 58 | * Merge of Linux 2.5.55 |
59 | * | 59 | * |
60 | * Revision 1.5 2002/12/11 14:44:48 starvik | 60 | * Revision 1.5 2002/12/11 14:44:48 starvik |
61 | * Extracted v10 (ETRAX 100LX) specific stuff to arch/cris/arch-v10/mm | 61 | * Extracted v10 (ETRAX 100LX) specific stuff to arch/cris/arch-v10/mm |
62 | * | 62 | * |
63 | * Revision 1.4 2002/11/13 15:10:28 starvik | 63 | * Revision 1.4 2002/11/13 15:10:28 starvik |
64 | * pte_offset has been renamed to pte_offset_kernel | 64 | * pte_offset has been renamed to pte_offset_kernel |
65 | * | 65 | * |
66 | * Revision 1.3 2002/11/05 06:45:13 starvik | 66 | * Revision 1.3 2002/11/05 06:45:13 starvik |
67 | * Merge of Linux 2.5.45 | 67 | * Merge of Linux 2.5.45 |
68 | * | 68 | * |
69 | * Revision 1.2 2001/12/18 13:35:22 bjornw | 69 | * Revision 1.2 2001/12/18 13:35:22 bjornw |
70 | * Applied the 2.4.13->2.4.16 CRIS patch to 2.5.1 (is a copy of 2.4.15). | 70 | * Applied the 2.4.13->2.4.16 CRIS patch to 2.5.1 (is a copy of 2.4.15). |
71 | * | 71 | * |
72 | * Revision 1.20 2001/11/22 13:34:06 bjornw | 72 | * Revision 1.20 2001/11/22 13:34:06 bjornw |
73 | * * Bug workaround (LX TR89): force a rerun of the whole of an interrupted | 73 | * * Bug workaround (LX TR89): force a rerun of the whole of an interrupted |
74 | * unaligned write, because the second half of the write will be corrupted | 74 | * unaligned write, because the second half of the write will be corrupted |
75 | * otherwise. Affected unaligned writes spanning not-yet mapped pages. | 75 | * otherwise. Affected unaligned writes spanning not-yet mapped pages. |
76 | * * Optimization: use the wr_rd bit in R_MMU_CAUSE to know whether a miss | 76 | * * Optimization: use the wr_rd bit in R_MMU_CAUSE to know whether a miss |
77 | * was due to a read or a write (before we didn't know this until the next | 77 | * was due to a read or a write (before we didn't know this until the next |
78 | * restart of the interrupted instruction, thus wasting one fault-irq) | 78 | * restart of the interrupted instruction, thus wasting one fault-irq) |
79 | * | 79 | * |
80 | * Revision 1.19 2001/11/12 19:02:10 pkj | 80 | * Revision 1.19 2001/11/12 19:02:10 pkj |
81 | * Fixed compiler warnings. | 81 | * Fixed compiler warnings. |
82 | * | 82 | * |
83 | * Revision 1.18 2001/07/18 22:14:32 bjornw | 83 | * Revision 1.18 2001/07/18 22:14:32 bjornw |
84 | * Enable interrupts in the bulk of do_page_fault | 84 | * Enable interrupts in the bulk of do_page_fault |
85 | * | 85 | * |
86 | * Revision 1.17 2001/07/18 13:07:23 bjornw | 86 | * Revision 1.17 2001/07/18 13:07:23 bjornw |
87 | * * Detect non-existant PTE's in vmalloc pmd synchronization | 87 | * * Detect non-existant PTE's in vmalloc pmd synchronization |
88 | * * Remove comment about fast-paths for VMALLOC_START etc, because all that | 88 | * * Remove comment about fast-paths for VMALLOC_START etc, because all that |
89 | * was totally bogus anyway it turned out :) | 89 | * was totally bogus anyway it turned out :) |
90 | * * Fix detection of vmalloc-area synchronization | 90 | * * Fix detection of vmalloc-area synchronization |
91 | * * Add some comments | 91 | * * Add some comments |
92 | * | 92 | * |
93 | * Revision 1.16 2001/06/13 00:06:08 bjornw | 93 | * Revision 1.16 2001/06/13 00:06:08 bjornw |
94 | * current_pgd should be volatile | 94 | * current_pgd should be volatile |
95 | * | 95 | * |
96 | * Revision 1.15 2001/06/13 00:02:23 bjornw | 96 | * Revision 1.15 2001/06/13 00:02:23 bjornw |
97 | * Use a separate variable to store the current pgd to avoid races in schedule | 97 | * Use a separate variable to store the current pgd to avoid races in schedule |
98 | * | 98 | * |
99 | * Revision 1.14 2001/05/16 17:41:07 hp | 99 | * Revision 1.14 2001/05/16 17:41:07 hp |
100 | * Last comment tweak further tweaked. | 100 | * Last comment tweak further tweaked. |
101 | * | 101 | * |
102 | * Revision 1.13 2001/05/15 00:58:44 hp | 102 | * Revision 1.13 2001/05/15 00:58:44 hp |
103 | * Expand a bit on the comment why we compare address >= TASK_SIZE rather | 103 | * Expand a bit on the comment why we compare address >= TASK_SIZE rather |
104 | * than >= VMALLOC_START. | 104 | * than >= VMALLOC_START. |
105 | * | 105 | * |
106 | * Revision 1.12 2001/04/04 10:51:14 bjornw | 106 | * Revision 1.12 2001/04/04 10:51:14 bjornw |
107 | * mmap_sem is grabbed for reading | 107 | * mmap_sem is grabbed for reading |
108 | * | 108 | * |
109 | * Revision 1.11 2001/03/23 07:36:07 starvik | 109 | * Revision 1.11 2001/03/23 07:36:07 starvik |
110 | * Corrected according to review remarks | 110 | * Corrected according to review remarks |
111 | * | 111 | * |
112 | * Revision 1.10 2001/03/21 16:10:11 bjornw | 112 | * Revision 1.10 2001/03/21 16:10:11 bjornw |
113 | * CRIS_FRAME_FIXUP not needed anymore, use FRAME_NORMAL | 113 | * CRIS_FRAME_FIXUP not needed anymore, use FRAME_NORMAL |
114 | * | 114 | * |
115 | * Revision 1.9 2001/03/05 13:22:20 bjornw | 115 | * Revision 1.9 2001/03/05 13:22:20 bjornw |
116 | * Spell-fix and fix in vmalloc_fault handling | 116 | * Spell-fix and fix in vmalloc_fault handling |
117 | * | 117 | * |
118 | * Revision 1.8 2000/11/22 14:45:31 bjornw | 118 | * Revision 1.8 2000/11/22 14:45:31 bjornw |
119 | * * 2.4.0-test10 removed the set_pgdir instantaneous kernel global mapping | 119 | * * 2.4.0-test10 removed the set_pgdir instantaneous kernel global mapping |
120 | * into all processes. Instead we fill in the missing PTE entries on demand. | 120 | * into all processes. Instead we fill in the missing PTE entries on demand. |
121 | * | 121 | * |
122 | * Revision 1.7 2000/11/21 16:39:09 bjornw | 122 | * Revision 1.7 2000/11/21 16:39:09 bjornw |
123 | * fixup switches frametype | 123 | * fixup switches frametype |
124 | * | 124 | * |
125 | * Revision 1.6 2000/11/17 16:54:08 bjornw | 125 | * Revision 1.6 2000/11/17 16:54:08 bjornw |
126 | * More detailed siginfo reporting | 126 | * More detailed siginfo reporting |
127 | * | 127 | * |
128 | * | 128 | * |
129 | */ | 129 | */ |
130 | 130 | ||
131 | #include <linux/mm.h> | 131 | #include <linux/mm.h> |
132 | #include <linux/interrupt.h> | 132 | #include <linux/interrupt.h> |
133 | #include <linux/module.h> | 133 | #include <linux/module.h> |
134 | #include <asm/uaccess.h> | 134 | #include <asm/uaccess.h> |
135 | 135 | ||
136 | extern int find_fixup_code(struct pt_regs *); | 136 | extern int find_fixup_code(struct pt_regs *); |
137 | extern void die_if_kernel(const char *, struct pt_regs *, long); | 137 | extern void die_if_kernel(const char *, struct pt_regs *, long); |
138 | extern int raw_printk(const char *fmt, ...); | 138 | extern int raw_printk(const char *fmt, ...); |
139 | 139 | ||
140 | /* debug of low-level TLB reload */ | 140 | /* debug of low-level TLB reload */ |
141 | #undef DEBUG | 141 | #undef DEBUG |
142 | 142 | ||
143 | #ifdef DEBUG | 143 | #ifdef DEBUG |
144 | #define D(x) x | 144 | #define D(x) x |
145 | #else | 145 | #else |
146 | #define D(x) | 146 | #define D(x) |
147 | #endif | 147 | #endif |
148 | 148 | ||
149 | /* debug of higher-level faults */ | 149 | /* debug of higher-level faults */ |
150 | #define DPG(x) | 150 | #define DPG(x) |
151 | 151 | ||
152 | /* current active page directory */ | 152 | /* current active page directory */ |
153 | 153 | ||
154 | volatile DEFINE_PER_CPU(pgd_t *,current_pgd); | 154 | volatile DEFINE_PER_CPU(pgd_t *,current_pgd); |
155 | unsigned long cris_signal_return_page; | 155 | unsigned long cris_signal_return_page; |
156 | 156 | ||
157 | /* | 157 | /* |
158 | * This routine handles page faults. It determines the address, | 158 | * This routine handles page faults. It determines the address, |
159 | * and the problem, and then passes it off to one of the appropriate | 159 | * and the problem, and then passes it off to one of the appropriate |
160 | * routines. | 160 | * routines. |
161 | * | 161 | * |
162 | * Notice that the address we're given is aligned to the page the fault | 162 | * Notice that the address we're given is aligned to the page the fault |
163 | * occurred in, since we only get the PFN in R_MMU_CAUSE not the complete | 163 | * occurred in, since we only get the PFN in R_MMU_CAUSE not the complete |
164 | * address. | 164 | * address. |
165 | * | 165 | * |
166 | * error_code: | 166 | * error_code: |
167 | * bit 0 == 0 means no page found, 1 means protection fault | 167 | * bit 0 == 0 means no page found, 1 means protection fault |
168 | * bit 1 == 0 means read, 1 means write | 168 | * bit 1 == 0 means read, 1 means write |
169 | * | 169 | * |
170 | * If this routine detects a bad access, it returns 1, otherwise it | 170 | * If this routine detects a bad access, it returns 1, otherwise it |
171 | * returns 0. | 171 | * returns 0. |
172 | */ | 172 | */ |
173 | 173 | ||
174 | asmlinkage void | 174 | asmlinkage void |
175 | do_page_fault(unsigned long address, struct pt_regs *regs, | 175 | do_page_fault(unsigned long address, struct pt_regs *regs, |
176 | int protection, int writeaccess) | 176 | int protection, int writeaccess) |
177 | { | 177 | { |
178 | struct task_struct *tsk; | 178 | struct task_struct *tsk; |
179 | struct mm_struct *mm; | 179 | struct mm_struct *mm; |
180 | struct vm_area_struct * vma; | 180 | struct vm_area_struct * vma; |
181 | siginfo_t info; | 181 | siginfo_t info; |
182 | 182 | ||
183 | D(printk("Page fault for %lX on %X at %lX, prot %d write %d\n", | 183 | D(printk("Page fault for %lX on %X at %lX, prot %d write %d\n", |
184 | address, smp_processor_id(), instruction_pointer(regs), | 184 | address, smp_processor_id(), instruction_pointer(regs), |
185 | protection, writeaccess)); | 185 | protection, writeaccess)); |
186 | 186 | ||
187 | tsk = current; | 187 | tsk = current; |
188 | 188 | ||
189 | /* | 189 | /* |
190 | * We fault-in kernel-space virtual memory on-demand. The | 190 | * We fault-in kernel-space virtual memory on-demand. The |
191 | * 'reference' page table is init_mm.pgd. | 191 | * 'reference' page table is init_mm.pgd. |
192 | * | 192 | * |
193 | * NOTE! We MUST NOT take any locks for this case. We may | 193 | * NOTE! We MUST NOT take any locks for this case. We may |
194 | * be in an interrupt or a critical region, and should | 194 | * be in an interrupt or a critical region, and should |
195 | * only copy the information from the master page table, | 195 | * only copy the information from the master page table, |
196 | * nothing more. | 196 | * nothing more. |
197 | * | 197 | * |
198 | * NOTE2: This is done so that, when updating the vmalloc | 198 | * NOTE2: This is done so that, when updating the vmalloc |
199 | * mappings we don't have to walk all processes pgdirs and | 199 | * mappings we don't have to walk all processes pgdirs and |
200 | * add the high mappings all at once. Instead we do it as they | 200 | * add the high mappings all at once. Instead we do it as they |
201 | * are used. However vmalloc'ed page entries have the PAGE_GLOBAL | 201 | * are used. However vmalloc'ed page entries have the PAGE_GLOBAL |
202 | * bit set so sometimes the TLB can use a lingering entry. | 202 | * bit set so sometimes the TLB can use a lingering entry. |
203 | * | 203 | * |
204 | * This verifies that the fault happens in kernel space | 204 | * This verifies that the fault happens in kernel space |
205 | * and that the fault was not a protection error (error_code & 1). | 205 | * and that the fault was not a protection error (error_code & 1). |
206 | */ | 206 | */ |
207 | 207 | ||
208 | if (address >= VMALLOC_START && | 208 | if (address >= VMALLOC_START && |
209 | !protection && | 209 | !protection && |
210 | !user_mode(regs)) | 210 | !user_mode(regs)) |
211 | goto vmalloc_fault; | 211 | goto vmalloc_fault; |
212 | 212 | ||
213 | /* When stack execution is not allowed we store the signal | 213 | /* When stack execution is not allowed we store the signal |
214 | * trampolines in the reserved cris_signal_return_page. | 214 | * trampolines in the reserved cris_signal_return_page. |
215 | * Handle this in the exact same way as vmalloc (we know | 215 | * Handle this in the exact same way as vmalloc (we know |
216 | * that the mapping is there and is valid so no need to | 216 | * that the mapping is there and is valid so no need to |
217 | * call handle_mm_fault). | 217 | * call handle_mm_fault). |
218 | */ | 218 | */ |
219 | if (cris_signal_return_page && | 219 | if (cris_signal_return_page && |
220 | address == cris_signal_return_page && | 220 | address == cris_signal_return_page && |
221 | !protection && user_mode(regs)) | 221 | !protection && user_mode(regs)) |
222 | goto vmalloc_fault; | 222 | goto vmalloc_fault; |
223 | 223 | ||
224 | /* we can and should enable interrupts at this point */ | 224 | /* we can and should enable interrupts at this point */ |
225 | local_irq_enable(); | 225 | local_irq_enable(); |
226 | 226 | ||
227 | mm = tsk->mm; | 227 | mm = tsk->mm; |
228 | info.si_code = SEGV_MAPERR; | 228 | info.si_code = SEGV_MAPERR; |
229 | 229 | ||
230 | /* | 230 | /* |
231 | * If we're in an interrupt or have no user | 231 | * If we're in an interrupt or have no user |
232 | * context, we must not take the fault.. | 232 | * context, we must not take the fault.. |
233 | */ | 233 | */ |
234 | 234 | ||
235 | if (in_interrupt() || !mm) | 235 | if (in_interrupt() || !mm) |
236 | goto no_context; | 236 | goto no_context; |
237 | 237 | ||
238 | down_read(&mm->mmap_sem); | 238 | down_read(&mm->mmap_sem); |
239 | vma = find_vma(mm, address); | 239 | vma = find_vma(mm, address); |
240 | if (!vma) | 240 | if (!vma) |
241 | goto bad_area; | 241 | goto bad_area; |
242 | if (vma->vm_start <= address) | 242 | if (vma->vm_start <= address) |
243 | goto good_area; | 243 | goto good_area; |
244 | if (!(vma->vm_flags & VM_GROWSDOWN)) | 244 | if (!(vma->vm_flags & VM_GROWSDOWN)) |
245 | goto bad_area; | 245 | goto bad_area; |
246 | if (user_mode(regs)) { | 246 | if (user_mode(regs)) { |
247 | /* | 247 | /* |
248 | * accessing the stack below usp is always a bug. | 248 | * accessing the stack below usp is always a bug. |
249 | * we get page-aligned addresses so we can only check | 249 | * we get page-aligned addresses so we can only check |
250 | * if we're within a page from usp, but that might be | 250 | * if we're within a page from usp, but that might be |
251 | * enough to catch brutal errors at least. | 251 | * enough to catch brutal errors at least. |
252 | */ | 252 | */ |
253 | if (address + PAGE_SIZE < rdusp()) | 253 | if (address + PAGE_SIZE < rdusp()) |
254 | goto bad_area; | 254 | goto bad_area; |
255 | } | 255 | } |
256 | if (expand_stack(vma, address)) | 256 | if (expand_stack(vma, address)) |
257 | goto bad_area; | 257 | goto bad_area; |
258 | 258 | ||
259 | /* | 259 | /* |
260 | * Ok, we have a good vm_area for this memory access, so | 260 | * Ok, we have a good vm_area for this memory access, so |
261 | * we can handle it.. | 261 | * we can handle it.. |
262 | */ | 262 | */ |
263 | 263 | ||
264 | good_area: | 264 | good_area: |
265 | info.si_code = SEGV_ACCERR; | 265 | info.si_code = SEGV_ACCERR; |
266 | 266 | ||
267 | /* first do some preliminary protection checks */ | 267 | /* first do some preliminary protection checks */ |
268 | 268 | ||
269 | if (writeaccess == 2){ | 269 | if (writeaccess == 2){ |
270 | if (!(vma->vm_flags & VM_EXEC)) | 270 | if (!(vma->vm_flags & VM_EXEC)) |
271 | goto bad_area; | 271 | goto bad_area; |
272 | } else if (writeaccess == 1) { | 272 | } else if (writeaccess == 1) { |
273 | if (!(vma->vm_flags & VM_WRITE)) | 273 | if (!(vma->vm_flags & VM_WRITE)) |
274 | goto bad_area; | 274 | goto bad_area; |
275 | } else { | 275 | } else { |
276 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) | 276 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) |
277 | goto bad_area; | 277 | goto bad_area; |
278 | } | 278 | } |
279 | 279 | ||
280 | /* | 280 | /* |
281 | * If for any reason at all we couldn't handle the fault, | 281 | * If for any reason at all we couldn't handle the fault, |
282 | * make sure we exit gracefully rather than endlessly redo | 282 | * make sure we exit gracefully rather than endlessly redo |
283 | * the fault. | 283 | * the fault. |
284 | */ | 284 | */ |
285 | 285 | ||
286 | switch (handle_mm_fault(mm, vma, address, writeaccess & 1)) { | 286 | switch (handle_mm_fault(mm, vma, address, writeaccess & 1)) { |
287 | case 1: | 287 | case VM_FAULT_MINOR: |
288 | tsk->min_flt++; | 288 | tsk->min_flt++; |
289 | break; | 289 | break; |
290 | case 2: | 290 | case VM_FAULT_MAJOR: |
291 | tsk->maj_flt++; | 291 | tsk->maj_flt++; |
292 | break; | 292 | break; |
293 | case 0: | 293 | case VM_FAULT_SIGBUS: |
294 | goto do_sigbus; | 294 | goto do_sigbus; |
295 | default: | 295 | default: |
296 | goto out_of_memory; | 296 | goto out_of_memory; |
297 | } | 297 | } |
298 | 298 | ||
299 | up_read(&mm->mmap_sem); | 299 | up_read(&mm->mmap_sem); |
300 | return; | 300 | return; |
301 | 301 | ||
302 | /* | 302 | /* |
303 | * Something tried to access memory that isn't in our memory map.. | 303 | * Something tried to access memory that isn't in our memory map.. |
304 | * Fix it, but check if it's kernel or user first.. | 304 | * Fix it, but check if it's kernel or user first.. |
305 | */ | 305 | */ |
306 | 306 | ||
307 | bad_area: | 307 | bad_area: |
308 | up_read(&mm->mmap_sem); | 308 | up_read(&mm->mmap_sem); |
309 | 309 | ||
310 | bad_area_nosemaphore: | 310 | bad_area_nosemaphore: |
311 | DPG(show_registers(regs)); | 311 | DPG(show_registers(regs)); |
312 | 312 | ||
313 | /* User mode accesses just cause a SIGSEGV */ | 313 | /* User mode accesses just cause a SIGSEGV */ |
314 | 314 | ||
315 | if (user_mode(regs)) { | 315 | if (user_mode(regs)) { |
316 | info.si_signo = SIGSEGV; | 316 | info.si_signo = SIGSEGV; |
317 | info.si_errno = 0; | 317 | info.si_errno = 0; |
318 | /* info.si_code has been set above */ | 318 | /* info.si_code has been set above */ |
319 | info.si_addr = (void *)address; | 319 | info.si_addr = (void *)address; |
320 | force_sig_info(SIGSEGV, &info, tsk); | 320 | force_sig_info(SIGSEGV, &info, tsk); |
321 | return; | 321 | return; |
322 | } | 322 | } |
323 | 323 | ||
324 | no_context: | 324 | no_context: |
325 | 325 | ||
326 | /* Are we prepared to handle this kernel fault? | 326 | /* Are we prepared to handle this kernel fault? |
327 | * | 327 | * |
328 | * (The kernel has valid exception-points in the source | 328 | * (The kernel has valid exception-points in the source |
329 | * when it acesses user-memory. When it fails in one | 329 | * when it acesses user-memory. When it fails in one |
330 | * of those points, we find it in a table and do a jump | 330 | * of those points, we find it in a table and do a jump |
331 | * to some fixup code that loads an appropriate error | 331 | * to some fixup code that loads an appropriate error |
332 | * code) | 332 | * code) |
333 | */ | 333 | */ |
334 | 334 | ||
335 | if (find_fixup_code(regs)) | 335 | if (find_fixup_code(regs)) |
336 | return; | 336 | return; |
337 | 337 | ||
338 | /* | 338 | /* |
339 | * Oops. The kernel tried to access some bad page. We'll have to | 339 | * Oops. The kernel tried to access some bad page. We'll have to |
340 | * terminate things with extreme prejudice. | 340 | * terminate things with extreme prejudice. |
341 | */ | 341 | */ |
342 | 342 | ||
343 | if ((unsigned long) (address) < PAGE_SIZE) | 343 | if ((unsigned long) (address) < PAGE_SIZE) |
344 | raw_printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); | 344 | raw_printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); |
345 | else | 345 | else |
346 | raw_printk(KERN_ALERT "Unable to handle kernel access"); | 346 | raw_printk(KERN_ALERT "Unable to handle kernel access"); |
347 | raw_printk(" at virtual address %08lx\n",address); | 347 | raw_printk(" at virtual address %08lx\n",address); |
348 | 348 | ||
349 | die_if_kernel("Oops", regs, (writeaccess << 1) | protection); | 349 | die_if_kernel("Oops", regs, (writeaccess << 1) | protection); |
350 | 350 | ||
351 | do_exit(SIGKILL); | 351 | do_exit(SIGKILL); |
352 | 352 | ||
353 | /* | 353 | /* |
354 | * We ran out of memory, or some other thing happened to us that made | 354 | * We ran out of memory, or some other thing happened to us that made |
355 | * us unable to handle the page fault gracefully. | 355 | * us unable to handle the page fault gracefully. |
356 | */ | 356 | */ |
357 | 357 | ||
358 | out_of_memory: | 358 | out_of_memory: |
359 | up_read(&mm->mmap_sem); | 359 | up_read(&mm->mmap_sem); |
360 | printk("VM: killing process %s\n", tsk->comm); | 360 | printk("VM: killing process %s\n", tsk->comm); |
361 | if (user_mode(regs)) | 361 | if (user_mode(regs)) |
362 | do_exit(SIGKILL); | 362 | do_exit(SIGKILL); |
363 | goto no_context; | 363 | goto no_context; |
364 | 364 | ||
365 | do_sigbus: | 365 | do_sigbus: |
366 | up_read(&mm->mmap_sem); | 366 | up_read(&mm->mmap_sem); |
367 | 367 | ||
368 | /* | 368 | /* |
369 | * Send a sigbus, regardless of whether we were in kernel | 369 | * Send a sigbus, regardless of whether we were in kernel |
370 | * or user mode. | 370 | * or user mode. |
371 | */ | 371 | */ |
372 | info.si_signo = SIGBUS; | 372 | info.si_signo = SIGBUS; |
373 | info.si_errno = 0; | 373 | info.si_errno = 0; |
374 | info.si_code = BUS_ADRERR; | 374 | info.si_code = BUS_ADRERR; |
375 | info.si_addr = (void *)address; | 375 | info.si_addr = (void *)address; |
376 | force_sig_info(SIGBUS, &info, tsk); | 376 | force_sig_info(SIGBUS, &info, tsk); |
377 | 377 | ||
378 | /* Kernel mode? Handle exceptions or die */ | 378 | /* Kernel mode? Handle exceptions or die */ |
379 | if (!user_mode(regs)) | 379 | if (!user_mode(regs)) |
380 | goto no_context; | 380 | goto no_context; |
381 | return; | 381 | return; |
382 | 382 | ||
383 | vmalloc_fault: | 383 | vmalloc_fault: |
384 | { | 384 | { |
385 | /* | 385 | /* |
386 | * Synchronize this task's top level page-table | 386 | * Synchronize this task's top level page-table |
387 | * with the 'reference' page table. | 387 | * with the 'reference' page table. |
388 | * | 388 | * |
389 | * Use current_pgd instead of tsk->active_mm->pgd | 389 | * Use current_pgd instead of tsk->active_mm->pgd |
390 | * since the latter might be unavailable if this | 390 | * since the latter might be unavailable if this |
391 | * code is executed in a misfortunately run irq | 391 | * code is executed in a misfortunately run irq |
392 | * (like inside schedule() between switch_mm and | 392 | * (like inside schedule() between switch_mm and |
393 | * switch_to...). | 393 | * switch_to...). |
394 | */ | 394 | */ |
395 | 395 | ||
396 | int offset = pgd_index(address); | 396 | int offset = pgd_index(address); |
397 | pgd_t *pgd, *pgd_k; | 397 | pgd_t *pgd, *pgd_k; |
398 | pud_t *pud, *pud_k; | 398 | pud_t *pud, *pud_k; |
399 | pmd_t *pmd, *pmd_k; | 399 | pmd_t *pmd, *pmd_k; |
400 | pte_t *pte_k; | 400 | pte_t *pte_k; |
401 | 401 | ||
402 | pgd = (pgd_t *)per_cpu(current_pgd, smp_processor_id()) + offset; | 402 | pgd = (pgd_t *)per_cpu(current_pgd, smp_processor_id()) + offset; |
403 | pgd_k = init_mm.pgd + offset; | 403 | pgd_k = init_mm.pgd + offset; |
404 | 404 | ||
405 | /* Since we're two-level, we don't need to do both | 405 | /* Since we're two-level, we don't need to do both |
406 | * set_pgd and set_pmd (they do the same thing). If | 406 | * set_pgd and set_pmd (they do the same thing). If |
407 | * we go three-level at some point, do the right thing | 407 | * we go three-level at some point, do the right thing |
408 | * with pgd_present and set_pgd here. | 408 | * with pgd_present and set_pgd here. |
409 | * | 409 | * |
410 | * Also, since the vmalloc area is global, we don't | 410 | * Also, since the vmalloc area is global, we don't |
411 | * need to copy individual PTE's, it is enough to | 411 | * need to copy individual PTE's, it is enough to |
412 | * copy the pgd pointer into the pte page of the | 412 | * copy the pgd pointer into the pte page of the |
413 | * root task. If that is there, we'll find our pte if | 413 | * root task. If that is there, we'll find our pte if |
414 | * it exists. | 414 | * it exists. |
415 | */ | 415 | */ |
416 | 416 | ||
417 | pud = pud_offset(pgd, address); | 417 | pud = pud_offset(pgd, address); |
418 | pud_k = pud_offset(pgd_k, address); | 418 | pud_k = pud_offset(pgd_k, address); |
419 | if (!pud_present(*pud_k)) | 419 | if (!pud_present(*pud_k)) |
420 | goto no_context; | 420 | goto no_context; |
421 | 421 | ||
422 | pmd = pmd_offset(pud, address); | 422 | pmd = pmd_offset(pud, address); |
423 | pmd_k = pmd_offset(pud_k, address); | 423 | pmd_k = pmd_offset(pud_k, address); |
424 | 424 | ||
425 | if (!pmd_present(*pmd_k)) | 425 | if (!pmd_present(*pmd_k)) |
426 | goto bad_area_nosemaphore; | 426 | goto bad_area_nosemaphore; |
427 | 427 | ||
428 | set_pmd(pmd, *pmd_k); | 428 | set_pmd(pmd, *pmd_k); |
429 | 429 | ||
430 | /* Make sure the actual PTE exists as well to | 430 | /* Make sure the actual PTE exists as well to |
431 | * catch kernel vmalloc-area accesses to non-mapped | 431 | * catch kernel vmalloc-area accesses to non-mapped |
432 | * addresses. If we don't do this, this will just | 432 | * addresses. If we don't do this, this will just |
433 | * silently loop forever. | 433 | * silently loop forever. |
434 | */ | 434 | */ |
435 | 435 | ||
436 | pte_k = pte_offset_kernel(pmd_k, address); | 436 | pte_k = pte_offset_kernel(pmd_k, address); |
437 | if (!pte_present(*pte_k)) | 437 | if (!pte_present(*pte_k)) |
438 | goto no_context; | 438 | goto no_context; |
439 | 439 | ||
440 | return; | 440 | return; |
441 | } | 441 | } |
442 | } | 442 | } |
443 | 443 | ||
444 | /* Find fixup code. */ | 444 | /* Find fixup code. */ |
445 | int | 445 | int |
446 | find_fixup_code(struct pt_regs *regs) | 446 | find_fixup_code(struct pt_regs *regs) |
447 | { | 447 | { |
448 | const struct exception_table_entry *fixup; | 448 | const struct exception_table_entry *fixup; |
449 | 449 | ||
450 | if ((fixup = search_exception_tables(instruction_pointer(regs))) != 0) { | 450 | if ((fixup = search_exception_tables(instruction_pointer(regs))) != 0) { |
451 | /* Adjust the instruction pointer in the stackframe. */ | 451 | /* Adjust the instruction pointer in the stackframe. */ |
452 | instruction_pointer(regs) = fixup->fixup; | 452 | instruction_pointer(regs) = fixup->fixup; |
453 | arch_fixup(regs); | 453 | arch_fixup(regs); |
454 | return 1; | 454 | return 1; |
455 | } | 455 | } |
456 | 456 | ||
457 | return 0; | 457 | return 0; |
458 | } | 458 | } |
459 | 459 |
arch/frv/mm/fault.c
1 | /* | 1 | /* |
2 | * linux/arch/frv/mm/fault.c | 2 | * linux/arch/frv/mm/fault.c |
3 | * | 3 | * |
4 | * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved. | 4 | * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved. |
5 | * - Written by David Howells (dhowells@redhat.com) | 5 | * - Written by David Howells (dhowells@redhat.com) |
6 | * - Derived from arch/m68knommu/mm/fault.c | 6 | * - Derived from arch/m68knommu/mm/fault.c |
7 | * - Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, | 7 | * - Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, |
8 | * - Copyright (C) 2000 Lineo, Inc. (www.lineo.com) | 8 | * - Copyright (C) 2000 Lineo, Inc. (www.lineo.com) |
9 | * | 9 | * |
10 | * Based on: | 10 | * Based on: |
11 | * | 11 | * |
12 | * linux/arch/m68k/mm/fault.c | 12 | * linux/arch/m68k/mm/fault.c |
13 | * | 13 | * |
14 | * Copyright (C) 1995 Hamish Macdonald | 14 | * Copyright (C) 1995 Hamish Macdonald |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/mman.h> | 17 | #include <linux/mman.h> |
18 | #include <linux/mm.h> | 18 | #include <linux/mm.h> |
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/ptrace.h> | 20 | #include <linux/ptrace.h> |
21 | #include <linux/hardirq.h> | 21 | #include <linux/hardirq.h> |
22 | 22 | ||
23 | #include <asm/system.h> | 23 | #include <asm/system.h> |
24 | #include <asm/pgtable.h> | 24 | #include <asm/pgtable.h> |
25 | #include <asm/uaccess.h> | 25 | #include <asm/uaccess.h> |
26 | #include <asm/gdb-stub.h> | 26 | #include <asm/gdb-stub.h> |
27 | 27 | ||
28 | /*****************************************************************************/ | 28 | /*****************************************************************************/ |
29 | /* | 29 | /* |
30 | * This routine handles page faults. It determines the problem, and | 30 | * This routine handles page faults. It determines the problem, and |
31 | * then passes it off to one of the appropriate routines. | 31 | * then passes it off to one of the appropriate routines. |
32 | */ | 32 | */ |
33 | asmlinkage void do_page_fault(int datammu, unsigned long esr0, unsigned long ear0) | 33 | asmlinkage void do_page_fault(int datammu, unsigned long esr0, unsigned long ear0) |
34 | { | 34 | { |
35 | struct vm_area_struct *vma; | 35 | struct vm_area_struct *vma; |
36 | struct mm_struct *mm; | 36 | struct mm_struct *mm; |
37 | unsigned long _pme, lrai, lrad, fixup; | 37 | unsigned long _pme, lrai, lrad, fixup; |
38 | siginfo_t info; | 38 | siginfo_t info; |
39 | pgd_t *pge; | 39 | pgd_t *pge; |
40 | pud_t *pue; | 40 | pud_t *pue; |
41 | pte_t *pte; | 41 | pte_t *pte; |
42 | int write; | 42 | int write; |
43 | 43 | ||
44 | #if 0 | 44 | #if 0 |
45 | const char *atxc[16] = { | 45 | const char *atxc[16] = { |
46 | [0x0] = "mmu-miss", [0x8] = "multi-dat", [0x9] = "multi-sat", | 46 | [0x0] = "mmu-miss", [0x8] = "multi-dat", [0x9] = "multi-sat", |
47 | [0xa] = "tlb-miss", [0xc] = "privilege", [0xd] = "write-prot", | 47 | [0xa] = "tlb-miss", [0xc] = "privilege", [0xd] = "write-prot", |
48 | }; | 48 | }; |
49 | 49 | ||
50 | printk("do_page_fault(%d,%lx [%s],%lx)\n", | 50 | printk("do_page_fault(%d,%lx [%s],%lx)\n", |
51 | datammu, esr0, atxc[esr0 >> 20 & 0xf], ear0); | 51 | datammu, esr0, atxc[esr0 >> 20 & 0xf], ear0); |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | mm = current->mm; | 54 | mm = current->mm; |
55 | 55 | ||
56 | /* | 56 | /* |
57 | * We fault-in kernel-space virtual memory on-demand. The | 57 | * We fault-in kernel-space virtual memory on-demand. The |
58 | * 'reference' page table is init_mm.pgd. | 58 | * 'reference' page table is init_mm.pgd. |
59 | * | 59 | * |
60 | * NOTE! We MUST NOT take any locks for this case. We may | 60 | * NOTE! We MUST NOT take any locks for this case. We may |
61 | * be in an interrupt or a critical region, and should | 61 | * be in an interrupt or a critical region, and should |
62 | * only copy the information from the master page table, | 62 | * only copy the information from the master page table, |
63 | * nothing more. | 63 | * nothing more. |
64 | * | 64 | * |
65 | * This verifies that the fault happens in kernel space | 65 | * This verifies that the fault happens in kernel space |
66 | * and that the fault was a page not present (invalid) error | 66 | * and that the fault was a page not present (invalid) error |
67 | */ | 67 | */ |
68 | if (!user_mode(__frame) && (esr0 & ESR0_ATXC) == ESR0_ATXC_AMRTLB_MISS) { | 68 | if (!user_mode(__frame) && (esr0 & ESR0_ATXC) == ESR0_ATXC_AMRTLB_MISS) { |
69 | if (ear0 >= VMALLOC_START && ear0 < VMALLOC_END) | 69 | if (ear0 >= VMALLOC_START && ear0 < VMALLOC_END) |
70 | goto kernel_pte_fault; | 70 | goto kernel_pte_fault; |
71 | if (ear0 >= PKMAP_BASE && ear0 < PKMAP_END) | 71 | if (ear0 >= PKMAP_BASE && ear0 < PKMAP_END) |
72 | goto kernel_pte_fault; | 72 | goto kernel_pte_fault; |
73 | } | 73 | } |
74 | 74 | ||
75 | info.si_code = SEGV_MAPERR; | 75 | info.si_code = SEGV_MAPERR; |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * If we're in an interrupt or have no user | 78 | * If we're in an interrupt or have no user |
79 | * context, we must not take the fault.. | 79 | * context, we must not take the fault.. |
80 | */ | 80 | */ |
81 | if (in_interrupt() || !mm) | 81 | if (in_interrupt() || !mm) |
82 | goto no_context; | 82 | goto no_context; |
83 | 83 | ||
84 | down_read(&mm->mmap_sem); | 84 | down_read(&mm->mmap_sem); |
85 | 85 | ||
86 | vma = find_vma(mm, ear0); | 86 | vma = find_vma(mm, ear0); |
87 | if (!vma) | 87 | if (!vma) |
88 | goto bad_area; | 88 | goto bad_area; |
89 | if (vma->vm_start <= ear0) | 89 | if (vma->vm_start <= ear0) |
90 | goto good_area; | 90 | goto good_area; |
91 | if (!(vma->vm_flags & VM_GROWSDOWN)) | 91 | if (!(vma->vm_flags & VM_GROWSDOWN)) |
92 | goto bad_area; | 92 | goto bad_area; |
93 | 93 | ||
94 | if (user_mode(__frame)) { | 94 | if (user_mode(__frame)) { |
95 | /* | 95 | /* |
96 | * accessing the stack below %esp is always a bug. | 96 | * accessing the stack below %esp is always a bug. |
97 | * The "+ 32" is there due to some instructions (like | 97 | * The "+ 32" is there due to some instructions (like |
98 | * pusha) doing post-decrement on the stack and that | 98 | * pusha) doing post-decrement on the stack and that |
99 | * doesn't show up until later.. | 99 | * doesn't show up until later.. |
100 | */ | 100 | */ |
101 | if ((ear0 & PAGE_MASK) + 2 * PAGE_SIZE < __frame->sp) { | 101 | if ((ear0 & PAGE_MASK) + 2 * PAGE_SIZE < __frame->sp) { |
102 | #if 0 | 102 | #if 0 |
103 | printk("[%d] ### Access below stack @%lx (sp=%lx)\n", | 103 | printk("[%d] ### Access below stack @%lx (sp=%lx)\n", |
104 | current->pid, ear0, __frame->sp); | 104 | current->pid, ear0, __frame->sp); |
105 | show_registers(__frame); | 105 | show_registers(__frame); |
106 | printk("[%d] ### Code: [%08lx] %02x %02x %02x %02x %02x %02x %02x %02x\n", | 106 | printk("[%d] ### Code: [%08lx] %02x %02x %02x %02x %02x %02x %02x %02x\n", |
107 | current->pid, | 107 | current->pid, |
108 | __frame->pc, | 108 | __frame->pc, |
109 | ((u8*)__frame->pc)[0], | 109 | ((u8*)__frame->pc)[0], |
110 | ((u8*)__frame->pc)[1], | 110 | ((u8*)__frame->pc)[1], |
111 | ((u8*)__frame->pc)[2], | 111 | ((u8*)__frame->pc)[2], |
112 | ((u8*)__frame->pc)[3], | 112 | ((u8*)__frame->pc)[3], |
113 | ((u8*)__frame->pc)[4], | 113 | ((u8*)__frame->pc)[4], |
114 | ((u8*)__frame->pc)[5], | 114 | ((u8*)__frame->pc)[5], |
115 | ((u8*)__frame->pc)[6], | 115 | ((u8*)__frame->pc)[6], |
116 | ((u8*)__frame->pc)[7] | 116 | ((u8*)__frame->pc)[7] |
117 | ); | 117 | ); |
118 | #endif | 118 | #endif |
119 | goto bad_area; | 119 | goto bad_area; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | if (expand_stack(vma, ear0)) | 123 | if (expand_stack(vma, ear0)) |
124 | goto bad_area; | 124 | goto bad_area; |
125 | 125 | ||
126 | /* | 126 | /* |
127 | * Ok, we have a good vm_area for this memory access, so | 127 | * Ok, we have a good vm_area for this memory access, so |
128 | * we can handle it.. | 128 | * we can handle it.. |
129 | */ | 129 | */ |
130 | good_area: | 130 | good_area: |
131 | info.si_code = SEGV_ACCERR; | 131 | info.si_code = SEGV_ACCERR; |
132 | write = 0; | 132 | write = 0; |
133 | switch (esr0 & ESR0_ATXC) { | 133 | switch (esr0 & ESR0_ATXC) { |
134 | default: | 134 | default: |
135 | /* handle write to write protected page */ | 135 | /* handle write to write protected page */ |
136 | case ESR0_ATXC_WP_EXCEP: | 136 | case ESR0_ATXC_WP_EXCEP: |
137 | #ifdef TEST_VERIFY_AREA | 137 | #ifdef TEST_VERIFY_AREA |
138 | if (!(user_mode(__frame))) | 138 | if (!(user_mode(__frame))) |
139 | printk("WP fault at %08lx\n", __frame->pc); | 139 | printk("WP fault at %08lx\n", __frame->pc); |
140 | #endif | 140 | #endif |
141 | if (!(vma->vm_flags & VM_WRITE)) | 141 | if (!(vma->vm_flags & VM_WRITE)) |
142 | goto bad_area; | 142 | goto bad_area; |
143 | write = 1; | 143 | write = 1; |
144 | break; | 144 | break; |
145 | 145 | ||
146 | /* handle read from protected page */ | 146 | /* handle read from protected page */ |
147 | case ESR0_ATXC_PRIV_EXCEP: | 147 | case ESR0_ATXC_PRIV_EXCEP: |
148 | goto bad_area; | 148 | goto bad_area; |
149 | 149 | ||
150 | /* handle read, write or exec on absent page | 150 | /* handle read, write or exec on absent page |
151 | * - can't support write without permitting read | 151 | * - can't support write without permitting read |
152 | * - don't support execute without permitting read and vice-versa | 152 | * - don't support execute without permitting read and vice-versa |
153 | */ | 153 | */ |
154 | case ESR0_ATXC_AMRTLB_MISS: | 154 | case ESR0_ATXC_AMRTLB_MISS: |
155 | if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))) | 155 | if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))) |
156 | goto bad_area; | 156 | goto bad_area; |
157 | break; | 157 | break; |
158 | } | 158 | } |
159 | 159 | ||
160 | /* | 160 | /* |
161 | * If for any reason at all we couldn't handle the fault, | 161 | * If for any reason at all we couldn't handle the fault, |
162 | * make sure we exit gracefully rather than endlessly redo | 162 | * make sure we exit gracefully rather than endlessly redo |
163 | * the fault. | 163 | * the fault. |
164 | */ | 164 | */ |
165 | switch (handle_mm_fault(mm, vma, ear0, write)) { | 165 | switch (handle_mm_fault(mm, vma, ear0, write)) { |
166 | case 1: | 166 | case VM_FAULT_MINOR: |
167 | current->min_flt++; | 167 | current->min_flt++; |
168 | break; | 168 | break; |
169 | case 2: | 169 | case VM_FAULT_MAJOR: |
170 | current->maj_flt++; | 170 | current->maj_flt++; |
171 | break; | 171 | break; |
172 | case 0: | 172 | case VM_FAULT_SIGBUS: |
173 | goto do_sigbus; | 173 | goto do_sigbus; |
174 | default: | 174 | default: |
175 | goto out_of_memory; | 175 | goto out_of_memory; |
176 | } | 176 | } |
177 | 177 | ||
178 | up_read(&mm->mmap_sem); | 178 | up_read(&mm->mmap_sem); |
179 | return; | 179 | return; |
180 | 180 | ||
181 | /* | 181 | /* |
182 | * Something tried to access memory that isn't in our memory map.. | 182 | * Something tried to access memory that isn't in our memory map.. |
183 | * Fix it, but check if it's kernel or user first.. | 183 | * Fix it, but check if it's kernel or user first.. |
184 | */ | 184 | */ |
185 | bad_area: | 185 | bad_area: |
186 | up_read(&mm->mmap_sem); | 186 | up_read(&mm->mmap_sem); |
187 | 187 | ||
188 | /* User mode accesses just cause a SIGSEGV */ | 188 | /* User mode accesses just cause a SIGSEGV */ |
189 | if (user_mode(__frame)) { | 189 | if (user_mode(__frame)) { |
190 | info.si_signo = SIGSEGV; | 190 | info.si_signo = SIGSEGV; |
191 | info.si_errno = 0; | 191 | info.si_errno = 0; |
192 | /* info.si_code has been set above */ | 192 | /* info.si_code has been set above */ |
193 | info.si_addr = (void *) ear0; | 193 | info.si_addr = (void *) ear0; |
194 | force_sig_info(SIGSEGV, &info, current); | 194 | force_sig_info(SIGSEGV, &info, current); |
195 | return; | 195 | return; |
196 | } | 196 | } |
197 | 197 | ||
198 | no_context: | 198 | no_context: |
199 | /* are we prepared to handle this kernel fault? */ | 199 | /* are we prepared to handle this kernel fault? */ |
200 | if ((fixup = search_exception_table(__frame->pc)) != 0) { | 200 | if ((fixup = search_exception_table(__frame->pc)) != 0) { |
201 | __frame->pc = fixup; | 201 | __frame->pc = fixup; |
202 | return; | 202 | return; |
203 | } | 203 | } |
204 | 204 | ||
205 | /* | 205 | /* |
206 | * Oops. The kernel tried to access some bad page. We'll have to | 206 | * Oops. The kernel tried to access some bad page. We'll have to |
207 | * terminate things with extreme prejudice. | 207 | * terminate things with extreme prejudice. |
208 | */ | 208 | */ |
209 | 209 | ||
210 | bust_spinlocks(1); | 210 | bust_spinlocks(1); |
211 | 211 | ||
212 | if (ear0 < PAGE_SIZE) | 212 | if (ear0 < PAGE_SIZE) |
213 | printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); | 213 | printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); |
214 | else | 214 | else |
215 | printk(KERN_ALERT "Unable to handle kernel paging request"); | 215 | printk(KERN_ALERT "Unable to handle kernel paging request"); |
216 | printk(" at virtual addr %08lx\n", ear0); | 216 | printk(" at virtual addr %08lx\n", ear0); |
217 | printk(" PC : %08lx\n", __frame->pc); | 217 | printk(" PC : %08lx\n", __frame->pc); |
218 | printk(" EXC : esr0=%08lx ear0=%08lx\n", esr0, ear0); | 218 | printk(" EXC : esr0=%08lx ear0=%08lx\n", esr0, ear0); |
219 | 219 | ||
220 | asm("lrai %1,%0,#1,#0,#0" : "=&r"(lrai) : "r"(ear0)); | 220 | asm("lrai %1,%0,#1,#0,#0" : "=&r"(lrai) : "r"(ear0)); |
221 | asm("lrad %1,%0,#1,#0,#0" : "=&r"(lrad) : "r"(ear0)); | 221 | asm("lrad %1,%0,#1,#0,#0" : "=&r"(lrad) : "r"(ear0)); |
222 | 222 | ||
223 | printk(KERN_ALERT " LRAI: %08lx\n", lrai); | 223 | printk(KERN_ALERT " LRAI: %08lx\n", lrai); |
224 | printk(KERN_ALERT " LRAD: %08lx\n", lrad); | 224 | printk(KERN_ALERT " LRAD: %08lx\n", lrad); |
225 | 225 | ||
226 | __break_hijack_kernel_event(); | 226 | __break_hijack_kernel_event(); |
227 | 227 | ||
228 | pge = pgd_offset(current->mm, ear0); | 228 | pge = pgd_offset(current->mm, ear0); |
229 | pue = pud_offset(pge, ear0); | 229 | pue = pud_offset(pge, ear0); |
230 | _pme = pue->pue[0].ste[0]; | 230 | _pme = pue->pue[0].ste[0]; |
231 | 231 | ||
232 | printk(KERN_ALERT " PGE : %8p { PME %08lx }\n", pge, _pme); | 232 | printk(KERN_ALERT " PGE : %8p { PME %08lx }\n", pge, _pme); |
233 | 233 | ||
234 | if (_pme & xAMPRx_V) { | 234 | if (_pme & xAMPRx_V) { |
235 | unsigned long dampr, damlr, val; | 235 | unsigned long dampr, damlr, val; |
236 | 236 | ||
237 | asm volatile("movsg dampr2,%0 ! movgs %2,dampr2 ! movsg damlr2,%1" | 237 | asm volatile("movsg dampr2,%0 ! movgs %2,dampr2 ! movsg damlr2,%1" |
238 | : "=&r"(dampr), "=r"(damlr) | 238 | : "=&r"(dampr), "=r"(damlr) |
239 | : "r" (_pme | xAMPRx_L|xAMPRx_SS_16Kb|xAMPRx_S|xAMPRx_C|xAMPRx_V) | 239 | : "r" (_pme | xAMPRx_L|xAMPRx_SS_16Kb|xAMPRx_S|xAMPRx_C|xAMPRx_V) |
240 | ); | 240 | ); |
241 | 241 | ||
242 | pte = (pte_t *) damlr + __pte_index(ear0); | 242 | pte = (pte_t *) damlr + __pte_index(ear0); |
243 | val = pte_val(*pte); | 243 | val = pte_val(*pte); |
244 | 244 | ||
245 | asm volatile("movgs %0,dampr2" :: "r" (dampr)); | 245 | asm volatile("movgs %0,dampr2" :: "r" (dampr)); |
246 | 246 | ||
247 | printk(KERN_ALERT " PTE : %8p { %08lx }\n", pte, val); | 247 | printk(KERN_ALERT " PTE : %8p { %08lx }\n", pte, val); |
248 | } | 248 | } |
249 | 249 | ||
250 | die_if_kernel("Oops\n"); | 250 | die_if_kernel("Oops\n"); |
251 | do_exit(SIGKILL); | 251 | do_exit(SIGKILL); |
252 | 252 | ||
253 | /* | 253 | /* |
254 | * We ran out of memory, or some other thing happened to us that made | 254 | * We ran out of memory, or some other thing happened to us that made |
255 | * us unable to handle the page fault gracefully. | 255 | * us unable to handle the page fault gracefully. |
256 | */ | 256 | */ |
257 | out_of_memory: | 257 | out_of_memory: |
258 | up_read(&mm->mmap_sem); | 258 | up_read(&mm->mmap_sem); |
259 | printk("VM: killing process %s\n", current->comm); | 259 | printk("VM: killing process %s\n", current->comm); |
260 | if (user_mode(__frame)) | 260 | if (user_mode(__frame)) |
261 | do_exit(SIGKILL); | 261 | do_exit(SIGKILL); |
262 | goto no_context; | 262 | goto no_context; |
263 | 263 | ||
264 | do_sigbus: | 264 | do_sigbus: |
265 | up_read(&mm->mmap_sem); | 265 | up_read(&mm->mmap_sem); |
266 | 266 | ||
267 | /* | 267 | /* |
268 | * Send a sigbus, regardless of whether we were in kernel | 268 | * Send a sigbus, regardless of whether we were in kernel |
269 | * or user mode. | 269 | * or user mode. |
270 | */ | 270 | */ |
271 | info.si_signo = SIGBUS; | 271 | info.si_signo = SIGBUS; |
272 | info.si_errno = 0; | 272 | info.si_errno = 0; |
273 | info.si_code = BUS_ADRERR; | 273 | info.si_code = BUS_ADRERR; |
274 | info.si_addr = (void *) ear0; | 274 | info.si_addr = (void *) ear0; |
275 | force_sig_info(SIGBUS, &info, current); | 275 | force_sig_info(SIGBUS, &info, current); |
276 | 276 | ||
277 | /* Kernel mode? Handle exceptions or die */ | 277 | /* Kernel mode? Handle exceptions or die */ |
278 | if (!user_mode(__frame)) | 278 | if (!user_mode(__frame)) |
279 | goto no_context; | 279 | goto no_context; |
280 | return; | 280 | return; |
281 | 281 | ||
282 | /* | 282 | /* |
283 | * The fault was caused by a kernel PTE (such as installed by vmalloc or kmap) | 283 | * The fault was caused by a kernel PTE (such as installed by vmalloc or kmap) |
284 | */ | 284 | */ |
285 | kernel_pte_fault: | 285 | kernel_pte_fault: |
286 | { | 286 | { |
287 | /* | 287 | /* |
288 | * Synchronize this task's top level page-table | 288 | * Synchronize this task's top level page-table |
289 | * with the 'reference' page table. | 289 | * with the 'reference' page table. |
290 | * | 290 | * |
291 | * Do _not_ use "tsk" here. We might be inside | 291 | * Do _not_ use "tsk" here. We might be inside |
292 | * an interrupt in the middle of a task switch.. | 292 | * an interrupt in the middle of a task switch.. |
293 | */ | 293 | */ |
294 | int index = pgd_index(ear0); | 294 | int index = pgd_index(ear0); |
295 | pgd_t *pgd, *pgd_k; | 295 | pgd_t *pgd, *pgd_k; |
296 | pud_t *pud, *pud_k; | 296 | pud_t *pud, *pud_k; |
297 | pmd_t *pmd, *pmd_k; | 297 | pmd_t *pmd, *pmd_k; |
298 | pte_t *pte_k; | 298 | pte_t *pte_k; |
299 | 299 | ||
300 | pgd = (pgd_t *) __get_TTBR(); | 300 | pgd = (pgd_t *) __get_TTBR(); |
301 | pgd = (pgd_t *)__va(pgd) + index; | 301 | pgd = (pgd_t *)__va(pgd) + index; |
302 | pgd_k = ((pgd_t *)(init_mm.pgd)) + index; | 302 | pgd_k = ((pgd_t *)(init_mm.pgd)) + index; |
303 | 303 | ||
304 | if (!pgd_present(*pgd_k)) | 304 | if (!pgd_present(*pgd_k)) |
305 | goto no_context; | 305 | goto no_context; |
306 | //set_pgd(pgd, *pgd_k); /////// gcc ICE's on this line | 306 | //set_pgd(pgd, *pgd_k); /////// gcc ICE's on this line |
307 | 307 | ||
308 | pud_k = pud_offset(pgd_k, ear0); | 308 | pud_k = pud_offset(pgd_k, ear0); |
309 | if (!pud_present(*pud_k)) | 309 | if (!pud_present(*pud_k)) |
310 | goto no_context; | 310 | goto no_context; |
311 | 311 | ||
312 | pmd_k = pmd_offset(pud_k, ear0); | 312 | pmd_k = pmd_offset(pud_k, ear0); |
313 | if (!pmd_present(*pmd_k)) | 313 | if (!pmd_present(*pmd_k)) |
314 | goto no_context; | 314 | goto no_context; |
315 | 315 | ||
316 | pud = pud_offset(pgd, ear0); | 316 | pud = pud_offset(pgd, ear0); |
317 | pmd = pmd_offset(pud, ear0); | 317 | pmd = pmd_offset(pud, ear0); |
318 | set_pmd(pmd, *pmd_k); | 318 | set_pmd(pmd, *pmd_k); |
319 | 319 | ||
320 | pte_k = pte_offset_kernel(pmd_k, ear0); | 320 | pte_k = pte_offset_kernel(pmd_k, ear0); |
321 | if (!pte_present(*pte_k)) | 321 | if (!pte_present(*pte_k)) |
322 | goto no_context; | 322 | goto no_context; |
323 | return; | 323 | return; |
324 | } | 324 | } |
325 | } /* end do_page_fault() */ | 325 | } /* end do_page_fault() */ |
326 | 326 |
arch/m68k/mm/fault.c
1 | /* | 1 | /* |
2 | * linux/arch/m68k/mm/fault.c | 2 | * linux/arch/m68k/mm/fault.c |
3 | * | 3 | * |
4 | * Copyright (C) 1995 Hamish Macdonald | 4 | * Copyright (C) 1995 Hamish Macdonald |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <linux/mman.h> | 7 | #include <linux/mman.h> |
8 | #include <linux/mm.h> | 8 | #include <linux/mm.h> |
9 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
10 | #include <linux/ptrace.h> | 10 | #include <linux/ptrace.h> |
11 | #include <linux/interrupt.h> | 11 | #include <linux/interrupt.h> |
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | 13 | ||
14 | #include <asm/setup.h> | 14 | #include <asm/setup.h> |
15 | #include <asm/traps.h> | 15 | #include <asm/traps.h> |
16 | #include <asm/system.h> | 16 | #include <asm/system.h> |
17 | #include <asm/uaccess.h> | 17 | #include <asm/uaccess.h> |
18 | #include <asm/pgalloc.h> | 18 | #include <asm/pgalloc.h> |
19 | 19 | ||
20 | extern void die_if_kernel(char *, struct pt_regs *, long); | 20 | extern void die_if_kernel(char *, struct pt_regs *, long); |
21 | extern const int frame_extra_sizes[]; /* in m68k/kernel/signal.c */ | 21 | extern const int frame_extra_sizes[]; /* in m68k/kernel/signal.c */ |
22 | 22 | ||
23 | int send_fault_sig(struct pt_regs *regs) | 23 | int send_fault_sig(struct pt_regs *regs) |
24 | { | 24 | { |
25 | siginfo_t siginfo = { 0, 0, 0, }; | 25 | siginfo_t siginfo = { 0, 0, 0, }; |
26 | 26 | ||
27 | siginfo.si_signo = current->thread.signo; | 27 | siginfo.si_signo = current->thread.signo; |
28 | siginfo.si_code = current->thread.code; | 28 | siginfo.si_code = current->thread.code; |
29 | siginfo.si_addr = (void *)current->thread.faddr; | 29 | siginfo.si_addr = (void *)current->thread.faddr; |
30 | #ifdef DEBUG | 30 | #ifdef DEBUG |
31 | printk("send_fault_sig: %p,%d,%d\n", siginfo.si_addr, siginfo.si_signo, siginfo.si_code); | 31 | printk("send_fault_sig: %p,%d,%d\n", siginfo.si_addr, siginfo.si_signo, siginfo.si_code); |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | if (user_mode(regs)) { | 34 | if (user_mode(regs)) { |
35 | force_sig_info(siginfo.si_signo, | 35 | force_sig_info(siginfo.si_signo, |
36 | &siginfo, current); | 36 | &siginfo, current); |
37 | } else { | 37 | } else { |
38 | const struct exception_table_entry *fixup; | 38 | const struct exception_table_entry *fixup; |
39 | 39 | ||
40 | /* Are we prepared to handle this kernel fault? */ | 40 | /* Are we prepared to handle this kernel fault? */ |
41 | if ((fixup = search_exception_tables(regs->pc))) { | 41 | if ((fixup = search_exception_tables(regs->pc))) { |
42 | struct pt_regs *tregs; | 42 | struct pt_regs *tregs; |
43 | /* Create a new four word stack frame, discarding the old | 43 | /* Create a new four word stack frame, discarding the old |
44 | one. */ | 44 | one. */ |
45 | regs->stkadj = frame_extra_sizes[regs->format]; | 45 | regs->stkadj = frame_extra_sizes[regs->format]; |
46 | tregs = (struct pt_regs *)((ulong)regs + regs->stkadj); | 46 | tregs = (struct pt_regs *)((ulong)regs + regs->stkadj); |
47 | tregs->vector = regs->vector; | 47 | tregs->vector = regs->vector; |
48 | tregs->format = 0; | 48 | tregs->format = 0; |
49 | tregs->pc = fixup->fixup; | 49 | tregs->pc = fixup->fixup; |
50 | tregs->sr = regs->sr; | 50 | tregs->sr = regs->sr; |
51 | return -1; | 51 | return -1; |
52 | } | 52 | } |
53 | 53 | ||
54 | //if (siginfo.si_signo == SIGBUS) | 54 | //if (siginfo.si_signo == SIGBUS) |
55 | // force_sig_info(siginfo.si_signo, | 55 | // force_sig_info(siginfo.si_signo, |
56 | // &siginfo, current); | 56 | // &siginfo, current); |
57 | 57 | ||
58 | /* | 58 | /* |
59 | * Oops. The kernel tried to access some bad page. We'll have to | 59 | * Oops. The kernel tried to access some bad page. We'll have to |
60 | * terminate things with extreme prejudice. | 60 | * terminate things with extreme prejudice. |
61 | */ | 61 | */ |
62 | if ((unsigned long)siginfo.si_addr < PAGE_SIZE) | 62 | if ((unsigned long)siginfo.si_addr < PAGE_SIZE) |
63 | printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); | 63 | printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); |
64 | else | 64 | else |
65 | printk(KERN_ALERT "Unable to handle kernel access"); | 65 | printk(KERN_ALERT "Unable to handle kernel access"); |
66 | printk(" at virtual address %p\n", siginfo.si_addr); | 66 | printk(" at virtual address %p\n", siginfo.si_addr); |
67 | die_if_kernel("Oops", regs, 0 /*error_code*/); | 67 | die_if_kernel("Oops", regs, 0 /*error_code*/); |
68 | do_exit(SIGKILL); | 68 | do_exit(SIGKILL); |
69 | } | 69 | } |
70 | 70 | ||
71 | return 1; | 71 | return 1; |
72 | } | 72 | } |
73 | 73 | ||
74 | /* | 74 | /* |
75 | * This routine handles page faults. It determines the problem, and | 75 | * This routine handles page faults. It determines the problem, and |
76 | * then passes it off to one of the appropriate routines. | 76 | * then passes it off to one of the appropriate routines. |
77 | * | 77 | * |
78 | * error_code: | 78 | * error_code: |
79 | * bit 0 == 0 means no page found, 1 means protection fault | 79 | * bit 0 == 0 means no page found, 1 means protection fault |
80 | * bit 1 == 0 means read, 1 means write | 80 | * bit 1 == 0 means read, 1 means write |
81 | * | 81 | * |
82 | * If this routine detects a bad access, it returns 1, otherwise it | 82 | * If this routine detects a bad access, it returns 1, otherwise it |
83 | * returns 0. | 83 | * returns 0. |
84 | */ | 84 | */ |
85 | int do_page_fault(struct pt_regs *regs, unsigned long address, | 85 | int do_page_fault(struct pt_regs *regs, unsigned long address, |
86 | unsigned long error_code) | 86 | unsigned long error_code) |
87 | { | 87 | { |
88 | struct mm_struct *mm = current->mm; | 88 | struct mm_struct *mm = current->mm; |
89 | struct vm_area_struct * vma; | 89 | struct vm_area_struct * vma; |
90 | int write, fault; | 90 | int write, fault; |
91 | 91 | ||
92 | #ifdef DEBUG | 92 | #ifdef DEBUG |
93 | printk ("do page fault:\nregs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld, %p\n", | 93 | printk ("do page fault:\nregs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld, %p\n", |
94 | regs->sr, regs->pc, address, error_code, | 94 | regs->sr, regs->pc, address, error_code, |
95 | current->mm->pgd); | 95 | current->mm->pgd); |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | /* | 98 | /* |
99 | * If we're in an interrupt or have no user | 99 | * If we're in an interrupt or have no user |
100 | * context, we must not take the fault.. | 100 | * context, we must not take the fault.. |
101 | */ | 101 | */ |
102 | if (in_interrupt() || !mm) | 102 | if (in_interrupt() || !mm) |
103 | goto no_context; | 103 | goto no_context; |
104 | 104 | ||
105 | down_read(&mm->mmap_sem); | 105 | down_read(&mm->mmap_sem); |
106 | 106 | ||
107 | vma = find_vma(mm, address); | 107 | vma = find_vma(mm, address); |
108 | if (!vma) | 108 | if (!vma) |
109 | goto map_err; | 109 | goto map_err; |
110 | if (vma->vm_flags & VM_IO) | 110 | if (vma->vm_flags & VM_IO) |
111 | goto acc_err; | 111 | goto acc_err; |
112 | if (vma->vm_start <= address) | 112 | if (vma->vm_start <= address) |
113 | goto good_area; | 113 | goto good_area; |
114 | if (!(vma->vm_flags & VM_GROWSDOWN)) | 114 | if (!(vma->vm_flags & VM_GROWSDOWN)) |
115 | goto map_err; | 115 | goto map_err; |
116 | if (user_mode(regs)) { | 116 | if (user_mode(regs)) { |
117 | /* Accessing the stack below usp is always a bug. The | 117 | /* Accessing the stack below usp is always a bug. The |
118 | "+ 256" is there due to some instructions doing | 118 | "+ 256" is there due to some instructions doing |
119 | pre-decrement on the stack and that doesn't show up | 119 | pre-decrement on the stack and that doesn't show up |
120 | until later. */ | 120 | until later. */ |
121 | if (address + 256 < rdusp()) | 121 | if (address + 256 < rdusp()) |
122 | goto map_err; | 122 | goto map_err; |
123 | } | 123 | } |
124 | if (expand_stack(vma, address)) | 124 | if (expand_stack(vma, address)) |
125 | goto map_err; | 125 | goto map_err; |
126 | 126 | ||
127 | /* | 127 | /* |
128 | * Ok, we have a good vm_area for this memory access, so | 128 | * Ok, we have a good vm_area for this memory access, so |
129 | * we can handle it.. | 129 | * we can handle it.. |
130 | */ | 130 | */ |
131 | good_area: | 131 | good_area: |
132 | #ifdef DEBUG | 132 | #ifdef DEBUG |
133 | printk("do_page_fault: good_area\n"); | 133 | printk("do_page_fault: good_area\n"); |
134 | #endif | 134 | #endif |
135 | write = 0; | 135 | write = 0; |
136 | switch (error_code & 3) { | 136 | switch (error_code & 3) { |
137 | default: /* 3: write, present */ | 137 | default: /* 3: write, present */ |
138 | /* fall through */ | 138 | /* fall through */ |
139 | case 2: /* write, not present */ | 139 | case 2: /* write, not present */ |
140 | if (!(vma->vm_flags & VM_WRITE)) | 140 | if (!(vma->vm_flags & VM_WRITE)) |
141 | goto acc_err; | 141 | goto acc_err; |
142 | write++; | 142 | write++; |
143 | break; | 143 | break; |
144 | case 1: /* read, present */ | 144 | case 1: /* read, present */ |
145 | goto acc_err; | 145 | goto acc_err; |
146 | case 0: /* read, not present */ | 146 | case 0: /* read, not present */ |
147 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) | 147 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) |
148 | goto acc_err; | 148 | goto acc_err; |
149 | } | 149 | } |
150 | 150 | ||
151 | /* | 151 | /* |
152 | * If for any reason at all we couldn't handle the fault, | 152 | * If for any reason at all we couldn't handle the fault, |
153 | * make sure we exit gracefully rather than endlessly redo | 153 | * make sure we exit gracefully rather than endlessly redo |
154 | * the fault. | 154 | * the fault. |
155 | */ | 155 | */ |
156 | 156 | ||
157 | survive: | 157 | survive: |
158 | fault = handle_mm_fault(mm, vma, address, write); | 158 | fault = handle_mm_fault(mm, vma, address, write); |
159 | #ifdef DEBUG | 159 | #ifdef DEBUG |
160 | printk("handle_mm_fault returns %d\n",fault); | 160 | printk("handle_mm_fault returns %d\n",fault); |
161 | #endif | 161 | #endif |
162 | switch (fault) { | 162 | switch (fault) { |
163 | case 1: | 163 | case VM_FAULT_MINOR: |
164 | current->min_flt++; | 164 | current->min_flt++; |
165 | break; | 165 | break; |
166 | case 2: | 166 | case VM_FAULT_MAJOR: |
167 | current->maj_flt++; | 167 | current->maj_flt++; |
168 | break; | 168 | break; |
169 | case 0: | 169 | case VM_FAULT_SIGBUS: |
170 | goto bus_err; | 170 | goto bus_err; |
171 | default: | 171 | default: |
172 | goto out_of_memory; | 172 | goto out_of_memory; |
173 | } | 173 | } |
174 | 174 | ||
175 | up_read(&mm->mmap_sem); | 175 | up_read(&mm->mmap_sem); |
176 | return 0; | 176 | return 0; |
177 | 177 | ||
178 | /* | 178 | /* |
179 | * We ran out of memory, or some other thing happened to us that made | 179 | * We ran out of memory, or some other thing happened to us that made |
180 | * us unable to handle the page fault gracefully. | 180 | * us unable to handle the page fault gracefully. |
181 | */ | 181 | */ |
182 | out_of_memory: | 182 | out_of_memory: |
183 | up_read(&mm->mmap_sem); | 183 | up_read(&mm->mmap_sem); |
184 | if (current->pid == 1) { | 184 | if (current->pid == 1) { |
185 | yield(); | 185 | yield(); |
186 | down_read(&mm->mmap_sem); | 186 | down_read(&mm->mmap_sem); |
187 | goto survive; | 187 | goto survive; |
188 | } | 188 | } |
189 | 189 | ||
190 | printk("VM: killing process %s\n", current->comm); | 190 | printk("VM: killing process %s\n", current->comm); |
191 | if (user_mode(regs)) | 191 | if (user_mode(regs)) |
192 | do_exit(SIGKILL); | 192 | do_exit(SIGKILL); |
193 | 193 | ||
194 | no_context: | 194 | no_context: |
195 | current->thread.signo = SIGBUS; | 195 | current->thread.signo = SIGBUS; |
196 | current->thread.faddr = address; | 196 | current->thread.faddr = address; |
197 | return send_fault_sig(regs); | 197 | return send_fault_sig(regs); |
198 | 198 | ||
199 | bus_err: | 199 | bus_err: |
200 | current->thread.signo = SIGBUS; | 200 | current->thread.signo = SIGBUS; |
201 | current->thread.code = BUS_ADRERR; | 201 | current->thread.code = BUS_ADRERR; |
202 | current->thread.faddr = address; | 202 | current->thread.faddr = address; |
203 | goto send_sig; | 203 | goto send_sig; |
204 | 204 | ||
205 | map_err: | 205 | map_err: |
206 | current->thread.signo = SIGSEGV; | 206 | current->thread.signo = SIGSEGV; |
207 | current->thread.code = SEGV_MAPERR; | 207 | current->thread.code = SEGV_MAPERR; |
208 | current->thread.faddr = address; | 208 | current->thread.faddr = address; |
209 | goto send_sig; | 209 | goto send_sig; |
210 | 210 | ||
211 | acc_err: | 211 | acc_err: |
212 | current->thread.signo = SIGSEGV; | 212 | current->thread.signo = SIGSEGV; |
213 | current->thread.code = SEGV_ACCERR; | 213 | current->thread.code = SEGV_ACCERR; |
214 | current->thread.faddr = address; | 214 | current->thread.faddr = address; |
215 | 215 | ||
216 | send_sig: | 216 | send_sig: |
217 | up_read(&mm->mmap_sem); | 217 | up_read(&mm->mmap_sem); |
218 | return send_fault_sig(regs); | 218 | return send_fault_sig(regs); |
219 | } | 219 | } |
220 | 220 |
arch/parisc/mm/fault.c
1 | /* $Id: fault.c,v 1.5 2000/01/26 16:20:29 jsm Exp $ | 1 | /* $Id: fault.c,v 1.5 2000/01/26 16:20:29 jsm Exp $ |
2 | * | 2 | * |
3 | * This file is subject to the terms and conditions of the GNU General Public | 3 | * This file is subject to the terms and conditions of the GNU General Public |
4 | * License. See the file "COPYING" in the main directory of this archive | 4 | * License. See the file "COPYING" in the main directory of this archive |
5 | * for more details. | 5 | * for more details. |
6 | * | 6 | * |
7 | * | 7 | * |
8 | * Copyright (C) 1995, 1996, 1997, 1998 by Ralf Baechle | 8 | * Copyright (C) 1995, 1996, 1997, 1998 by Ralf Baechle |
9 | * Copyright 1999 SuSE GmbH (Philipp Rumpf, prumpf@tux.org) | 9 | * Copyright 1999 SuSE GmbH (Philipp Rumpf, prumpf@tux.org) |
10 | * Copyright 1999 Hewlett Packard Co. | 10 | * Copyright 1999 Hewlett Packard Co. |
11 | * | 11 | * |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/mm.h> | 14 | #include <linux/mm.h> |
15 | #include <linux/ptrace.h> | 15 | #include <linux/ptrace.h> |
16 | #include <linux/sched.h> | 16 | #include <linux/sched.h> |
17 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | 19 | ||
20 | #include <asm/uaccess.h> | 20 | #include <asm/uaccess.h> |
21 | #include <asm/traps.h> | 21 | #include <asm/traps.h> |
22 | 22 | ||
23 | #define PRINT_USER_FAULTS /* (turn this on if you want user faults to be */ | 23 | #define PRINT_USER_FAULTS /* (turn this on if you want user faults to be */ |
24 | /* dumped to the console via printk) */ | 24 | /* dumped to the console via printk) */ |
25 | 25 | ||
26 | 26 | ||
27 | /* Defines for parisc_acctyp() */ | 27 | /* Defines for parisc_acctyp() */ |
28 | #define READ 0 | 28 | #define READ 0 |
29 | #define WRITE 1 | 29 | #define WRITE 1 |
30 | 30 | ||
31 | /* Various important other fields */ | 31 | /* Various important other fields */ |
32 | #define bit22set(x) (x & 0x00000200) | 32 | #define bit22set(x) (x & 0x00000200) |
33 | #define bits23_25set(x) (x & 0x000001c0) | 33 | #define bits23_25set(x) (x & 0x000001c0) |
34 | #define isGraphicsFlushRead(x) ((x & 0xfc003fdf) == 0x04001a80) | 34 | #define isGraphicsFlushRead(x) ((x & 0xfc003fdf) == 0x04001a80) |
35 | /* extended opcode is 0x6a */ | 35 | /* extended opcode is 0x6a */ |
36 | 36 | ||
37 | #define BITSSET 0x1c0 /* for identifying LDCW */ | 37 | #define BITSSET 0x1c0 /* for identifying LDCW */ |
38 | 38 | ||
39 | 39 | ||
40 | DEFINE_PER_CPU(struct exception_data, exception_data); | 40 | DEFINE_PER_CPU(struct exception_data, exception_data); |
41 | 41 | ||
42 | /* | 42 | /* |
43 | * parisc_acctyp(unsigned int inst) -- | 43 | * parisc_acctyp(unsigned int inst) -- |
44 | * Given a PA-RISC memory access instruction, determine if the | 44 | * Given a PA-RISC memory access instruction, determine if the |
45 | * the instruction would perform a memory read or memory write | 45 | * the instruction would perform a memory read or memory write |
46 | * operation. | 46 | * operation. |
47 | * | 47 | * |
48 | * This function assumes that the given instruction is a memory access | 48 | * This function assumes that the given instruction is a memory access |
49 | * instruction (i.e. you should really only call it if you know that | 49 | * instruction (i.e. you should really only call it if you know that |
50 | * the instruction has generated some sort of a memory access fault). | 50 | * the instruction has generated some sort of a memory access fault). |
51 | * | 51 | * |
52 | * Returns: | 52 | * Returns: |
53 | * VM_READ if read operation | 53 | * VM_READ if read operation |
54 | * VM_WRITE if write operation | 54 | * VM_WRITE if write operation |
55 | * VM_EXEC if execute operation | 55 | * VM_EXEC if execute operation |
56 | */ | 56 | */ |
57 | static unsigned long | 57 | static unsigned long |
58 | parisc_acctyp(unsigned long code, unsigned int inst) | 58 | parisc_acctyp(unsigned long code, unsigned int inst) |
59 | { | 59 | { |
60 | if (code == 6 || code == 16) | 60 | if (code == 6 || code == 16) |
61 | return VM_EXEC; | 61 | return VM_EXEC; |
62 | 62 | ||
63 | switch (inst & 0xf0000000) { | 63 | switch (inst & 0xf0000000) { |
64 | case 0x40000000: /* load */ | 64 | case 0x40000000: /* load */ |
65 | case 0x50000000: /* new load */ | 65 | case 0x50000000: /* new load */ |
66 | return VM_READ; | 66 | return VM_READ; |
67 | 67 | ||
68 | case 0x60000000: /* store */ | 68 | case 0x60000000: /* store */ |
69 | case 0x70000000: /* new store */ | 69 | case 0x70000000: /* new store */ |
70 | return VM_WRITE; | 70 | return VM_WRITE; |
71 | 71 | ||
72 | case 0x20000000: /* coproc */ | 72 | case 0x20000000: /* coproc */ |
73 | case 0x30000000: /* coproc2 */ | 73 | case 0x30000000: /* coproc2 */ |
74 | if (bit22set(inst)) | 74 | if (bit22set(inst)) |
75 | return VM_WRITE; | 75 | return VM_WRITE; |
76 | 76 | ||
77 | case 0x0: /* indexed/memory management */ | 77 | case 0x0: /* indexed/memory management */ |
78 | if (bit22set(inst)) { | 78 | if (bit22set(inst)) { |
79 | /* | 79 | /* |
80 | * Check for the 'Graphics Flush Read' instruction. | 80 | * Check for the 'Graphics Flush Read' instruction. |
81 | * It resembles an FDC instruction, except for bits | 81 | * It resembles an FDC instruction, except for bits |
82 | * 20 and 21. Any combination other than zero will | 82 | * 20 and 21. Any combination other than zero will |
83 | * utilize the block mover functionality on some | 83 | * utilize the block mover functionality on some |
84 | * older PA-RISC platforms. The case where a block | 84 | * older PA-RISC platforms. The case where a block |
85 | * move is performed from VM to graphics IO space | 85 | * move is performed from VM to graphics IO space |
86 | * should be treated as a READ. | 86 | * should be treated as a READ. |
87 | * | 87 | * |
88 | * The significance of bits 20,21 in the FDC | 88 | * The significance of bits 20,21 in the FDC |
89 | * instruction is: | 89 | * instruction is: |
90 | * | 90 | * |
91 | * 00 Flush data cache (normal instruction behavior) | 91 | * 00 Flush data cache (normal instruction behavior) |
92 | * 01 Graphics flush write (IO space -> VM) | 92 | * 01 Graphics flush write (IO space -> VM) |
93 | * 10 Graphics flush read (VM -> IO space) | 93 | * 10 Graphics flush read (VM -> IO space) |
94 | * 11 Graphics flush read/write (VM <-> IO space) | 94 | * 11 Graphics flush read/write (VM <-> IO space) |
95 | */ | 95 | */ |
96 | if (isGraphicsFlushRead(inst)) | 96 | if (isGraphicsFlushRead(inst)) |
97 | return VM_READ; | 97 | return VM_READ; |
98 | return VM_WRITE; | 98 | return VM_WRITE; |
99 | } else { | 99 | } else { |
100 | /* | 100 | /* |
101 | * Check for LDCWX and LDCWS (semaphore instructions). | 101 | * Check for LDCWX and LDCWS (semaphore instructions). |
102 | * If bits 23 through 25 are all 1's it is one of | 102 | * If bits 23 through 25 are all 1's it is one of |
103 | * the above two instructions and is a write. | 103 | * the above two instructions and is a write. |
104 | * | 104 | * |
105 | * Note: With the limited bits we are looking at, | 105 | * Note: With the limited bits we are looking at, |
106 | * this will also catch PROBEW and PROBEWI. However, | 106 | * this will also catch PROBEW and PROBEWI. However, |
107 | * these should never get in here because they don't | 107 | * these should never get in here because they don't |
108 | * generate exceptions of the type: | 108 | * generate exceptions of the type: |
109 | * Data TLB miss fault/data page fault | 109 | * Data TLB miss fault/data page fault |
110 | * Data memory protection trap | 110 | * Data memory protection trap |
111 | */ | 111 | */ |
112 | if (bits23_25set(inst) == BITSSET) | 112 | if (bits23_25set(inst) == BITSSET) |
113 | return VM_WRITE; | 113 | return VM_WRITE; |
114 | } | 114 | } |
115 | return VM_READ; /* Default */ | 115 | return VM_READ; /* Default */ |
116 | } | 116 | } |
117 | return VM_READ; /* Default */ | 117 | return VM_READ; /* Default */ |
118 | } | 118 | } |
119 | 119 | ||
120 | #undef bit22set | 120 | #undef bit22set |
121 | #undef bits23_25set | 121 | #undef bits23_25set |
122 | #undef isGraphicsFlushRead | 122 | #undef isGraphicsFlushRead |
123 | #undef BITSSET | 123 | #undef BITSSET |
124 | 124 | ||
125 | 125 | ||
126 | #if 0 | 126 | #if 0 |
127 | /* This is the treewalk to find a vma which is the highest that has | 127 | /* This is the treewalk to find a vma which is the highest that has |
128 | * a start < addr. We're using find_vma_prev instead right now, but | 128 | * a start < addr. We're using find_vma_prev instead right now, but |
129 | * we might want to use this at some point in the future. Probably | 129 | * we might want to use this at some point in the future. Probably |
130 | * not, but I want it committed to CVS so I don't lose it :-) | 130 | * not, but I want it committed to CVS so I don't lose it :-) |
131 | */ | 131 | */ |
132 | while (tree != vm_avl_empty) { | 132 | while (tree != vm_avl_empty) { |
133 | if (tree->vm_start > addr) { | 133 | if (tree->vm_start > addr) { |
134 | tree = tree->vm_avl_left; | 134 | tree = tree->vm_avl_left; |
135 | } else { | 135 | } else { |
136 | prev = tree; | 136 | prev = tree; |
137 | if (prev->vm_next == NULL) | 137 | if (prev->vm_next == NULL) |
138 | break; | 138 | break; |
139 | if (prev->vm_next->vm_start > addr) | 139 | if (prev->vm_next->vm_start > addr) |
140 | break; | 140 | break; |
141 | tree = tree->vm_avl_right; | 141 | tree = tree->vm_avl_right; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | #endif | 144 | #endif |
145 | 145 | ||
146 | void do_page_fault(struct pt_regs *regs, unsigned long code, | 146 | void do_page_fault(struct pt_regs *regs, unsigned long code, |
147 | unsigned long address) | 147 | unsigned long address) |
148 | { | 148 | { |
149 | struct vm_area_struct *vma, *prev_vma; | 149 | struct vm_area_struct *vma, *prev_vma; |
150 | struct task_struct *tsk = current; | 150 | struct task_struct *tsk = current; |
151 | struct mm_struct *mm = tsk->mm; | 151 | struct mm_struct *mm = tsk->mm; |
152 | const struct exception_table_entry *fix; | 152 | const struct exception_table_entry *fix; |
153 | unsigned long acc_type; | 153 | unsigned long acc_type; |
154 | 154 | ||
155 | if (in_interrupt() || !mm) | 155 | if (in_interrupt() || !mm) |
156 | goto no_context; | 156 | goto no_context; |
157 | 157 | ||
158 | down_read(&mm->mmap_sem); | 158 | down_read(&mm->mmap_sem); |
159 | vma = find_vma_prev(mm, address, &prev_vma); | 159 | vma = find_vma_prev(mm, address, &prev_vma); |
160 | if (!vma || address < vma->vm_start) | 160 | if (!vma || address < vma->vm_start) |
161 | goto check_expansion; | 161 | goto check_expansion; |
162 | /* | 162 | /* |
163 | * Ok, we have a good vm_area for this memory access. We still need to | 163 | * Ok, we have a good vm_area for this memory access. We still need to |
164 | * check the access permissions. | 164 | * check the access permissions. |
165 | */ | 165 | */ |
166 | 166 | ||
167 | good_area: | 167 | good_area: |
168 | 168 | ||
169 | acc_type = parisc_acctyp(code,regs->iir); | 169 | acc_type = parisc_acctyp(code,regs->iir); |
170 | 170 | ||
171 | if ((vma->vm_flags & acc_type) != acc_type) | 171 | if ((vma->vm_flags & acc_type) != acc_type) |
172 | goto bad_area; | 172 | goto bad_area; |
173 | 173 | ||
174 | /* | 174 | /* |
175 | * If for any reason at all we couldn't handle the fault, make | 175 | * If for any reason at all we couldn't handle the fault, make |
176 | * sure we exit gracefully rather than endlessly redo the | 176 | * sure we exit gracefully rather than endlessly redo the |
177 | * fault. | 177 | * fault. |
178 | */ | 178 | */ |
179 | 179 | ||
180 | switch (handle_mm_fault(mm, vma, address, (acc_type & VM_WRITE) != 0)) { | 180 | switch (handle_mm_fault(mm, vma, address, (acc_type & VM_WRITE) != 0)) { |
181 | case 1: | 181 | case VM_FAULT_MINOR: |
182 | ++current->min_flt; | 182 | ++current->min_flt; |
183 | break; | 183 | break; |
184 | case 2: | 184 | case VM_FAULT_MAJOR: |
185 | ++current->maj_flt; | 185 | ++current->maj_flt; |
186 | break; | 186 | break; |
187 | case 0: | 187 | case VM_FAULT_SIGBUS: |
188 | /* | 188 | /* |
189 | * We ran out of memory, or some other thing happened | 189 | * We hit a hared mapping outside of the file, or some |
190 | * to us that made us unable to handle the page fault | 190 | * other thing happened to us that made us unable to |
191 | * gracefully. | 191 | * handle the page fault gracefully. |
192 | */ | 192 | */ |
193 | goto bad_area; | 193 | goto bad_area; |
194 | default: | 194 | default: |
195 | goto out_of_memory; | 195 | goto out_of_memory; |
196 | } | 196 | } |
197 | up_read(&mm->mmap_sem); | 197 | up_read(&mm->mmap_sem); |
198 | return; | 198 | return; |
199 | 199 | ||
200 | check_expansion: | 200 | check_expansion: |
201 | vma = prev_vma; | 201 | vma = prev_vma; |
202 | if (vma && (expand_stack(vma, address) == 0)) | 202 | if (vma && (expand_stack(vma, address) == 0)) |
203 | goto good_area; | 203 | goto good_area; |
204 | 204 | ||
205 | /* | 205 | /* |
206 | * Something tried to access memory that isn't in our memory map.. | 206 | * Something tried to access memory that isn't in our memory map.. |
207 | */ | 207 | */ |
208 | bad_area: | 208 | bad_area: |
209 | up_read(&mm->mmap_sem); | 209 | up_read(&mm->mmap_sem); |
210 | 210 | ||
211 | if (user_mode(regs)) { | 211 | if (user_mode(regs)) { |
212 | struct siginfo si; | 212 | struct siginfo si; |
213 | 213 | ||
214 | #ifdef PRINT_USER_FAULTS | 214 | #ifdef PRINT_USER_FAULTS |
215 | printk(KERN_DEBUG "\n"); | 215 | printk(KERN_DEBUG "\n"); |
216 | printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n", | 216 | printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n", |
217 | tsk->pid, tsk->comm, code, address); | 217 | tsk->pid, tsk->comm, code, address); |
218 | if (vma) { | 218 | if (vma) { |
219 | printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n", | 219 | printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n", |
220 | vma->vm_start, vma->vm_end); | 220 | vma->vm_start, vma->vm_end); |
221 | } | 221 | } |
222 | show_regs(regs); | 222 | show_regs(regs); |
223 | #endif | 223 | #endif |
224 | /* FIXME: actually we need to get the signo and code correct */ | 224 | /* FIXME: actually we need to get the signo and code correct */ |
225 | si.si_signo = SIGSEGV; | 225 | si.si_signo = SIGSEGV; |
226 | si.si_errno = 0; | 226 | si.si_errno = 0; |
227 | si.si_code = SEGV_MAPERR; | 227 | si.si_code = SEGV_MAPERR; |
228 | si.si_addr = (void __user *) address; | 228 | si.si_addr = (void __user *) address; |
229 | force_sig_info(SIGSEGV, &si, current); | 229 | force_sig_info(SIGSEGV, &si, current); |
230 | return; | 230 | return; |
231 | } | 231 | } |
232 | 232 | ||
233 | no_context: | 233 | no_context: |
234 | 234 | ||
235 | if (!user_mode(regs)) { | 235 | if (!user_mode(regs)) { |
236 | fix = search_exception_tables(regs->iaoq[0]); | 236 | fix = search_exception_tables(regs->iaoq[0]); |
237 | 237 | ||
238 | if (fix) { | 238 | if (fix) { |
239 | struct exception_data *d; | 239 | struct exception_data *d; |
240 | 240 | ||
241 | d = &__get_cpu_var(exception_data); | 241 | d = &__get_cpu_var(exception_data); |
242 | d->fault_ip = regs->iaoq[0]; | 242 | d->fault_ip = regs->iaoq[0]; |
243 | d->fault_space = regs->isr; | 243 | d->fault_space = regs->isr; |
244 | d->fault_addr = regs->ior; | 244 | d->fault_addr = regs->ior; |
245 | 245 | ||
246 | regs->iaoq[0] = ((fix->fixup) & ~3); | 246 | regs->iaoq[0] = ((fix->fixup) & ~3); |
247 | 247 | ||
248 | /* | 248 | /* |
249 | * NOTE: In some cases the faulting instruction | 249 | * NOTE: In some cases the faulting instruction |
250 | * may be in the delay slot of a branch. We | 250 | * may be in the delay slot of a branch. We |
251 | * don't want to take the branch, so we don't | 251 | * don't want to take the branch, so we don't |
252 | * increment iaoq[1], instead we set it to be | 252 | * increment iaoq[1], instead we set it to be |
253 | * iaoq[0]+4, and clear the B bit in the PSW | 253 | * iaoq[0]+4, and clear the B bit in the PSW |
254 | */ | 254 | */ |
255 | 255 | ||
256 | regs->iaoq[1] = regs->iaoq[0] + 4; | 256 | regs->iaoq[1] = regs->iaoq[0] + 4; |
257 | regs->gr[0] &= ~PSW_B; /* IPSW in gr[0] */ | 257 | regs->gr[0] &= ~PSW_B; /* IPSW in gr[0] */ |
258 | 258 | ||
259 | return; | 259 | return; |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | parisc_terminate("Bad Address (null pointer deref?)", regs, code, address); | 263 | parisc_terminate("Bad Address (null pointer deref?)", regs, code, address); |
264 | 264 | ||
265 | out_of_memory: | 265 | out_of_memory: |
266 | up_read(&mm->mmap_sem); | 266 | up_read(&mm->mmap_sem); |
267 | printk(KERN_CRIT "VM: killing process %s\n", current->comm); | 267 | printk(KERN_CRIT "VM: killing process %s\n", current->comm); |
268 | if (user_mode(regs)) | 268 | if (user_mode(regs)) |
269 | do_exit(SIGKILL); | 269 | do_exit(SIGKILL); |
270 | goto no_context; | 270 | goto no_context; |
271 | } | 271 | } |
272 | 272 |
arch/sh64/mm/fault.c
1 | /* | 1 | /* |
2 | * This file is subject to the terms and conditions of the GNU General Public | 2 | * This file is subject to the terms and conditions of the GNU General Public |
3 | * License. See the file "COPYING" in the main directory of this archive | 3 | * License. See the file "COPYING" in the main directory of this archive |
4 | * for more details. | 4 | * for more details. |
5 | * | 5 | * |
6 | * arch/sh64/mm/fault.c | 6 | * arch/sh64/mm/fault.c |
7 | * | 7 | * |
8 | * Copyright (C) 2000, 2001 Paolo Alberelli | 8 | * Copyright (C) 2000, 2001 Paolo Alberelli |
9 | * Copyright (C) 2003 Richard Curnow (/proc/tlb, bug fixes) | 9 | * Copyright (C) 2003 Richard Curnow (/proc/tlb, bug fixes) |
10 | * Copyright (C) 2003 Paul Mundt | 10 | * Copyright (C) 2003 Paul Mundt |
11 | * | 11 | * |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/signal.h> | 14 | #include <linux/signal.h> |
15 | #include <linux/rwsem.h> | 15 | #include <linux/rwsem.h> |
16 | #include <linux/sched.h> | 16 | #include <linux/sched.h> |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
19 | #include <linux/string.h> | 19 | #include <linux/string.h> |
20 | #include <linux/types.h> | 20 | #include <linux/types.h> |
21 | #include <linux/ptrace.h> | 21 | #include <linux/ptrace.h> |
22 | #include <linux/mman.h> | 22 | #include <linux/mman.h> |
23 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
24 | #include <linux/smp.h> | 24 | #include <linux/smp.h> |
25 | #include <linux/smp_lock.h> | 25 | #include <linux/smp_lock.h> |
26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
27 | 27 | ||
28 | #include <asm/system.h> | 28 | #include <asm/system.h> |
29 | #include <asm/io.h> | 29 | #include <asm/io.h> |
30 | #include <asm/tlb.h> | 30 | #include <asm/tlb.h> |
31 | #include <asm/uaccess.h> | 31 | #include <asm/uaccess.h> |
32 | #include <asm/pgalloc.h> | 32 | #include <asm/pgalloc.h> |
33 | #include <asm/mmu_context.h> | 33 | #include <asm/mmu_context.h> |
34 | #include <asm/registers.h> /* required by inline asm statements */ | 34 | #include <asm/registers.h> /* required by inline asm statements */ |
35 | 35 | ||
36 | #if defined(CONFIG_SH64_PROC_TLB) | 36 | #if defined(CONFIG_SH64_PROC_TLB) |
37 | #include <linux/init.h> | 37 | #include <linux/init.h> |
38 | #include <linux/proc_fs.h> | 38 | #include <linux/proc_fs.h> |
39 | /* Count numbers of tlb refills in each region */ | 39 | /* Count numbers of tlb refills in each region */ |
40 | static unsigned long long calls_to_update_mmu_cache = 0ULL; | 40 | static unsigned long long calls_to_update_mmu_cache = 0ULL; |
41 | static unsigned long long calls_to_flush_tlb_page = 0ULL; | 41 | static unsigned long long calls_to_flush_tlb_page = 0ULL; |
42 | static unsigned long long calls_to_flush_tlb_range = 0ULL; | 42 | static unsigned long long calls_to_flush_tlb_range = 0ULL; |
43 | static unsigned long long calls_to_flush_tlb_mm = 0ULL; | 43 | static unsigned long long calls_to_flush_tlb_mm = 0ULL; |
44 | static unsigned long long calls_to_flush_tlb_all = 0ULL; | 44 | static unsigned long long calls_to_flush_tlb_all = 0ULL; |
45 | unsigned long long calls_to_do_slow_page_fault = 0ULL; | 45 | unsigned long long calls_to_do_slow_page_fault = 0ULL; |
46 | unsigned long long calls_to_do_fast_page_fault = 0ULL; | 46 | unsigned long long calls_to_do_fast_page_fault = 0ULL; |
47 | 47 | ||
48 | /* Count size of ranges for flush_tlb_range */ | 48 | /* Count size of ranges for flush_tlb_range */ |
49 | static unsigned long long flush_tlb_range_1 = 0ULL; | 49 | static unsigned long long flush_tlb_range_1 = 0ULL; |
50 | static unsigned long long flush_tlb_range_2 = 0ULL; | 50 | static unsigned long long flush_tlb_range_2 = 0ULL; |
51 | static unsigned long long flush_tlb_range_3_4 = 0ULL; | 51 | static unsigned long long flush_tlb_range_3_4 = 0ULL; |
52 | static unsigned long long flush_tlb_range_5_7 = 0ULL; | 52 | static unsigned long long flush_tlb_range_5_7 = 0ULL; |
53 | static unsigned long long flush_tlb_range_8_11 = 0ULL; | 53 | static unsigned long long flush_tlb_range_8_11 = 0ULL; |
54 | static unsigned long long flush_tlb_range_12_15 = 0ULL; | 54 | static unsigned long long flush_tlb_range_12_15 = 0ULL; |
55 | static unsigned long long flush_tlb_range_16_up = 0ULL; | 55 | static unsigned long long flush_tlb_range_16_up = 0ULL; |
56 | 56 | ||
57 | static unsigned long long page_not_present = 0ULL; | 57 | static unsigned long long page_not_present = 0ULL; |
58 | 58 | ||
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | extern void die(const char *,struct pt_regs *,long); | 61 | extern void die(const char *,struct pt_regs *,long); |
62 | 62 | ||
63 | #define PFLAG(val,flag) (( (val) & (flag) ) ? #flag : "" ) | 63 | #define PFLAG(val,flag) (( (val) & (flag) ) ? #flag : "" ) |
64 | #define PPROT(flag) PFLAG(pgprot_val(prot),flag) | 64 | #define PPROT(flag) PFLAG(pgprot_val(prot),flag) |
65 | 65 | ||
66 | static inline void print_prots(pgprot_t prot) | 66 | static inline void print_prots(pgprot_t prot) |
67 | { | 67 | { |
68 | printk("prot is 0x%08lx\n",pgprot_val(prot)); | 68 | printk("prot is 0x%08lx\n",pgprot_val(prot)); |
69 | 69 | ||
70 | printk("%s %s %s %s %s\n",PPROT(_PAGE_SHARED),PPROT(_PAGE_READ), | 70 | printk("%s %s %s %s %s\n",PPROT(_PAGE_SHARED),PPROT(_PAGE_READ), |
71 | PPROT(_PAGE_EXECUTE),PPROT(_PAGE_WRITE),PPROT(_PAGE_USER)); | 71 | PPROT(_PAGE_EXECUTE),PPROT(_PAGE_WRITE),PPROT(_PAGE_USER)); |
72 | } | 72 | } |
73 | 73 | ||
74 | static inline void print_vma(struct vm_area_struct *vma) | 74 | static inline void print_vma(struct vm_area_struct *vma) |
75 | { | 75 | { |
76 | printk("vma start 0x%08lx\n", vma->vm_start); | 76 | printk("vma start 0x%08lx\n", vma->vm_start); |
77 | printk("vma end 0x%08lx\n", vma->vm_end); | 77 | printk("vma end 0x%08lx\n", vma->vm_end); |
78 | 78 | ||
79 | print_prots(vma->vm_page_prot); | 79 | print_prots(vma->vm_page_prot); |
80 | printk("vm_flags 0x%08lx\n", vma->vm_flags); | 80 | printk("vm_flags 0x%08lx\n", vma->vm_flags); |
81 | } | 81 | } |
82 | 82 | ||
83 | static inline void print_task(struct task_struct *tsk) | 83 | static inline void print_task(struct task_struct *tsk) |
84 | { | 84 | { |
85 | printk("Task pid %d\n", tsk->pid); | 85 | printk("Task pid %d\n", tsk->pid); |
86 | } | 86 | } |
87 | 87 | ||
88 | static pte_t *lookup_pte(struct mm_struct *mm, unsigned long address) | 88 | static pte_t *lookup_pte(struct mm_struct *mm, unsigned long address) |
89 | { | 89 | { |
90 | pgd_t *dir; | 90 | pgd_t *dir; |
91 | pmd_t *pmd; | 91 | pmd_t *pmd; |
92 | pte_t *pte; | 92 | pte_t *pte; |
93 | pte_t entry; | 93 | pte_t entry; |
94 | 94 | ||
95 | dir = pgd_offset(mm, address); | 95 | dir = pgd_offset(mm, address); |
96 | if (pgd_none(*dir)) { | 96 | if (pgd_none(*dir)) { |
97 | return NULL; | 97 | return NULL; |
98 | } | 98 | } |
99 | 99 | ||
100 | pmd = pmd_offset(dir, address); | 100 | pmd = pmd_offset(dir, address); |
101 | if (pmd_none(*pmd)) { | 101 | if (pmd_none(*pmd)) { |
102 | return NULL; | 102 | return NULL; |
103 | } | 103 | } |
104 | 104 | ||
105 | pte = pte_offset_kernel(pmd, address); | 105 | pte = pte_offset_kernel(pmd, address); |
106 | entry = *pte; | 106 | entry = *pte; |
107 | 107 | ||
108 | if (pte_none(entry)) { | 108 | if (pte_none(entry)) { |
109 | return NULL; | 109 | return NULL; |
110 | } | 110 | } |
111 | if (!pte_present(entry)) { | 111 | if (!pte_present(entry)) { |
112 | return NULL; | 112 | return NULL; |
113 | } | 113 | } |
114 | 114 | ||
115 | return pte; | 115 | return pte; |
116 | } | 116 | } |
117 | 117 | ||
118 | /* | 118 | /* |
119 | * This routine handles page faults. It determines the address, | 119 | * This routine handles page faults. It determines the address, |
120 | * and the problem, and then passes it off to one of the appropriate | 120 | * and the problem, and then passes it off to one of the appropriate |
121 | * routines. | 121 | * routines. |
122 | */ | 122 | */ |
123 | asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess, | 123 | asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess, |
124 | unsigned long textaccess, unsigned long address) | 124 | unsigned long textaccess, unsigned long address) |
125 | { | 125 | { |
126 | struct task_struct *tsk; | 126 | struct task_struct *tsk; |
127 | struct mm_struct *mm; | 127 | struct mm_struct *mm; |
128 | struct vm_area_struct * vma; | 128 | struct vm_area_struct * vma; |
129 | const struct exception_table_entry *fixup; | 129 | const struct exception_table_entry *fixup; |
130 | pte_t *pte; | 130 | pte_t *pte; |
131 | 131 | ||
132 | #if defined(CONFIG_SH64_PROC_TLB) | 132 | #if defined(CONFIG_SH64_PROC_TLB) |
133 | ++calls_to_do_slow_page_fault; | 133 | ++calls_to_do_slow_page_fault; |
134 | #endif | 134 | #endif |
135 | 135 | ||
136 | /* SIM | 136 | /* SIM |
137 | * Note this is now called with interrupts still disabled | 137 | * Note this is now called with interrupts still disabled |
138 | * This is to cope with being called for a missing IO port | 138 | * This is to cope with being called for a missing IO port |
139 | * address with interupts disabled. This should be fixed as | 139 | * address with interupts disabled. This should be fixed as |
140 | * soon as we have a better 'fast path' miss handler. | 140 | * soon as we have a better 'fast path' miss handler. |
141 | * | 141 | * |
142 | * Plus take care how you try and debug this stuff. | 142 | * Plus take care how you try and debug this stuff. |
143 | * For example, writing debug data to a port which you | 143 | * For example, writing debug data to a port which you |
144 | * have just faulted on is not going to work. | 144 | * have just faulted on is not going to work. |
145 | */ | 145 | */ |
146 | 146 | ||
147 | tsk = current; | 147 | tsk = current; |
148 | mm = tsk->mm; | 148 | mm = tsk->mm; |
149 | 149 | ||
150 | /* Not an IO address, so reenable interrupts */ | 150 | /* Not an IO address, so reenable interrupts */ |
151 | local_irq_enable(); | 151 | local_irq_enable(); |
152 | 152 | ||
153 | /* | 153 | /* |
154 | * If we're in an interrupt or have no user | 154 | * If we're in an interrupt or have no user |
155 | * context, we must not take the fault.. | 155 | * context, we must not take the fault.. |
156 | */ | 156 | */ |
157 | if (in_interrupt() || !mm) | 157 | if (in_interrupt() || !mm) |
158 | goto no_context; | 158 | goto no_context; |
159 | 159 | ||
160 | /* TLB misses upon some cache flushes get done under cli() */ | 160 | /* TLB misses upon some cache flushes get done under cli() */ |
161 | down_read(&mm->mmap_sem); | 161 | down_read(&mm->mmap_sem); |
162 | 162 | ||
163 | vma = find_vma(mm, address); | 163 | vma = find_vma(mm, address); |
164 | 164 | ||
165 | if (!vma) { | 165 | if (!vma) { |
166 | #ifdef DEBUG_FAULT | 166 | #ifdef DEBUG_FAULT |
167 | print_task(tsk); | 167 | print_task(tsk); |
168 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", | 168 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", |
169 | __FUNCTION__,__LINE__, | 169 | __FUNCTION__,__LINE__, |
170 | address,regs->pc,textaccess,writeaccess); | 170 | address,regs->pc,textaccess,writeaccess); |
171 | show_regs(regs); | 171 | show_regs(regs); |
172 | #endif | 172 | #endif |
173 | goto bad_area; | 173 | goto bad_area; |
174 | } | 174 | } |
175 | if (vma->vm_start <= address) { | 175 | if (vma->vm_start <= address) { |
176 | goto good_area; | 176 | goto good_area; |
177 | } | 177 | } |
178 | 178 | ||
179 | if (!(vma->vm_flags & VM_GROWSDOWN)) { | 179 | if (!(vma->vm_flags & VM_GROWSDOWN)) { |
180 | #ifdef DEBUG_FAULT | 180 | #ifdef DEBUG_FAULT |
181 | print_task(tsk); | 181 | print_task(tsk); |
182 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", | 182 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", |
183 | __FUNCTION__,__LINE__, | 183 | __FUNCTION__,__LINE__, |
184 | address,regs->pc,textaccess,writeaccess); | 184 | address,regs->pc,textaccess,writeaccess); |
185 | show_regs(regs); | 185 | show_regs(regs); |
186 | 186 | ||
187 | print_vma(vma); | 187 | print_vma(vma); |
188 | #endif | 188 | #endif |
189 | goto bad_area; | 189 | goto bad_area; |
190 | } | 190 | } |
191 | if (expand_stack(vma, address)) { | 191 | if (expand_stack(vma, address)) { |
192 | #ifdef DEBUG_FAULT | 192 | #ifdef DEBUG_FAULT |
193 | print_task(tsk); | 193 | print_task(tsk); |
194 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", | 194 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", |
195 | __FUNCTION__,__LINE__, | 195 | __FUNCTION__,__LINE__, |
196 | address,regs->pc,textaccess,writeaccess); | 196 | address,regs->pc,textaccess,writeaccess); |
197 | show_regs(regs); | 197 | show_regs(regs); |
198 | #endif | 198 | #endif |
199 | goto bad_area; | 199 | goto bad_area; |
200 | } | 200 | } |
201 | /* | 201 | /* |
202 | * Ok, we have a good vm_area for this memory access, so | 202 | * Ok, we have a good vm_area for this memory access, so |
203 | * we can handle it.. | 203 | * we can handle it.. |
204 | */ | 204 | */ |
205 | good_area: | 205 | good_area: |
206 | if (textaccess) { | 206 | if (textaccess) { |
207 | if (!(vma->vm_flags & VM_EXEC)) | 207 | if (!(vma->vm_flags & VM_EXEC)) |
208 | goto bad_area; | 208 | goto bad_area; |
209 | } else { | 209 | } else { |
210 | if (writeaccess) { | 210 | if (writeaccess) { |
211 | if (!(vma->vm_flags & VM_WRITE)) | 211 | if (!(vma->vm_flags & VM_WRITE)) |
212 | goto bad_area; | 212 | goto bad_area; |
213 | } else { | 213 | } else { |
214 | if (!(vma->vm_flags & VM_READ)) | 214 | if (!(vma->vm_flags & VM_READ)) |
215 | goto bad_area; | 215 | goto bad_area; |
216 | } | 216 | } |
217 | } | 217 | } |
218 | 218 | ||
219 | /* | 219 | /* |
220 | * If for any reason at all we couldn't handle the fault, | 220 | * If for any reason at all we couldn't handle the fault, |
221 | * make sure we exit gracefully rather than endlessly redo | 221 | * make sure we exit gracefully rather than endlessly redo |
222 | * the fault. | 222 | * the fault. |
223 | */ | 223 | */ |
224 | survive: | 224 | survive: |
225 | switch (handle_mm_fault(mm, vma, address, writeaccess)) { | 225 | switch (handle_mm_fault(mm, vma, address, writeaccess)) { |
226 | case 1: | 226 | case VM_FAULT_MINOR: |
227 | tsk->min_flt++; | 227 | tsk->min_flt++; |
228 | break; | 228 | break; |
229 | case 2: | 229 | case VM_FAULT_MAJOR: |
230 | tsk->maj_flt++; | 230 | tsk->maj_flt++; |
231 | break; | 231 | break; |
232 | case 0: | 232 | case VM_FAULT_SIGBUS: |
233 | goto do_sigbus; | 233 | goto do_sigbus; |
234 | default: | 234 | default: |
235 | goto out_of_memory; | 235 | goto out_of_memory; |
236 | } | 236 | } |
237 | /* If we get here, the page fault has been handled. Do the TLB refill | 237 | /* If we get here, the page fault has been handled. Do the TLB refill |
238 | now from the newly-setup PTE, to avoid having to fault again right | 238 | now from the newly-setup PTE, to avoid having to fault again right |
239 | away on the same instruction. */ | 239 | away on the same instruction. */ |
240 | pte = lookup_pte (mm, address); | 240 | pte = lookup_pte (mm, address); |
241 | if (!pte) { | 241 | if (!pte) { |
242 | /* From empirical evidence, we can get here, due to | 242 | /* From empirical evidence, we can get here, due to |
243 | !pte_present(pte). (e.g. if a swap-in occurs, and the page | 243 | !pte_present(pte). (e.g. if a swap-in occurs, and the page |
244 | is swapped back out again before the process that wanted it | 244 | is swapped back out again before the process that wanted it |
245 | gets rescheduled?) */ | 245 | gets rescheduled?) */ |
246 | goto no_pte; | 246 | goto no_pte; |
247 | } | 247 | } |
248 | 248 | ||
249 | __do_tlb_refill(address, textaccess, pte); | 249 | __do_tlb_refill(address, textaccess, pte); |
250 | 250 | ||
251 | no_pte: | 251 | no_pte: |
252 | 252 | ||
253 | up_read(&mm->mmap_sem); | 253 | up_read(&mm->mmap_sem); |
254 | return; | 254 | return; |
255 | 255 | ||
256 | /* | 256 | /* |
257 | * Something tried to access memory that isn't in our memory map.. | 257 | * Something tried to access memory that isn't in our memory map.. |
258 | * Fix it, but check if it's kernel or user first.. | 258 | * Fix it, but check if it's kernel or user first.. |
259 | */ | 259 | */ |
260 | bad_area: | 260 | bad_area: |
261 | #ifdef DEBUG_FAULT | 261 | #ifdef DEBUG_FAULT |
262 | printk("fault:bad area\n"); | 262 | printk("fault:bad area\n"); |
263 | #endif | 263 | #endif |
264 | up_read(&mm->mmap_sem); | 264 | up_read(&mm->mmap_sem); |
265 | 265 | ||
266 | if (user_mode(regs)) { | 266 | if (user_mode(regs)) { |
267 | static int count=0; | 267 | static int count=0; |
268 | siginfo_t info; | 268 | siginfo_t info; |
269 | if (count < 4) { | 269 | if (count < 4) { |
270 | /* This is really to help debug faults when starting | 270 | /* This is really to help debug faults when starting |
271 | * usermode, so only need a few */ | 271 | * usermode, so only need a few */ |
272 | count++; | 272 | count++; |
273 | printk("user mode bad_area address=%08lx pid=%d (%s) pc=%08lx\n", | 273 | printk("user mode bad_area address=%08lx pid=%d (%s) pc=%08lx\n", |
274 | address, current->pid, current->comm, | 274 | address, current->pid, current->comm, |
275 | (unsigned long) regs->pc); | 275 | (unsigned long) regs->pc); |
276 | #if 0 | 276 | #if 0 |
277 | show_regs(regs); | 277 | show_regs(regs); |
278 | #endif | 278 | #endif |
279 | } | 279 | } |
280 | if (tsk->pid == 1) { | 280 | if (tsk->pid == 1) { |
281 | panic("INIT had user mode bad_area\n"); | 281 | panic("INIT had user mode bad_area\n"); |
282 | } | 282 | } |
283 | tsk->thread.address = address; | 283 | tsk->thread.address = address; |
284 | tsk->thread.error_code = writeaccess; | 284 | tsk->thread.error_code = writeaccess; |
285 | info.si_signo = SIGSEGV; | 285 | info.si_signo = SIGSEGV; |
286 | info.si_errno = 0; | 286 | info.si_errno = 0; |
287 | info.si_addr = (void *) address; | 287 | info.si_addr = (void *) address; |
288 | force_sig_info(SIGSEGV, &info, tsk); | 288 | force_sig_info(SIGSEGV, &info, tsk); |
289 | return; | 289 | return; |
290 | } | 290 | } |
291 | 291 | ||
292 | no_context: | 292 | no_context: |
293 | #ifdef DEBUG_FAULT | 293 | #ifdef DEBUG_FAULT |
294 | printk("fault:No context\n"); | 294 | printk("fault:No context\n"); |
295 | #endif | 295 | #endif |
296 | /* Are we prepared to handle this kernel fault? */ | 296 | /* Are we prepared to handle this kernel fault? */ |
297 | fixup = search_exception_tables(regs->pc); | 297 | fixup = search_exception_tables(regs->pc); |
298 | if (fixup) { | 298 | if (fixup) { |
299 | regs->pc = fixup->fixup; | 299 | regs->pc = fixup->fixup; |
300 | return; | 300 | return; |
301 | } | 301 | } |
302 | 302 | ||
303 | /* | 303 | /* |
304 | * Oops. The kernel tried to access some bad page. We'll have to | 304 | * Oops. The kernel tried to access some bad page. We'll have to |
305 | * terminate things with extreme prejudice. | 305 | * terminate things with extreme prejudice. |
306 | * | 306 | * |
307 | */ | 307 | */ |
308 | if (address < PAGE_SIZE) | 308 | if (address < PAGE_SIZE) |
309 | printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); | 309 | printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); |
310 | else | 310 | else |
311 | printk(KERN_ALERT "Unable to handle kernel paging request"); | 311 | printk(KERN_ALERT "Unable to handle kernel paging request"); |
312 | printk(" at virtual address %08lx\n", address); | 312 | printk(" at virtual address %08lx\n", address); |
313 | printk(KERN_ALERT "pc = %08Lx%08Lx\n", regs->pc >> 32, regs->pc & 0xffffffff); | 313 | printk(KERN_ALERT "pc = %08Lx%08Lx\n", regs->pc >> 32, regs->pc & 0xffffffff); |
314 | die("Oops", regs, writeaccess); | 314 | die("Oops", regs, writeaccess); |
315 | do_exit(SIGKILL); | 315 | do_exit(SIGKILL); |
316 | 316 | ||
317 | /* | 317 | /* |
318 | * We ran out of memory, or some other thing happened to us that made | 318 | * We ran out of memory, or some other thing happened to us that made |
319 | * us unable to handle the page fault gracefully. | 319 | * us unable to handle the page fault gracefully. |
320 | */ | 320 | */ |
321 | out_of_memory: | 321 | out_of_memory: |
322 | if (current->pid == 1) { | 322 | if (current->pid == 1) { |
323 | panic("INIT out of memory\n"); | 323 | panic("INIT out of memory\n"); |
324 | yield(); | 324 | yield(); |
325 | goto survive; | 325 | goto survive; |
326 | } | 326 | } |
327 | printk("fault:Out of memory\n"); | 327 | printk("fault:Out of memory\n"); |
328 | up_read(&mm->mmap_sem); | 328 | up_read(&mm->mmap_sem); |
329 | if (current->pid == 1) { | 329 | if (current->pid == 1) { |
330 | yield(); | 330 | yield(); |
331 | down_read(&mm->mmap_sem); | 331 | down_read(&mm->mmap_sem); |
332 | goto survive; | 332 | goto survive; |
333 | } | 333 | } |
334 | printk("VM: killing process %s\n", tsk->comm); | 334 | printk("VM: killing process %s\n", tsk->comm); |
335 | if (user_mode(regs)) | 335 | if (user_mode(regs)) |
336 | do_exit(SIGKILL); | 336 | do_exit(SIGKILL); |
337 | goto no_context; | 337 | goto no_context; |
338 | 338 | ||
339 | do_sigbus: | 339 | do_sigbus: |
340 | printk("fault:Do sigbus\n"); | 340 | printk("fault:Do sigbus\n"); |
341 | up_read(&mm->mmap_sem); | 341 | up_read(&mm->mmap_sem); |
342 | 342 | ||
343 | /* | 343 | /* |
344 | * Send a sigbus, regardless of whether we were in kernel | 344 | * Send a sigbus, regardless of whether we were in kernel |
345 | * or user mode. | 345 | * or user mode. |
346 | */ | 346 | */ |
347 | tsk->thread.address = address; | 347 | tsk->thread.address = address; |
348 | tsk->thread.error_code = writeaccess; | 348 | tsk->thread.error_code = writeaccess; |
349 | tsk->thread.trap_no = 14; | 349 | tsk->thread.trap_no = 14; |
350 | force_sig(SIGBUS, tsk); | 350 | force_sig(SIGBUS, tsk); |
351 | 351 | ||
352 | /* Kernel mode? Handle exceptions or die */ | 352 | /* Kernel mode? Handle exceptions or die */ |
353 | if (!user_mode(regs)) | 353 | if (!user_mode(regs)) |
354 | goto no_context; | 354 | goto no_context; |
355 | } | 355 | } |
356 | 356 | ||
357 | 357 | ||
358 | void flush_tlb_all(void); | 358 | void flush_tlb_all(void); |
359 | 359 | ||
360 | void update_mmu_cache(struct vm_area_struct * vma, | 360 | void update_mmu_cache(struct vm_area_struct * vma, |
361 | unsigned long address, pte_t pte) | 361 | unsigned long address, pte_t pte) |
362 | { | 362 | { |
363 | #if defined(CONFIG_SH64_PROC_TLB) | 363 | #if defined(CONFIG_SH64_PROC_TLB) |
364 | ++calls_to_update_mmu_cache; | 364 | ++calls_to_update_mmu_cache; |
365 | #endif | 365 | #endif |
366 | 366 | ||
367 | /* | 367 | /* |
368 | * This appears to get called once for every pte entry that gets | 368 | * This appears to get called once for every pte entry that gets |
369 | * established => I don't think it's efficient to try refilling the | 369 | * established => I don't think it's efficient to try refilling the |
370 | * TLBs with the pages - some may not get accessed even. Also, for | 370 | * TLBs with the pages - some may not get accessed even. Also, for |
371 | * executable pages, it is impossible to determine reliably here which | 371 | * executable pages, it is impossible to determine reliably here which |
372 | * TLB they should be mapped into (or both even). | 372 | * TLB they should be mapped into (or both even). |
373 | * | 373 | * |
374 | * So, just do nothing here and handle faults on demand. In the | 374 | * So, just do nothing here and handle faults on demand. In the |
375 | * TLBMISS handling case, the refill is now done anyway after the pte | 375 | * TLBMISS handling case, the refill is now done anyway after the pte |
376 | * has been fixed up, so that deals with most useful cases. | 376 | * has been fixed up, so that deals with most useful cases. |
377 | */ | 377 | */ |
378 | } | 378 | } |
379 | 379 | ||
380 | static void __flush_tlb_page(struct vm_area_struct *vma, unsigned long page) | 380 | static void __flush_tlb_page(struct vm_area_struct *vma, unsigned long page) |
381 | { | 381 | { |
382 | unsigned long long match, pteh=0, lpage; | 382 | unsigned long long match, pteh=0, lpage; |
383 | unsigned long tlb; | 383 | unsigned long tlb; |
384 | struct mm_struct *mm; | 384 | struct mm_struct *mm; |
385 | 385 | ||
386 | mm = vma->vm_mm; | 386 | mm = vma->vm_mm; |
387 | 387 | ||
388 | if (mm->context == NO_CONTEXT) | 388 | if (mm->context == NO_CONTEXT) |
389 | return; | 389 | return; |
390 | 390 | ||
391 | /* | 391 | /* |
392 | * Sign-extend based on neff. | 392 | * Sign-extend based on neff. |
393 | */ | 393 | */ |
394 | lpage = (page & NEFF_SIGN) ? (page | NEFF_MASK) : page; | 394 | lpage = (page & NEFF_SIGN) ? (page | NEFF_MASK) : page; |
395 | match = ((mm->context & MMU_CONTEXT_ASID_MASK) << PTEH_ASID_SHIFT) | PTEH_VALID; | 395 | match = ((mm->context & MMU_CONTEXT_ASID_MASK) << PTEH_ASID_SHIFT) | PTEH_VALID; |
396 | match |= lpage; | 396 | match |= lpage; |
397 | 397 | ||
398 | /* Do ITLB : don't bother for pages in non-exectutable VMAs */ | 398 | /* Do ITLB : don't bother for pages in non-exectutable VMAs */ |
399 | if (vma->vm_flags & VM_EXEC) { | 399 | if (vma->vm_flags & VM_EXEC) { |
400 | for_each_itlb_entry(tlb) { | 400 | for_each_itlb_entry(tlb) { |
401 | asm volatile ("getcfg %1, 0, %0" | 401 | asm volatile ("getcfg %1, 0, %0" |
402 | : "=r" (pteh) | 402 | : "=r" (pteh) |
403 | : "r" (tlb) ); | 403 | : "r" (tlb) ); |
404 | 404 | ||
405 | if (pteh == match) { | 405 | if (pteh == match) { |
406 | __flush_tlb_slot(tlb); | 406 | __flush_tlb_slot(tlb); |
407 | break; | 407 | break; |
408 | } | 408 | } |
409 | 409 | ||
410 | } | 410 | } |
411 | } | 411 | } |
412 | 412 | ||
413 | /* Do DTLB : any page could potentially be in here. */ | 413 | /* Do DTLB : any page could potentially be in here. */ |
414 | for_each_dtlb_entry(tlb) { | 414 | for_each_dtlb_entry(tlb) { |
415 | asm volatile ("getcfg %1, 0, %0" | 415 | asm volatile ("getcfg %1, 0, %0" |
416 | : "=r" (pteh) | 416 | : "=r" (pteh) |
417 | : "r" (tlb) ); | 417 | : "r" (tlb) ); |
418 | 418 | ||
419 | if (pteh == match) { | 419 | if (pteh == match) { |
420 | __flush_tlb_slot(tlb); | 420 | __flush_tlb_slot(tlb); |
421 | break; | 421 | break; |
422 | } | 422 | } |
423 | 423 | ||
424 | } | 424 | } |
425 | } | 425 | } |
426 | 426 | ||
427 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long page) | 427 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long page) |
428 | { | 428 | { |
429 | unsigned long flags; | 429 | unsigned long flags; |
430 | 430 | ||
431 | #if defined(CONFIG_SH64_PROC_TLB) | 431 | #if defined(CONFIG_SH64_PROC_TLB) |
432 | ++calls_to_flush_tlb_page; | 432 | ++calls_to_flush_tlb_page; |
433 | #endif | 433 | #endif |
434 | 434 | ||
435 | if (vma->vm_mm) { | 435 | if (vma->vm_mm) { |
436 | page &= PAGE_MASK; | 436 | page &= PAGE_MASK; |
437 | local_irq_save(flags); | 437 | local_irq_save(flags); |
438 | __flush_tlb_page(vma, page); | 438 | __flush_tlb_page(vma, page); |
439 | local_irq_restore(flags); | 439 | local_irq_restore(flags); |
440 | } | 440 | } |
441 | } | 441 | } |
442 | 442 | ||
443 | void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, | 443 | void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, |
444 | unsigned long end) | 444 | unsigned long end) |
445 | { | 445 | { |
446 | unsigned long flags; | 446 | unsigned long flags; |
447 | unsigned long long match, pteh=0, pteh_epn, pteh_low; | 447 | unsigned long long match, pteh=0, pteh_epn, pteh_low; |
448 | unsigned long tlb; | 448 | unsigned long tlb; |
449 | struct mm_struct *mm; | 449 | struct mm_struct *mm; |
450 | 450 | ||
451 | mm = vma->vm_mm; | 451 | mm = vma->vm_mm; |
452 | 452 | ||
453 | #if defined(CONFIG_SH64_PROC_TLB) | 453 | #if defined(CONFIG_SH64_PROC_TLB) |
454 | ++calls_to_flush_tlb_range; | 454 | ++calls_to_flush_tlb_range; |
455 | 455 | ||
456 | { | 456 | { |
457 | unsigned long size = (end - 1) - start; | 457 | unsigned long size = (end - 1) - start; |
458 | size >>= 12; /* divide by PAGE_SIZE */ | 458 | size >>= 12; /* divide by PAGE_SIZE */ |
459 | size++; /* end=start+4096 => 1 page */ | 459 | size++; /* end=start+4096 => 1 page */ |
460 | switch (size) { | 460 | switch (size) { |
461 | case 1 : flush_tlb_range_1++; break; | 461 | case 1 : flush_tlb_range_1++; break; |
462 | case 2 : flush_tlb_range_2++; break; | 462 | case 2 : flush_tlb_range_2++; break; |
463 | case 3 ... 4 : flush_tlb_range_3_4++; break; | 463 | case 3 ... 4 : flush_tlb_range_3_4++; break; |
464 | case 5 ... 7 : flush_tlb_range_5_7++; break; | 464 | case 5 ... 7 : flush_tlb_range_5_7++; break; |
465 | case 8 ... 11 : flush_tlb_range_8_11++; break; | 465 | case 8 ... 11 : flush_tlb_range_8_11++; break; |
466 | case 12 ... 15 : flush_tlb_range_12_15++; break; | 466 | case 12 ... 15 : flush_tlb_range_12_15++; break; |
467 | default : flush_tlb_range_16_up++; break; | 467 | default : flush_tlb_range_16_up++; break; |
468 | } | 468 | } |
469 | } | 469 | } |
470 | #endif | 470 | #endif |
471 | 471 | ||
472 | if (mm->context == NO_CONTEXT) | 472 | if (mm->context == NO_CONTEXT) |
473 | return; | 473 | return; |
474 | 474 | ||
475 | local_irq_save(flags); | 475 | local_irq_save(flags); |
476 | 476 | ||
477 | start &= PAGE_MASK; | 477 | start &= PAGE_MASK; |
478 | end &= PAGE_MASK; | 478 | end &= PAGE_MASK; |
479 | 479 | ||
480 | match = ((mm->context & MMU_CONTEXT_ASID_MASK) << PTEH_ASID_SHIFT) | PTEH_VALID; | 480 | match = ((mm->context & MMU_CONTEXT_ASID_MASK) << PTEH_ASID_SHIFT) | PTEH_VALID; |
481 | 481 | ||
482 | /* Flush ITLB */ | 482 | /* Flush ITLB */ |
483 | for_each_itlb_entry(tlb) { | 483 | for_each_itlb_entry(tlb) { |
484 | asm volatile ("getcfg %1, 0, %0" | 484 | asm volatile ("getcfg %1, 0, %0" |
485 | : "=r" (pteh) | 485 | : "=r" (pteh) |
486 | : "r" (tlb) ); | 486 | : "r" (tlb) ); |
487 | 487 | ||
488 | pteh_epn = pteh & PAGE_MASK; | 488 | pteh_epn = pteh & PAGE_MASK; |
489 | pteh_low = pteh & ~PAGE_MASK; | 489 | pteh_low = pteh & ~PAGE_MASK; |
490 | 490 | ||
491 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) | 491 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) |
492 | __flush_tlb_slot(tlb); | 492 | __flush_tlb_slot(tlb); |
493 | } | 493 | } |
494 | 494 | ||
495 | /* Flush DTLB */ | 495 | /* Flush DTLB */ |
496 | for_each_dtlb_entry(tlb) { | 496 | for_each_dtlb_entry(tlb) { |
497 | asm volatile ("getcfg %1, 0, %0" | 497 | asm volatile ("getcfg %1, 0, %0" |
498 | : "=r" (pteh) | 498 | : "=r" (pteh) |
499 | : "r" (tlb) ); | 499 | : "r" (tlb) ); |
500 | 500 | ||
501 | pteh_epn = pteh & PAGE_MASK; | 501 | pteh_epn = pteh & PAGE_MASK; |
502 | pteh_low = pteh & ~PAGE_MASK; | 502 | pteh_low = pteh & ~PAGE_MASK; |
503 | 503 | ||
504 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) | 504 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) |
505 | __flush_tlb_slot(tlb); | 505 | __flush_tlb_slot(tlb); |
506 | } | 506 | } |
507 | 507 | ||
508 | local_irq_restore(flags); | 508 | local_irq_restore(flags); |
509 | } | 509 | } |
510 | 510 | ||
511 | void flush_tlb_mm(struct mm_struct *mm) | 511 | void flush_tlb_mm(struct mm_struct *mm) |
512 | { | 512 | { |
513 | unsigned long flags; | 513 | unsigned long flags; |
514 | 514 | ||
515 | #if defined(CONFIG_SH64_PROC_TLB) | 515 | #if defined(CONFIG_SH64_PROC_TLB) |
516 | ++calls_to_flush_tlb_mm; | 516 | ++calls_to_flush_tlb_mm; |
517 | #endif | 517 | #endif |
518 | 518 | ||
519 | if (mm->context == NO_CONTEXT) | 519 | if (mm->context == NO_CONTEXT) |
520 | return; | 520 | return; |
521 | 521 | ||
522 | local_irq_save(flags); | 522 | local_irq_save(flags); |
523 | 523 | ||
524 | mm->context=NO_CONTEXT; | 524 | mm->context=NO_CONTEXT; |
525 | if(mm==current->mm) | 525 | if(mm==current->mm) |
526 | activate_context(mm); | 526 | activate_context(mm); |
527 | 527 | ||
528 | local_irq_restore(flags); | 528 | local_irq_restore(flags); |
529 | 529 | ||
530 | } | 530 | } |
531 | 531 | ||
532 | void flush_tlb_all(void) | 532 | void flush_tlb_all(void) |
533 | { | 533 | { |
534 | /* Invalidate all, including shared pages, excluding fixed TLBs */ | 534 | /* Invalidate all, including shared pages, excluding fixed TLBs */ |
535 | 535 | ||
536 | unsigned long flags, tlb; | 536 | unsigned long flags, tlb; |
537 | 537 | ||
538 | #if defined(CONFIG_SH64_PROC_TLB) | 538 | #if defined(CONFIG_SH64_PROC_TLB) |
539 | ++calls_to_flush_tlb_all; | 539 | ++calls_to_flush_tlb_all; |
540 | #endif | 540 | #endif |
541 | 541 | ||
542 | local_irq_save(flags); | 542 | local_irq_save(flags); |
543 | 543 | ||
544 | /* Flush each ITLB entry */ | 544 | /* Flush each ITLB entry */ |
545 | for_each_itlb_entry(tlb) { | 545 | for_each_itlb_entry(tlb) { |
546 | __flush_tlb_slot(tlb); | 546 | __flush_tlb_slot(tlb); |
547 | } | 547 | } |
548 | 548 | ||
549 | /* Flush each DTLB entry */ | 549 | /* Flush each DTLB entry */ |
550 | for_each_dtlb_entry(tlb) { | 550 | for_each_dtlb_entry(tlb) { |
551 | __flush_tlb_slot(tlb); | 551 | __flush_tlb_slot(tlb); |
552 | } | 552 | } |
553 | 553 | ||
554 | local_irq_restore(flags); | 554 | local_irq_restore(flags); |
555 | } | 555 | } |
556 | 556 | ||
557 | void flush_tlb_kernel_range(unsigned long start, unsigned long end) | 557 | void flush_tlb_kernel_range(unsigned long start, unsigned long end) |
558 | { | 558 | { |
559 | /* FIXME: Optimize this later.. */ | 559 | /* FIXME: Optimize this later.. */ |
560 | flush_tlb_all(); | 560 | flush_tlb_all(); |
561 | } | 561 | } |
562 | 562 | ||
563 | #if defined(CONFIG_SH64_PROC_TLB) | 563 | #if defined(CONFIG_SH64_PROC_TLB) |
564 | /* Procfs interface to read the performance information */ | 564 | /* Procfs interface to read the performance information */ |
565 | 565 | ||
566 | static int | 566 | static int |
567 | tlb_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data) | 567 | tlb_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data) |
568 | { | 568 | { |
569 | int len=0; | 569 | int len=0; |
570 | len += sprintf(buf+len, "do_fast_page_fault called %12lld times\n", calls_to_do_fast_page_fault); | 570 | len += sprintf(buf+len, "do_fast_page_fault called %12lld times\n", calls_to_do_fast_page_fault); |
571 | len += sprintf(buf+len, "do_slow_page_fault called %12lld times\n", calls_to_do_slow_page_fault); | 571 | len += sprintf(buf+len, "do_slow_page_fault called %12lld times\n", calls_to_do_slow_page_fault); |
572 | len += sprintf(buf+len, "update_mmu_cache called %12lld times\n", calls_to_update_mmu_cache); | 572 | len += sprintf(buf+len, "update_mmu_cache called %12lld times\n", calls_to_update_mmu_cache); |
573 | len += sprintf(buf+len, "flush_tlb_page called %12lld times\n", calls_to_flush_tlb_page); | 573 | len += sprintf(buf+len, "flush_tlb_page called %12lld times\n", calls_to_flush_tlb_page); |
574 | len += sprintf(buf+len, "flush_tlb_range called %12lld times\n", calls_to_flush_tlb_range); | 574 | len += sprintf(buf+len, "flush_tlb_range called %12lld times\n", calls_to_flush_tlb_range); |
575 | len += sprintf(buf+len, "flush_tlb_mm called %12lld times\n", calls_to_flush_tlb_mm); | 575 | len += sprintf(buf+len, "flush_tlb_mm called %12lld times\n", calls_to_flush_tlb_mm); |
576 | len += sprintf(buf+len, "flush_tlb_all called %12lld times\n", calls_to_flush_tlb_all); | 576 | len += sprintf(buf+len, "flush_tlb_all called %12lld times\n", calls_to_flush_tlb_all); |
577 | len += sprintf(buf+len, "flush_tlb_range_sizes\n" | 577 | len += sprintf(buf+len, "flush_tlb_range_sizes\n" |
578 | " 1 : %12lld\n" | 578 | " 1 : %12lld\n" |
579 | " 2 : %12lld\n" | 579 | " 2 : %12lld\n" |
580 | " 3 - 4 : %12lld\n" | 580 | " 3 - 4 : %12lld\n" |
581 | " 5 - 7 : %12lld\n" | 581 | " 5 - 7 : %12lld\n" |
582 | " 8 - 11 : %12lld\n" | 582 | " 8 - 11 : %12lld\n" |
583 | "12 - 15 : %12lld\n" | 583 | "12 - 15 : %12lld\n" |
584 | "16+ : %12lld\n", | 584 | "16+ : %12lld\n", |
585 | flush_tlb_range_1, flush_tlb_range_2, flush_tlb_range_3_4, | 585 | flush_tlb_range_1, flush_tlb_range_2, flush_tlb_range_3_4, |
586 | flush_tlb_range_5_7, flush_tlb_range_8_11, flush_tlb_range_12_15, | 586 | flush_tlb_range_5_7, flush_tlb_range_8_11, flush_tlb_range_12_15, |
587 | flush_tlb_range_16_up); | 587 | flush_tlb_range_16_up); |
588 | len += sprintf(buf+len, "page not present %12lld times\n", page_not_present); | 588 | len += sprintf(buf+len, "page not present %12lld times\n", page_not_present); |
589 | *eof = 1; | 589 | *eof = 1; |
590 | return len; | 590 | return len; |
591 | } | 591 | } |
592 | 592 | ||
593 | static int __init register_proc_tlb(void) | 593 | static int __init register_proc_tlb(void) |
594 | { | 594 | { |
595 | create_proc_read_entry("tlb", 0, NULL, tlb_proc_info, NULL); | 595 | create_proc_read_entry("tlb", 0, NULL, tlb_proc_info, NULL); |
596 | return 0; | 596 | return 0; |
597 | } | 597 | } |
598 | 598 | ||
599 | __initcall(register_proc_tlb); | 599 | __initcall(register_proc_tlb); |
600 | 600 | ||
601 | #endif | 601 | #endif |
602 | 602 |