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/interrupt.h>
17#include <linux/module.h>
18
19#include <asm/uaccess.h>
20#include <asm/traps.h>
21
22
23#define bit22set(x) (x & 0x00000200)
24#define bits23_25set(x) (x & 0x000001c0)
25#define isGraphicsFlushRead(x) ((x & 0xfc003fdf) == 0x04001a80)
26
27
28#define BITSSET 0x1c0
29
30
31DEFINE_PER_CPU(struct exception_data, exception_data);
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
144
145 if ((sizeof(regs->iaoq[0]) > sizeof(fix->insn))
146 && (regs->iaoq[0] >> 32))
147 return 0;
148
149 fix = search_exception_tables(regs->iaoq[0]);
150 if (fix) {
151 struct exception_data *d;
152 d = this_cpu_ptr(&exception_data);
153 d->fault_ip = regs->iaoq[0];
154 d->fault_space = regs->isr;
155 d->fault_addr = regs->ior;
156
157 regs->iaoq[0] = ((fix->fixup) & ~3);
158
159
160
161
162
163
164
165 regs->iaoq[1] = regs->iaoq[0] + 4;
166 regs->gr[0] &= ~PSW_B;
167
168 return 1;
169 }
170
171 return 0;
172}
173
174
175
176
177
178static inline void
179show_signal_msg(struct pt_regs *regs, unsigned long code,
180 unsigned long address, struct task_struct *tsk,
181 struct vm_area_struct *vma)
182{
183 if (!unhandled_signal(tsk, SIGSEGV))
184 return;
185
186 if (!printk_ratelimit())
187 return;
188
189 pr_warn("\n");
190 pr_warn("do_page_fault() command='%s' type=%lu address=0x%08lx",
191 tsk->comm, code, address);
192 print_vma_addr(KERN_CONT " in ", regs->iaoq[0]);
193 if (vma)
194 pr_warn(" vm_start = 0x%08lx, vm_end = 0x%08lx\n",
195 vma->vm_start, vma->vm_end);
196
197 show_regs(regs);
198}
199
200void do_page_fault(struct pt_regs *regs, unsigned long code,
201 unsigned long address)
202{
203 struct vm_area_struct *vma, *prev_vma;
204 struct task_struct *tsk;
205 struct mm_struct *mm;
206 unsigned long acc_type;
207 int fault;
208 unsigned int flags;
209
210 if (in_atomic())
211 goto no_context;
212
213 tsk = current;
214 mm = tsk->mm;
215 if (!mm)
216 goto no_context;
217
218 flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
219 if (user_mode(regs))
220 flags |= FAULT_FLAG_USER;
221
222 acc_type = parisc_acctyp(code, regs->iir);
223 if (acc_type & VM_WRITE)
224 flags |= FAULT_FLAG_WRITE;
225retry:
226 down_read(&mm->mmap_sem);
227 vma = find_vma_prev(mm, address, &prev_vma);
228 if (!vma || address < vma->vm_start)
229 goto check_expansion;
230
231
232
233
234
235good_area:
236
237 if ((vma->vm_flags & acc_type) != acc_type)
238 goto bad_area;
239
240
241
242
243
244
245
246 fault = handle_mm_fault(mm, vma, address, flags);
247
248 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
249 return;
250
251 if (unlikely(fault & VM_FAULT_ERROR)) {
252
253
254
255
256
257 if (fault & VM_FAULT_OOM)
258 goto out_of_memory;
259 else if (fault & VM_FAULT_SIGSEGV)
260 goto bad_area;
261 else if (fault & VM_FAULT_SIGBUS)
262 goto bad_area;
263 BUG();
264 }
265 if (flags & FAULT_FLAG_ALLOW_RETRY) {
266 if (fault & VM_FAULT_MAJOR)
267 current->maj_flt++;
268 else
269 current->min_flt++;
270 if (fault & VM_FAULT_RETRY) {
271 flags &= ~FAULT_FLAG_ALLOW_RETRY;
272
273
274
275
276
277
278
279 goto retry;
280 }
281 }
282 up_read(&mm->mmap_sem);
283 return;
284
285check_expansion:
286 vma = prev_vma;
287 if (vma && (expand_stack(vma, address) == 0))
288 goto good_area;
289
290
291
292
293bad_area:
294 up_read(&mm->mmap_sem);
295
296 if (user_mode(regs)) {
297 struct siginfo si;
298
299 show_signal_msg(regs, code, address, tsk, vma);
300
301 switch (code) {
302 case 15:
303
304 if (!vma ||
305 address < vma->vm_start || address > vma->vm_end) {
306 si.si_signo = SIGSEGV;
307 si.si_code = SEGV_MAPERR;
308 break;
309 }
310
311
312 if ((vma->vm_flags & acc_type) != acc_type) {
313 si.si_signo = SIGSEGV;
314 si.si_code = SEGV_ACCERR;
315 break;
316 }
317
318
319
320 case 17:
321 case 18:
322 si.si_signo = SIGBUS;
323 si.si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR;
324 break;
325 case 16:
326 case 26:
327 default:
328 si.si_signo = SIGSEGV;
329 si.si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR;
330 break;
331 }
332 si.si_errno = 0;
333 si.si_addr = (void __user *) address;
334 force_sig_info(si.si_signo, &si, current);
335 return;
336 }
337
338no_context:
339
340 if (!user_mode(regs) && fixup_exception(regs)) {
341 return;
342 }
343
344 parisc_terminate("Bad Address (null pointer deref?)", regs, code, address);
345
346 out_of_memory:
347 up_read(&mm->mmap_sem);
348 if (!user_mode(regs))
349 goto no_context;
350 pagefault_out_of_memory();
351}
352