2 * linux/arch/alpha/mm/fault.c
4 * Copyright (C) 1995 Linus Torvalds
7 #include <linux/sched.h>
8 #include <linux/kernel.h>
12 #define __EXTERN_INLINE inline
13 #include <asm/mmu_context.h>
14 #include <asm/tlbflush.h>
15 #undef __EXTERN_INLINE
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/smp_lock.h>
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
28 #include <asm/system.h>
29 #include <asm/uaccess.h>
31 extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
35 * Force a new ASN for a task.
39 unsigned long last_asn = ASN_FIRST_VERSION;
43 __load_new_mm_context(struct mm_struct *next_mm)
46 struct pcb_struct *pcb;
48 mmc = __get_new_mm_context(next_mm, smp_processor_id());
49 next_mm->context[smp_processor_id()] = mmc;
51 pcb = ¤t_thread_info()->pcb;
52 pcb->asn = mmc & HARDWARE_ASN_MASK;
53 pcb->ptbr = ((unsigned long) next_mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
60 * This routine handles page faults. It determines the address,
61 * and the problem, and then passes it off to handle_mm_fault().
64 * 0 = translation not valid
65 * 1 = access violation
67 * 3 = fault-on-execute
71 * -1 = instruction fetch
75 * Registers $9 through $15 are saved in a block just prior to `regs' and
76 * are saved and restored around the call to allow exception code to
80 /* Macro for exception fixup code to access integer registers. */
82 (((unsigned long *)regs)[(r) <= 8 ? (r) : (r) <= 15 ? (r)-16 : \
83 (r) <= 18 ? (r)+8 : (r)-10])
86 do_page_fault(unsigned long address, unsigned long mmcsr,
87 long cause, struct pt_regs *regs)
89 struct vm_area_struct * vma;
90 struct mm_struct *mm = current->mm;
91 const struct exception_table_entry *fixup;
92 int fault, si_code = SEGV_MAPERR;
95 /* As of EV6, a load into $31/$f31 is a prefetch, and never faults
96 (or is suppressed by the PALcode). Support that for older CPUs
97 by ignoring such an instruction. */
100 __get_user(insn, (unsigned int __user *)regs->pc);
101 if ((insn >> 21 & 0x1f) == 0x1f &&
102 /* ldq ldl ldt lds ldg ldf ldwu ldbu */
103 (1ul << (insn >> 26) & 0x30f00001400ul)) {
109 /* If we're in an interrupt context, or have no user context,
110 we must not take the fault. */
111 if (!mm || in_interrupt())
114 #ifdef CONFIG_ALPHA_LARGE_VMALLOC
115 if (address >= TASK_SIZE)
119 down_read(&mm->mmap_sem);
120 vma = find_vma(mm, address);
123 if (vma->vm_start <= address)
125 if (!(vma->vm_flags & VM_GROWSDOWN))
127 if (expand_stack(vma, address))
130 /* Ok, we have a good vm_area for this memory access, so
133 si_code = SEGV_ACCERR;
135 if (!(vma->vm_flags & VM_EXEC))
138 /* Allow reads even for write-only mappings */
139 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
142 if (!(vma->vm_flags & VM_WRITE))
147 /* If for any reason at all we couldn't handle the fault,
148 make sure we exit gracefully rather than endlessly redo
150 fault = handle_mm_fault(mm, vma, address, cause > 0);
151 up_read(&mm->mmap_sem);
160 case VM_FAULT_SIGBUS:
169 /* Something tried to access memory that isn't in our memory map.
170 Fix it, but check if it's kernel or user first. */
172 up_read(&mm->mmap_sem);
178 /* Are we prepared to handle this fault as an exception? */
179 if ((fixup = search_exception_tables(regs->pc)) != 0) {
181 newpc = fixup_exception(dpf_reg, fixup, regs->pc);
186 /* Oops. The kernel tried to access some bad page. We'll have to
187 terminate things with extreme prejudice. */
188 printk(KERN_ALERT "Unable to handle kernel paging request at "
189 "virtual address %016lx\n", address);
190 die_if_kernel("Oops", regs, cause, (unsigned long*)regs - 16);
193 /* We ran out of memory, or some other thing happened to us that
194 made us unable to handle the page fault gracefully. */
196 if (is_init(current)) {
198 down_read(&mm->mmap_sem);
201 printk(KERN_ALERT "VM: killing process %s(%d)\n",
202 current->comm, current->pid);
203 if (!user_mode(regs))
208 /* Send a sigbus, regardless of whether we were in kernel
210 info.si_signo = SIGBUS;
212 info.si_code = BUS_ADRERR;
213 info.si_addr = (void __user *) address;
214 force_sig_info(SIGBUS, &info, current);
215 if (!user_mode(regs))
220 info.si_signo = SIGSEGV;
222 info.si_code = si_code;
223 info.si_addr = (void __user *) address;
224 force_sig_info(SIGSEGV, &info, current);
227 #ifdef CONFIG_ALPHA_LARGE_VMALLOC
232 /* Synchronize this task's top level page-table
233 with the "reference" page table from init. */
234 long index = pgd_index(address);
237 pgd = current->active_mm->pgd + index;
238 pgd_k = swapper_pg_dir + index;
239 if (!pgd_present(*pgd) && pgd_present(*pgd_k)) {
240 pgd_val(*pgd) = pgd_val(*pgd_k);