2 * linux/arch/frv/mm/fault.c
4 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
5 * - Written by David Howells (dhowells@redhat.com)
6 * - Derived from arch/m68knommu/mm/fault.c
7 * - Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
8 * - Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
12 * linux/arch/m68k/mm/fault.c
14 * Copyright (C) 1995 Hamish Macdonald
17 #include <linux/mman.h>
19 #include <linux/kernel.h>
20 #include <linux/ptrace.h>
21 #include <linux/hardirq.h>
23 #include <asm/system.h>
24 #include <asm/pgtable.h>
25 #include <asm/uaccess.h>
26 #include <asm/gdb-stub.h>
28 /*****************************************************************************/
30 * This routine handles page faults. It determines the problem, and
31 * then passes it off to one of the appropriate routines.
33 asmlinkage
void do_page_fault(int datammu
, unsigned long esr0
, unsigned long ear0
)
35 struct vm_area_struct
*vma
;
37 unsigned long _pme
, lrai
, lrad
, fixup
;
46 const char *atxc
[16] = {
47 [0x0] = "mmu-miss", [0x8] = "multi-dat", [0x9] = "multi-sat",
48 [0xa] = "tlb-miss", [0xc] = "privilege", [0xd] = "write-prot",
51 printk("do_page_fault(%d,%lx [%s],%lx)\n",
52 datammu
, esr0
, atxc
[esr0
>> 20 & 0xf], ear0
);
58 * We fault-in kernel-space virtual memory on-demand. The
59 * 'reference' page table is init_mm.pgd.
61 * NOTE! We MUST NOT take any locks for this case. We may
62 * be in an interrupt or a critical region, and should
63 * only copy the information from the master page table,
66 * This verifies that the fault happens in kernel space
67 * and that the fault was a page not present (invalid) error
69 if (!user_mode(__frame
) && (esr0
& ESR0_ATXC
) == ESR0_ATXC_AMRTLB_MISS
) {
70 if (ear0
>= VMALLOC_START
&& ear0
< VMALLOC_END
)
71 goto kernel_pte_fault
;
72 if (ear0
>= PKMAP_BASE
&& ear0
< PKMAP_END
)
73 goto kernel_pte_fault
;
76 info
.si_code
= SEGV_MAPERR
;
79 * If we're in an interrupt or have no user
80 * context, we must not take the fault..
82 if (in_atomic() || !mm
)
85 down_read(&mm
->mmap_sem
);
87 vma
= find_vma(mm
, ear0
);
90 if (vma
->vm_start
<= ear0
)
92 if (!(vma
->vm_flags
& VM_GROWSDOWN
))
95 if (user_mode(__frame
)) {
97 * accessing the stack below %esp is always a bug.
98 * The "+ 32" is there due to some instructions (like
99 * pusha) doing post-decrement on the stack and that
100 * doesn't show up until later..
102 if ((ear0
& PAGE_MASK
) + 2 * PAGE_SIZE
< __frame
->sp
) {
104 printk("[%d] ### Access below stack @%lx (sp=%lx)\n",
105 current
->pid
, ear0
, __frame
->sp
);
106 show_registers(__frame
);
107 printk("[%d] ### Code: [%08lx] %02x %02x %02x %02x %02x %02x %02x %02x\n",
110 ((u8
*)__frame
->pc
)[0],
111 ((u8
*)__frame
->pc
)[1],
112 ((u8
*)__frame
->pc
)[2],
113 ((u8
*)__frame
->pc
)[3],
114 ((u8
*)__frame
->pc
)[4],
115 ((u8
*)__frame
->pc
)[5],
116 ((u8
*)__frame
->pc
)[6],
117 ((u8
*)__frame
->pc
)[7]
124 if (expand_stack(vma
, ear0
))
128 * Ok, we have a good vm_area for this memory access, so
132 info
.si_code
= SEGV_ACCERR
;
134 switch (esr0
& ESR0_ATXC
) {
136 /* handle write to write protected page */
137 case ESR0_ATXC_WP_EXCEP
:
138 #ifdef TEST_VERIFY_AREA
139 if (!(user_mode(__frame
)))
140 printk("WP fault at %08lx\n", __frame
->pc
);
142 if (!(vma
->vm_flags
& VM_WRITE
))
147 /* handle read from protected page */
148 case ESR0_ATXC_PRIV_EXCEP
:
151 /* handle read, write or exec on absent page
152 * - can't support write without permitting read
153 * - don't support execute without permitting read and vice-versa
155 case ESR0_ATXC_AMRTLB_MISS
:
156 if (!(vma
->vm_flags
& (VM_READ
| VM_WRITE
| VM_EXEC
)))
162 * If for any reason at all we couldn't handle the fault,
163 * make sure we exit gracefully rather than endlessly redo
166 fault
= handle_mm_fault(mm
, vma
, ear0
, write
? FAULT_FLAG_WRITE
: 0);
167 if (unlikely(fault
& VM_FAULT_ERROR
)) {
168 if (fault
& VM_FAULT_OOM
)
170 else if (fault
& VM_FAULT_SIGBUS
)
174 if (fault
& VM_FAULT_MAJOR
)
179 up_read(&mm
->mmap_sem
);
183 * Something tried to access memory that isn't in our memory map..
184 * Fix it, but check if it's kernel or user first..
187 up_read(&mm
->mmap_sem
);
189 /* User mode accesses just cause a SIGSEGV */
190 if (user_mode(__frame
)) {
191 info
.si_signo
= SIGSEGV
;
193 /* info.si_code has been set above */
194 info
.si_addr
= (void *) ear0
;
195 force_sig_info(SIGSEGV
, &info
, current
);
200 /* are we prepared to handle this kernel fault? */
201 if ((fixup
= search_exception_table(__frame
->pc
)) != 0) {
207 * Oops. The kernel tried to access some bad page. We'll have to
208 * terminate things with extreme prejudice.
213 if (ear0
< PAGE_SIZE
)
214 printk(KERN_ALERT
"Unable to handle kernel NULL pointer dereference");
216 printk(KERN_ALERT
"Unable to handle kernel paging request");
217 printk(" at virtual addr %08lx\n", ear0
);
218 printk(" PC : %08lx\n", __frame
->pc
);
219 printk(" EXC : esr0=%08lx ear0=%08lx\n", esr0
, ear0
);
221 asm("lrai %1,%0,#1,#0,#0" : "=&r"(lrai
) : "r"(ear0
));
222 asm("lrad %1,%0,#1,#0,#0" : "=&r"(lrad
) : "r"(ear0
));
224 printk(KERN_ALERT
" LRAI: %08lx\n", lrai
);
225 printk(KERN_ALERT
" LRAD: %08lx\n", lrad
);
227 __break_hijack_kernel_event();
229 pge
= pgd_offset(current
->mm
, ear0
);
230 pue
= pud_offset(pge
, ear0
);
231 _pme
= pue
->pue
[0].ste
[0];
233 printk(KERN_ALERT
" PGE : %8p { PME %08lx }\n", pge
, _pme
);
235 if (_pme
& xAMPRx_V
) {
236 unsigned long dampr
, damlr
, val
;
238 asm volatile("movsg dampr2,%0 ! movgs %2,dampr2 ! movsg damlr2,%1"
239 : "=&r"(dampr
), "=r"(damlr
)
240 : "r" (_pme
| xAMPRx_L
|xAMPRx_SS_16Kb
|xAMPRx_S
|xAMPRx_C
|xAMPRx_V
)
243 pte
= (pte_t
*) damlr
+ __pte_index(ear0
);
246 asm volatile("movgs %0,dampr2" :: "r" (dampr
));
248 printk(KERN_ALERT
" PTE : %8p { %08lx }\n", pte
, val
);
251 die_if_kernel("Oops\n");
255 * We ran out of memory, or some other thing happened to us that made
256 * us unable to handle the page fault gracefully.
259 up_read(&mm
->mmap_sem
);
260 printk("VM: killing process %s\n", current
->comm
);
261 if (user_mode(__frame
))
262 do_group_exit(SIGKILL
);
266 up_read(&mm
->mmap_sem
);
269 * Send a sigbus, regardless of whether we were in kernel
272 info
.si_signo
= SIGBUS
;
274 info
.si_code
= BUS_ADRERR
;
275 info
.si_addr
= (void *) ear0
;
276 force_sig_info(SIGBUS
, &info
, current
);
278 /* Kernel mode? Handle exceptions or die */
279 if (!user_mode(__frame
))
284 * The fault was caused by a kernel PTE (such as installed by vmalloc or kmap)
289 * Synchronize this task's top level page-table
290 * with the 'reference' page table.
292 * Do _not_ use "tsk" here. We might be inside
293 * an interrupt in the middle of a task switch..
295 int index
= pgd_index(ear0
);
301 pgd
= (pgd_t
*) __get_TTBR();
302 pgd
= (pgd_t
*)__va(pgd
) + index
;
303 pgd_k
= ((pgd_t
*)(init_mm
.pgd
)) + index
;
305 if (!pgd_present(*pgd_k
))
307 //set_pgd(pgd, *pgd_k); /////// gcc ICE's on this line
309 pud_k
= pud_offset(pgd_k
, ear0
);
310 if (!pud_present(*pud_k
))
313 pmd_k
= pmd_offset(pud_k
, ear0
);
314 if (!pmd_present(*pmd_k
))
317 pud
= pud_offset(pgd
, ear0
);
318 pmd
= pmd_offset(pud
, ear0
);
319 set_pmd(pmd
, *pmd_k
);
321 pte_k
= pte_offset_kernel(pmd_k
, ear0
);
322 if (!pte_present(*pte_k
))
326 } /* end do_page_fault() */