1
2
3
4
5
6
7
8#include <linux/sched/signal.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/tlbflush.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/interrupt.h>
26#include <linux/extable.h>
27#include <linux/uaccess.h>
28#include <linux/perf_event.h>
29
30extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
31
32
33
34
35
36
37#ifndef CONFIG_SMP
38unsigned long last_asn = ASN_FIRST_VERSION;
39#endif
40
41void
42__load_new_mm_context(struct mm_struct *next_mm)
43{
44 unsigned long mmc;
45 struct pcb_struct *pcb;
46
47 mmc = __get_new_mm_context(next_mm, smp_processor_id());
48 next_mm->context[smp_processor_id()] = mmc;
49
50 pcb = ¤t_thread_info()->pcb;
51 pcb->asn = mmc & HARDWARE_ASN_MASK;
52 pcb->ptbr = ((unsigned long) next_mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
53
54 __reload_thread(pcb);
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
80#define dpf_reg(r) \
81 (((unsigned long *)regs)[(r) <= 8 ? (r) : (r) <= 15 ? (r)-16 : \
82 (r) <= 18 ? (r)+10 : (r)-10])
83
84asmlinkage void
85do_page_fault(unsigned long address, unsigned long mmcsr,
86 long cause, struct pt_regs *regs)
87{
88 struct vm_area_struct * vma;
89 struct mm_struct *mm = current->mm;
90 const struct exception_table_entry *fixup;
91 int si_code = SEGV_MAPERR;
92 vm_fault_t fault;
93 unsigned int flags = FAULT_FLAG_DEFAULT;
94
95
96
97
98 if (cause == 0) {
99 unsigned int insn;
100 __get_user(insn, (unsigned int __user *)regs->pc);
101 if ((insn >> 21 & 0x1f) == 0x1f &&
102
103 (1ul << (insn >> 26) & 0x30f00001400ul)) {
104 regs->pc += 4;
105 return;
106 }
107 }
108
109
110
111 if (!mm || faulthandler_disabled())
112 goto no_context;
113
114#ifdef CONFIG_ALPHA_LARGE_VMALLOC
115 if (address >= TASK_SIZE)
116 goto vmalloc_fault;
117#endif
118 if (user_mode(regs))
119 flags |= FAULT_FLAG_USER;
120 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
121retry:
122 mmap_read_lock(mm);
123 vma = find_vma(mm, address);
124 if (!vma)
125 goto bad_area;
126 if (vma->vm_start <= address)
127 goto good_area;
128 if (!(vma->vm_flags & VM_GROWSDOWN))
129 goto bad_area;
130 if (expand_stack(vma, address))
131 goto bad_area;
132
133
134
135 good_area:
136 si_code = SEGV_ACCERR;
137 if (cause < 0) {
138 if (!(vma->vm_flags & VM_EXEC))
139 goto bad_area;
140 } else if (!cause) {
141
142 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
143 goto bad_area;
144 } else {
145 if (!(vma->vm_flags & VM_WRITE))
146 goto bad_area;
147 flags |= FAULT_FLAG_WRITE;
148 }
149
150
151
152
153 fault = handle_mm_fault(vma, address, flags, regs);
154
155 if (fault_signal_pending(fault, regs))
156 return;
157
158 if (unlikely(fault & VM_FAULT_ERROR)) {
159 if (fault & VM_FAULT_OOM)
160 goto out_of_memory;
161 else if (fault & VM_FAULT_SIGSEGV)
162 goto bad_area;
163 else if (fault & VM_FAULT_SIGBUS)
164 goto do_sigbus;
165 BUG();
166 }
167
168 if (flags & FAULT_FLAG_ALLOW_RETRY) {
169 if (fault & VM_FAULT_RETRY) {
170 flags |= FAULT_FLAG_TRIED;
171
172
173
174
175
176
177 goto retry;
178 }
179 }
180
181 mmap_read_unlock(mm);
182
183 return;
184
185
186
187 bad_area:
188 mmap_read_unlock(mm);
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 mmap_read_unlock(mm);
213 if (!user_mode(regs))
214 goto no_context;
215 pagefault_out_of_memory();
216 return;
217
218 do_sigbus:
219 mmap_read_unlock(mm);
220
221
222 force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *) address);
223 if (!user_mode(regs))
224 goto no_context;
225 return;
226
227 do_sigsegv:
228 force_sig_fault(SIGSEGV, si_code, (void __user *) address);
229 return;
230
231#ifdef CONFIG_ALPHA_LARGE_VMALLOC
232 vmalloc_fault:
233 if (user_mode(regs))
234 goto do_sigsegv;
235 else {
236
237
238 long index = pgd_index(address);
239 pgd_t *pgd, *pgd_k;
240
241 pgd = current->active_mm->pgd + index;
242 pgd_k = swapper_pg_dir + index;
243 if (!pgd_present(*pgd) && pgd_present(*pgd_k)) {
244 pgd_val(*pgd) = pgd_val(*pgd_k);
245 return;
246 }
247 goto no_context;
248 }
249#endif
250}
251