This source file includes following definitions.
- do_page_fault
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/mm.h>
15 #include <linux/interrupt.h>
16 #include <linux/extable.h>
17 #include <linux/sched/signal.h>
18
19 #include <linux/uaccess.h>
20 #include <asm/siginfo.h>
21 #include <asm/signal.h>
22
23 #define NUM_TLB_ENTRIES 64
24 #define TLB_OFFSET(add) (((add) >> PAGE_SHIFT) & (NUM_TLB_ENTRIES-1))
25
26 unsigned long pte_misses;
27 unsigned long pte_errors;
28
29
30
31
32 volatile pgd_t *current_pgd[NR_CPUS];
33
34 extern void die(char *, struct pt_regs *, long);
35
36
37
38
39
40
41
42
43
44
45 asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address,
46 unsigned long vector, int write_acc)
47 {
48 struct task_struct *tsk;
49 struct mm_struct *mm;
50 struct vm_area_struct *vma;
51 int si_code;
52 vm_fault_t fault;
53 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
54
55 tsk = current;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 if (address >= VMALLOC_START &&
77 (vector != 0x300 && vector != 0x400) &&
78 !user_mode(regs))
79 goto vmalloc_fault;
80
81
82 if (user_mode(regs)) {
83
84 local_irq_enable();
85 flags |= FAULT_FLAG_USER;
86 } else {
87
88
89
90
91 if (regs->sr && (SPR_SR_IEE | SPR_SR_TEE))
92 local_irq_enable();
93 }
94
95 mm = tsk->mm;
96 si_code = SEGV_MAPERR;
97
98
99
100
101
102
103 if (in_interrupt() || !mm)
104 goto no_context;
105
106 retry:
107 down_read(&mm->mmap_sem);
108 vma = find_vma(mm, address);
109
110 if (!vma)
111 goto bad_area;
112
113 if (vma->vm_start <= address)
114 goto good_area;
115
116 if (!(vma->vm_flags & VM_GROWSDOWN))
117 goto bad_area;
118
119 if (user_mode(regs)) {
120
121
122
123
124
125
126 if (address + PAGE_SIZE < regs->sp)
127 goto bad_area;
128 }
129 if (expand_stack(vma, address))
130 goto bad_area;
131
132
133
134
135
136
137 good_area:
138 si_code = SEGV_ACCERR;
139
140
141
142 if (write_acc) {
143 if (!(vma->vm_flags & VM_WRITE))
144 goto bad_area;
145 flags |= FAULT_FLAG_WRITE;
146 } else {
147
148 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
149 goto bad_area;
150 }
151
152
153 if ((vector == 0x400) && !(vma->vm_page_prot.pgprot & _PAGE_EXEC))
154 goto bad_area;
155
156
157
158
159
160
161
162 fault = handle_mm_fault(vma, address, flags);
163
164 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
165 return;
166
167 if (unlikely(fault & VM_FAULT_ERROR)) {
168 if (fault & VM_FAULT_OOM)
169 goto out_of_memory;
170 else if (fault & VM_FAULT_SIGSEGV)
171 goto bad_area;
172 else if (fault & VM_FAULT_SIGBUS)
173 goto do_sigbus;
174 BUG();
175 }
176
177 if (flags & FAULT_FLAG_ALLOW_RETRY) {
178
179 if (fault & VM_FAULT_MAJOR)
180 tsk->maj_flt++;
181 else
182 tsk->min_flt++;
183 if (fault & VM_FAULT_RETRY) {
184 flags &= ~FAULT_FLAG_ALLOW_RETRY;
185 flags |= FAULT_FLAG_TRIED;
186
187
188
189
190
191
192 goto retry;
193 }
194 }
195
196 up_read(&mm->mmap_sem);
197 return;
198
199
200
201
202
203
204 bad_area:
205 up_read(&mm->mmap_sem);
206
207 bad_area_nosemaphore:
208
209
210
211 if (user_mode(regs)) {
212 force_sig_fault(SIGSEGV, si_code, (void __user *)address);
213 return;
214 }
215
216 no_context:
217
218
219
220
221
222
223
224
225
226
227 {
228 const struct exception_table_entry *entry;
229
230 __asm__ __volatile__("l.nop 42");
231
232 if ((entry = search_exception_tables(regs->pc)) != NULL) {
233
234 regs->pc = entry->fixup;
235 return;
236 }
237 }
238
239
240
241
242
243
244 if ((unsigned long)(address) < PAGE_SIZE)
245 printk(KERN_ALERT
246 "Unable to handle kernel NULL pointer dereference");
247 else
248 printk(KERN_ALERT "Unable to handle kernel access");
249 printk(" at virtual address 0x%08lx\n", address);
250
251 die("Oops", regs, write_acc);
252
253 do_exit(SIGKILL);
254
255
256
257
258
259
260 out_of_memory:
261 __asm__ __volatile__("l.nop 42");
262 __asm__ __volatile__("l.nop 1");
263
264 up_read(&mm->mmap_sem);
265 if (!user_mode(regs))
266 goto no_context;
267 pagefault_out_of_memory();
268 return;
269
270 do_sigbus:
271 up_read(&mm->mmap_sem);
272
273
274
275
276
277 force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address);
278
279
280 if (!user_mode(regs))
281 goto no_context;
282 return;
283
284 vmalloc_fault:
285 {
286
287
288
289
290
291
292
293
294
295
296
297 int offset = pgd_index(address);
298 pgd_t *pgd, *pgd_k;
299 pud_t *pud, *pud_k;
300 pmd_t *pmd, *pmd_k;
301 pte_t *pte_k;
302
303
304
305
306
307
308
309
310 pgd = (pgd_t *)current_pgd[smp_processor_id()] + offset;
311 pgd_k = init_mm.pgd + offset;
312
313
314
315
316
317
318
319
320
321
322
323
324
325 pud = pud_offset(pgd, address);
326 pud_k = pud_offset(pgd_k, address);
327 if (!pud_present(*pud_k))
328 goto no_context;
329
330 pmd = pmd_offset(pud, address);
331 pmd_k = pmd_offset(pud_k, address);
332
333 if (!pmd_present(*pmd_k))
334 goto bad_area_nosemaphore;
335
336 set_pmd(pmd, *pmd_k);
337
338
339
340
341
342
343
344 pte_k = pte_offset_kernel(pmd_k, address);
345 if (!pte_present(*pte_k))
346 goto no_context;
347
348 return;
349 }
350 }