1
2
3
4
5
6
7#include <linux/config.h>
8#include <linux/sched.h>
9#include <linux/kernel.h>
10#include <linux/mm.h>
11#include <asm/io.h>
12
13#define __EXTERN_INLINE inline
14#include <asm/mmu_context.h>
15#include <asm/pgalloc.h>
16#undef __EXTERN_INLINE
17
18#include <linux/signal.h>
19#include <linux/errno.h>
20#include <linux/string.h>
21#include <linux/types.h>
22#include <linux/ptrace.h>
23#include <linux/mman.h>
24#include <linux/smp.h>
25#include <linux/smp_lock.h>
26#include <linux/interrupt.h>
27
28#include <asm/system.h>
29#include <asm/uaccess.h>
30
31extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
32
33
34
35
36
37
38#ifndef CONFIG_SMP
39unsigned long last_asn = ASN_FIRST_VERSION;
40#endif
41
42extern void
43__load_new_mm_context(struct mm_struct *next_mm)
44{
45 unsigned long mmc;
46
47 mmc = __get_new_mm_context(next_mm, smp_processor_id());
48 next_mm->context[smp_processor_id()] = mmc;
49 current->thread.asn = mmc & HARDWARE_ASN_MASK;
50 current->thread.ptbr
51 = ((unsigned long) next_mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
52
53 __reload_thread(¤t->thread);
54}
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79#define dpf_reg(r) \
80 (((unsigned long *)regs)[(r) <= 8 ? (r) : (r) <= 15 ? (r)-16 : \
81 (r) <= 18 ? (r)+8 : (r)-10])
82
83asmlinkage void
84do_page_fault(unsigned long address, unsigned long mmcsr,
85 long cause, struct pt_regs *regs)
86{
87 struct vm_area_struct * vma;
88 struct mm_struct *mm = current->mm;
89 unsigned int fixup;
90 int fault;
91 siginfo_t info;
92
93
94
95
96 if (cause == 0) {
97 unsigned int insn;
98 __get_user(insn, (unsigned int *)regs->pc);
99 if ((insn >> 21 & 0x1f) == 0x1f &&
100
101 (1ul << (insn >> 26) & 0x30f00001400ul)) {
102 regs->pc += 4;
103 return;
104 }
105 }
106
107
108
109 if (!mm || in_interrupt())
110 goto no_context;
111
112 info.si_code = SEGV_MAPERR;
113
114#ifdef CONFIG_ALPHA_LARGE_VMALLOC
115 if (address >= TASK_SIZE)
116 goto vmalloc_fault;
117#endif
118
119 down_read(&mm->mmap_sem);
120 vma = find_vma(mm, address);
121 if (!vma)
122 goto bad_area;
123 if (vma->vm_start <= address)
124 goto good_area;
125 if (!(vma->vm_flags & VM_GROWSDOWN))
126 goto bad_area;
127 if (expand_stack(vma, address))
128 goto bad_area;
129
130
131
132
133good_area:
134 info.si_code = SEGV_ACCERR;
135 if (cause < 0) {
136 if (!(vma->vm_flags & VM_EXEC))
137 goto bad_area;
138 } else if (!cause) {
139
140 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
141 goto bad_area;
142 } else {
143 if (!(vma->vm_flags & VM_WRITE))
144 goto bad_area;
145 }
146
147 survive:
148
149
150
151
152
153 fault = handle_mm_fault(mm, vma, address, cause > 0);
154 if (fault < 0)
155 goto out_of_memory;
156 if (fault == 0)
157 goto do_sigbus;
158
159 up_read(&mm->mmap_sem);
160 return;
161
162
163
164
165
166bad_area:
167 up_read(&mm->mmap_sem);
168
169 if (user_mode(regs)) {
170
171 info.si_signo = SIGSEGV;
172 info.si_errno = 0;
173
174 info.si_addr = (void *)address;
175 force_sig_info(SIGSEGV,&info,current);
176 return;
177 }
178
179no_context:
180
181 if ((fixup = search_exception_table(regs->pc, regs->gp)) != 0) {
182 unsigned long newpc;
183 newpc = fixup_exception(dpf_reg, fixup, regs->pc);
184#if 0
185 printk("%s: Exception at [<%lx>] (%lx) handled successfully\n",
186 current->comm, regs->pc, newpc);
187#endif
188 regs->pc = newpc;
189 return;
190 }
191
192
193
194
195
196 printk(KERN_ALERT "Unable to handle kernel paging request at "
197 "virtual address %016lx\n", address);
198 die_if_kernel("Oops", regs, cause, (unsigned long*)regs - 16);
199 do_exit(SIGKILL);
200
201
202
203
204
205out_of_memory:
206 if (current->pid == 1) {
207 yield();
208 goto survive;
209 }
210 up_read(&mm->mmap_sem);
211 printk(KERN_ALERT "VM: killing process %s(%d)\n",
212 current->comm, current->pid);
213 if (!user_mode(regs))
214 goto no_context;
215 do_exit(SIGKILL);
216
217do_sigbus:
218 up_read(&mm->mmap_sem);
219
220
221
222
223 info.si_signo = SIGBUS;
224 info.si_errno = 0;
225
226 info.si_code = BUS_ADRERR;
227 info.si_addr = (void *)address;
228 force_sig_info(SIGBUS,&info,current);
229 if (!user_mode(regs))
230 goto no_context;
231 return;
232
233#ifdef CONFIG_ALPHA_LARGE_VMALLOC
234vmalloc_fault:
235 if (user_mode(regs)) {
236 info.si_signo = SIGSEGV;
237 info.si_errno = 0;
238
239 info.si_addr = (void *)address;
240 force_sig_info(SIGSEGV,&info,current);
241 return;
242 } else {
243
244
245 long offset = __pgd_offset(address);
246 pgd_t *pgd, *pgd_k;
247
248 pgd = current->active_mm->pgd + offset;
249 pgd_k = swapper_pg_dir + offset;
250 if (!pgd_present(*pgd) && pgd_present(*pgd_k)) {
251 pgd_val(*pgd) = pgd_val(*pgd_k);
252 return;
253 }
254 goto no_context;
255 }
256#endif
257}
258