1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/mm.h>
14#include <linux/ptrace.h>
15#include <linux/sched.h>
16#include <linux/sched/debug.h>
17#include <linux/interrupt.h>
18#include <linux/extable.h>
19#include <linux/uaccess.h>
20#include <linux/hugetlb.h>
21
22#include <asm/traps.h>
23
24
25#define bit22set(x) (x & 0x00000200)
26#define bits23_25set(x) (x & 0x000001c0)
27#define isGraphicsFlushRead(x) ((x & 0xfc003fdf) == 0x04001a80)
28
29
30#define BITSSET 0x1c0
31
32
33int show_unhandled_signals = 1;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50static unsigned long
51parisc_acctyp(unsigned long code, unsigned int inst)
52{
53 if (code == 6 || code == 16)
54 return VM_EXEC;
55
56 switch (inst & 0xf0000000) {
57 case 0x40000000:
58 case 0x50000000:
59 return VM_READ;
60
61 case 0x60000000:
62 case 0x70000000:
63 return VM_WRITE;
64
65 case 0x20000000:
66 case 0x30000000:
67 if (bit22set(inst))
68 return VM_WRITE;
69
70 case 0x0:
71 if (bit22set(inst)) {
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 if (isGraphicsFlushRead(inst))
90 return VM_READ;
91 return VM_WRITE;
92 } else {
93
94
95
96
97
98
99
100
101
102
103
104
105 if (bits23_25set(inst) == BITSSET)
106 return VM_WRITE;
107 }
108 return VM_READ;
109 }
110 return VM_READ;
111}
112
113#undef bit22set
114#undef bits23_25set
115#undef isGraphicsFlushRead
116#undef BITSSET
117
118
119#if 0
120
121
122
123
124
125 while (tree != vm_avl_empty) {
126 if (tree->vm_start > addr) {
127 tree = tree->vm_avl_left;
128 } else {
129 prev = tree;
130 if (prev->vm_next == NULL)
131 break;
132 if (prev->vm_next->vm_start > addr)
133 break;
134 tree = tree->vm_avl_right;
135 }
136 }
137#endif
138
139int fixup_exception(struct pt_regs *regs)
140{
141 const struct exception_table_entry *fix;
142
143 fix = search_exception_tables(regs->iaoq[0]);
144 if (fix) {
145
146
147
148
149
150
151
152 if (fix->fixup & 1) {
153 regs->gr[8] = -EFAULT;
154
155
156 if (parisc_acctyp(0, regs->iir) == VM_READ) {
157 int treg = regs->iir & 0x1f;
158 BUG_ON(treg == 0);
159 regs->gr[treg] = 0;
160 }
161 }
162
163 regs->iaoq[0] = (unsigned long)&fix->fixup + fix->fixup;
164 regs->iaoq[0] &= ~3;
165
166
167
168
169
170
171
172 regs->iaoq[1] = regs->iaoq[0] + 4;
173 regs->gr[0] &= ~PSW_B;
174
175 return 1;
176 }
177
178 return 0;
179}
180
181
182
183
184
185
186
187
188
189
190static const char * const trap_description[] = {
191 [1] "High-priority machine check (HPMC)",
192 [2] "Power failure interrupt",
193 [3] "Recovery counter trap",
194 [5] "Low-priority machine check",
195 [6] "Instruction TLB miss fault",
196 [7] "Instruction access rights / protection trap",
197 [8] "Illegal instruction trap",
198 [9] "Break instruction trap",
199 [10] "Privileged operation trap",
200 [11] "Privileged register trap",
201 [12] "Overflow trap",
202 [13] "Conditional trap",
203 [14] "FP Assist Exception trap",
204 [15] "Data TLB miss fault",
205 [16] "Non-access ITLB miss fault",
206 [17] "Non-access DTLB miss fault",
207 [18] "Data memory protection/unaligned access trap",
208 [19] "Data memory break trap",
209 [20] "TLB dirty bit trap",
210 [21] "Page reference trap",
211 [22] "Assist emulation trap",
212 [25] "Taken branch trap",
213 [26] "Data memory access rights trap",
214 [27] "Data memory protection ID trap",
215 [28] "Unaligned data reference trap",
216};
217
218const char *trap_name(unsigned long code)
219{
220 const char *t = NULL;
221
222 if (code < ARRAY_SIZE(trap_description))
223 t = trap_description[code];
224
225 return t ? t : "Unknown trap";
226}
227
228
229
230
231
232static inline void
233show_signal_msg(struct pt_regs *regs, unsigned long code,
234 unsigned long address, struct task_struct *tsk,
235 struct vm_area_struct *vma)
236{
237 if (!unhandled_signal(tsk, SIGSEGV))
238 return;
239
240 if (!printk_ratelimit())
241 return;
242
243 pr_warn("\n");
244 pr_warn("do_page_fault() command='%s' type=%lu address=0x%08lx",
245 tsk->comm, code, address);
246 print_vma_addr(KERN_CONT " in ", regs->iaoq[0]);
247
248 pr_cont("\ntrap #%lu: %s%c", code, trap_name(code),
249 vma ? ',':'\n');
250
251 if (vma)
252 pr_cont(" vm_start = 0x%08lx, vm_end = 0x%08lx\n",
253 vma->vm_start, vma->vm_end);
254
255 show_regs(regs);
256}
257
258void do_page_fault(struct pt_regs *regs, unsigned long code,
259 unsigned long address)
260{
261 struct vm_area_struct *vma, *prev_vma;
262 struct task_struct *tsk;
263 struct mm_struct *mm;
264 unsigned long acc_type;
265 vm_fault_t fault = 0;
266 unsigned int flags;
267
268 if (faulthandler_disabled())
269 goto no_context;
270
271 tsk = current;
272 mm = tsk->mm;
273 if (!mm)
274 goto no_context;
275
276 flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
277 if (user_mode(regs))
278 flags |= FAULT_FLAG_USER;
279
280 acc_type = parisc_acctyp(code, regs->iir);
281 if (acc_type & VM_WRITE)
282 flags |= FAULT_FLAG_WRITE;
283retry:
284 down_read(&mm->mmap_sem);
285 vma = find_vma_prev(mm, address, &prev_vma);
286 if (!vma || address < vma->vm_start)
287 goto check_expansion;
288
289
290
291
292
293good_area:
294
295 if ((vma->vm_flags & acc_type) != acc_type)
296 goto bad_area;
297
298
299
300
301
302
303
304 fault = handle_mm_fault(vma, address, flags);
305
306 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
307 return;
308
309 if (unlikely(fault & VM_FAULT_ERROR)) {
310
311
312
313
314
315 if (fault & VM_FAULT_OOM)
316 goto out_of_memory;
317 else if (fault & VM_FAULT_SIGSEGV)
318 goto bad_area;
319 else if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|
320 VM_FAULT_HWPOISON_LARGE))
321 goto bad_area;
322 BUG();
323 }
324 if (flags & FAULT_FLAG_ALLOW_RETRY) {
325 if (fault & VM_FAULT_MAJOR)
326 current->maj_flt++;
327 else
328 current->min_flt++;
329 if (fault & VM_FAULT_RETRY) {
330 flags &= ~FAULT_FLAG_ALLOW_RETRY;
331
332
333
334
335
336
337
338 goto retry;
339 }
340 }
341 up_read(&mm->mmap_sem);
342 return;
343
344check_expansion:
345 vma = prev_vma;
346 if (vma && (expand_stack(vma, address) == 0))
347 goto good_area;
348
349
350
351
352bad_area:
353 up_read(&mm->mmap_sem);
354
355 if (user_mode(regs)) {
356 int signo, si_code;
357
358 switch (code) {
359 case 15:
360
361 if (!vma ||
362 address < vma->vm_start || address >= vma->vm_end) {
363 signo = SIGSEGV;
364 si_code = SEGV_MAPERR;
365 break;
366 }
367
368
369 if ((vma->vm_flags & acc_type) != acc_type) {
370 signo = SIGSEGV;
371 si_code = SEGV_ACCERR;
372 break;
373 }
374
375
376
377 case 17:
378 case 18:
379 signo = SIGBUS;
380 si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR;
381 break;
382 case 16:
383 case 26:
384 default:
385 signo = SIGSEGV;
386 si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR;
387 break;
388 }
389#ifdef CONFIG_MEMORY_FAILURE
390 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
391 unsigned int lsb = 0;
392 printk(KERN_ERR
393 "MCE: Killing %s:%d due to hardware memory corruption fault at %08lx\n",
394 tsk->comm, tsk->pid, address);
395
396
397
398
399
400 if (fault & VM_FAULT_HWPOISON_LARGE)
401 lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
402 else if (fault & VM_FAULT_HWPOISON)
403 lsb = PAGE_SHIFT;
404
405 force_sig_mceerr(BUS_MCEERR_AR, (void __user *) address,
406 lsb, current);
407 return;
408 }
409#endif
410 show_signal_msg(regs, code, address, tsk, vma);
411
412 force_sig_fault(signo, si_code, (void __user *) address, current);
413 return;
414 }
415
416no_context:
417
418 if (!user_mode(regs) && fixup_exception(regs)) {
419 return;
420 }
421
422 parisc_terminate("Bad Address (null pointer deref?)", regs, code, address);
423
424 out_of_memory:
425 up_read(&mm->mmap_sem);
426 if (!user_mode(regs))
427 goto no_context;
428 pagefault_out_of_memory();
429}
430