1
2
3
4
5
6
7#include <linux/sched.h>
8#include <linux/kernel.h>
9#include <linux/mm.h>
10#include <asm/io.h>
11
12#define __EXTERN_INLINE inline
13#include <asm/mmu_context.h>
14#include <asm/tlbflush.h>
15#undef __EXTERN_INLINE
16
17#include <linux/signal.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/types.h>
21#include <linux/ptrace.h>
22#include <linux/mman.h>
23#include <linux/smp.h>
24#include <linux/interrupt.h>
25#include <linux/module.h>
26
27#include <asm/uaccess.h>
28
29extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
30
31
32
33
34
35
36#ifndef CONFIG_SMP
37unsigned long last_asn = ASN_FIRST_VERSION;
38#endif
39
40void
41__load_new_mm_context(struct mm_struct *next_mm)
42{
43 unsigned long mmc;
44 struct pcb_struct *pcb;
45
46 mmc = __get_new_mm_context(next_mm, smp_processor_id());
47 next_mm->context[smp_processor_id()] = mmc;
48
49 pcb = ¤t_thread_info()->pcb;
50 pcb->asn = mmc & HARDWARE_ASN_MASK;
51 pcb->ptbr = ((unsigned long) next_mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
52
53 __reload_thread(pcb);
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 const struct exception_table_entry *fixup;
90 int fault, si_code = SEGV_MAPERR;
91 siginfo_t info;
92 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
93
94
95
96
97 if (cause == 0) {
98 unsigned int insn;
99 __get_user(insn, (unsigned int __user *)regs->pc);
100 if ((insn >> 21 & 0x1f) == 0x1f &&
101
102 (1ul << (insn >> 26) & 0x30f00001400ul)) {
103 regs->pc += 4;
104 return;
105 }
106 }
107
108
109
110 if (!mm || in_atomic())
111 goto no_context;
112
113#ifdef CONFIG_ALPHA_LARGE_VMALLOC
114 if (address >= TASK_SIZE)
115 goto vmalloc_fault;
116#endif
117 if (user_mode(regs))
118 flags |= FAULT_FLAG_USER;
119retry:
120 down_read(&mm->mmap_sem);
121 vma = find_vma(mm, address);
122 if (!vma)
123 goto bad_area;
124 if (vma->vm_start <= address)
125 goto good_area;
126 if (!(vma->vm_flags & VM_GROWSDOWN))
127 goto bad_area;
128 if (expand_stack(vma, address))
129 goto bad_area;
130
131
132
133 good_area:
134 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 flags |= FAULT_FLAG_WRITE;
146 }
147
148
149
150
151 fault = handle_mm_fault(mm, vma, address, flags);
152
153 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
154 return;
155
156 if (unlikely(fault & VM_FAULT_ERROR)) {
157 if (fault & VM_FAULT_OOM)
158 goto out_of_memory;
159 else if (fault & VM_FAULT_SIGBUS)
160 goto do_sigbus;
161 BUG();
162 }
163
164 if (flags & FAULT_FLAG_ALLOW_RETRY) {
165 if (fault & VM_FAULT_MAJOR)
166 current->maj_flt++;
167 else
168 current->min_flt++;
169 if (fault & VM_FAULT_RETRY) {
170 flags &= ~FAULT_FLAG_ALLOW_RETRY;
171
172
173
174
175
176
177 goto retry;
178 }
179 }
180
181 up_read(&mm->mmap_sem);
182
183 return;
184
185
186
187 bad_area:
188 up_read(&mm->mmap_sem);
189
190 if (user_mode(regs))
191 goto do_sigsegv;
192
193 no_context:
194
195 if ((fixup = search_exception_tables(regs->pc)) != 0) {
196 unsigned long newpc;
197 newpc = fixup_exception(dpf_reg, fixup, regs->pc);
198 regs->pc = newpc;
199 return;
200 }
201
202
203
204 printk(KERN_ALERT "Unable to handle kernel paging request at "
205 "virtual address %016lx\n", address);
206 die_if_kernel("Oops", regs, cause, (unsigned long*)regs - 16);
207 do_exit(SIGKILL);
208
209
210
211 out_of_memory:
212 up_read(&mm->mmap_sem);
213 if (!user_mode(regs))
214 goto no_context;
215 pagefault_out_of_memory();
216 return;
217
218 do_sigbus:
219 up_read(&mm->mmap_sem);
220
221
222 info.si_signo = SIGBUS;
223 info.si_errno = 0;
224 info.si_code = BUS_ADRERR;
225 info.si_addr = (void __user *) address;
226 force_sig_info(SIGBUS, &info, current);
227 if (!user_mode(regs))
228 goto no_context;
229 return;
230
231 do_sigsegv:
232 info.si_signo = SIGSEGV;
233 info.si_errno = 0;
234 info.si_code = si_code;
235 info.si_addr = (void __user *) address;
236 force_sig_info(SIGSEGV, &info, current);
237 return;
238
239#ifdef CONFIG_ALPHA_LARGE_VMALLOC
240 vmalloc_fault:
241 if (user_mode(regs))
242 goto do_sigsegv;
243 else {
244
245
246 long index = pgd_index(address);
247 pgd_t *pgd, *pgd_k;
248
249 pgd = current->active_mm->pgd + index;
250 pgd_k = swapper_pg_dir + index;
251 if (!pgd_present(*pgd) && pgd_present(*pgd_k)) {
252 pgd_val(*pgd) = pgd_val(*pgd_k);
253 return;
254 }
255 goto no_context;
256 }
257#endif
258}
259