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/pgtable.h>
24 #include <asm/uaccess.h>
25 #include <asm/gdb-stub.h>
27 /*****************************************************************************/
29 * This routine handles page faults. It determines the problem, and
30 * then passes it off to one of the appropriate routines.
32 asmlinkage
void do_page_fault(int datammu
, unsigned long esr0
, unsigned long ear0
)
34 struct vm_area_struct
*vma
;
36 unsigned long _pme
, lrai
, lrad
, fixup
;
37 unsigned long flags
= 0;
45 const char *atxc
[16] = {
46 [0x0] = "mmu-miss", [0x8] = "multi-dat", [0x9] = "multi-sat",
47 [0xa] = "tlb-miss", [0xc] = "privilege", [0xd] = "write-prot",
50 printk("do_page_fault(%d,%lx [%s],%lx)\n",
51 datammu
, esr0
, atxc
[esr0
>> 20 & 0xf], ear0
);
57 * We fault-in kernel-space virtual memory on-demand. The
58 * 'reference' page table is init_mm.pgd.
60 * NOTE! We MUST NOT take any locks for this case. We may
61 * be in an interrupt or a critical region, and should
62 * only copy the information from the master page table,
65 * This verifies that the fault happens in kernel space
66 * and that the fault was a page not present (invalid) error
68 if (!user_mode(__frame
) && (esr0
& ESR0_ATXC
) == ESR0_ATXC_AMRTLB_MISS
) {
69 if (ear0
>= VMALLOC_START
&& ear0
< VMALLOC_END
)
70 goto kernel_pte_fault
;
71 if (ear0
>= PKMAP_BASE
&& ear0
< PKMAP_END
)
72 goto kernel_pte_fault
;
75 info
.si_code
= SEGV_MAPERR
;
78 * If we're in an interrupt or have no user
79 * context, we must not take the fault..
81 if (in_atomic() || !mm
)
84 if (user_mode(__frame
))
85 flags
|= FAULT_FLAG_USER
;
87 down_read(&mm
->mmap_sem
);
89 vma
= find_vma(mm
, ear0
);
92 if (vma
->vm_start
<= ear0
)
94 if (!(vma
->vm_flags
& VM_GROWSDOWN
))
97 if (user_mode(__frame
)) {
99 * accessing the stack below %esp is always a bug.
100 * The "+ 32" is there due to some instructions (like
101 * pusha) doing post-decrement on the stack and that
102 * doesn't show up until later..
104 if ((ear0
& PAGE_MASK
) + 2 * PAGE_SIZE
< __frame
->sp
) {
106 printk("[%d] ### Access below stack @%lx (sp=%lx)\n",
107 current
->pid
, ear0
, __frame
->sp
);
108 show_registers(__frame
);
109 printk("[%d] ### Code: [%08lx] %02x %02x %02x %02x %02x %02x %02x %02x\n",
112 ((u8
*)__frame
->pc
)[0],
113 ((u8
*)__frame
->pc
)[1],
114 ((u8
*)__frame
->pc
)[2],
115 ((u8
*)__frame
->pc
)[3],
116 ((u8
*)__frame
->pc
)[4],
117 ((u8
*)__frame
->pc
)[5],
118 ((u8
*)__frame
->pc
)[6],
119 ((u8
*)__frame
->pc
)[7]
126 if (expand_stack(vma
, ear0
))
130 * Ok, we have a good vm_area for this memory access, so
134 info
.si_code
= SEGV_ACCERR
;
135 switch (esr0
& ESR0_ATXC
) {
137 /* handle write to write protected page */
138 case ESR0_ATXC_WP_EXCEP
:
139 #ifdef TEST_VERIFY_AREA
140 if (!(user_mode(__frame
)))
141 printk("WP fault at %08lx\n", __frame
->pc
);
143 if (!(vma
->vm_flags
& VM_WRITE
))
145 flags
|= FAULT_FLAG_WRITE
;
148 /* handle read from protected page */
149 case ESR0_ATXC_PRIV_EXCEP
:
152 /* handle read, write or exec on absent page
153 * - can't support write without permitting read
154 * - don't support execute without permitting read and vice-versa
156 case ESR0_ATXC_AMRTLB_MISS
:
157 if (!(vma
->vm_flags
& (VM_READ
| VM_WRITE
| VM_EXEC
)))
163 * If for any reason at all we couldn't handle the fault,
164 * make sure we exit gracefully rather than endlessly redo
167 fault
= handle_mm_fault(mm
, vma
, ear0
, flags
);
168 if (unlikely(fault
& VM_FAULT_ERROR
)) {
169 if (fault
& VM_FAULT_OOM
)
171 else if (fault
& VM_FAULT_SIGBUS
)
175 if (fault
& VM_FAULT_MAJOR
)
180 up_read(&mm
->mmap_sem
);
184 * Something tried to access memory that isn't in our memory map..
185 * Fix it, but check if it's kernel or user first..
188 up_read(&mm
->mmap_sem
);
190 /* User mode accesses just cause a SIGSEGV */
191 if (user_mode(__frame
)) {
192 info
.si_signo
= SIGSEGV
;
194 /* info.si_code has been set above */
195 info
.si_addr
= (void *) ear0
;
196 force_sig_info(SIGSEGV
, &info
, current
);
201 /* are we prepared to handle this kernel fault? */
202 if ((fixup
= search_exception_table(__frame
->pc
)) != 0) {
208 * Oops. The kernel tried to access some bad page. We'll have to
209 * terminate things with extreme prejudice.
214 if (ear0
< PAGE_SIZE
)
215 printk(KERN_ALERT
"Unable to handle kernel NULL pointer dereference");
217 printk(KERN_ALERT
"Unable to handle kernel paging request");
218 printk(" at virtual addr %08lx\n", ear0
);
219 printk(" PC : %08lx\n", __frame
->pc
);
220 printk(" EXC : esr0=%08lx ear0=%08lx\n", esr0
, ear0
);
222 asm("lrai %1,%0,#1,#0,#0" : "=&r"(lrai
) : "r"(ear0
));
223 asm("lrad %1,%0,#1,#0,#0" : "=&r"(lrad
) : "r"(ear0
));
225 printk(KERN_ALERT
" LRAI: %08lx\n", lrai
);
226 printk(KERN_ALERT
" LRAD: %08lx\n", lrad
);
228 __break_hijack_kernel_event();
230 pge
= pgd_offset(current
->mm
, ear0
);
231 pue
= pud_offset(pge
, ear0
);
232 _pme
= pue
->pue
[0].ste
[0];
234 printk(KERN_ALERT
" PGE : %8p { PME %08lx }\n", pge
, _pme
);
236 if (_pme
& xAMPRx_V
) {
237 unsigned long dampr
, damlr
, val
;
239 asm volatile("movsg dampr2,%0 ! movgs %2,dampr2 ! movsg damlr2,%1"
240 : "=&r"(dampr
), "=r"(damlr
)
241 : "r" (_pme
| xAMPRx_L
|xAMPRx_SS_16Kb
|xAMPRx_S
|xAMPRx_C
|xAMPRx_V
)
244 pte
= (pte_t
*) damlr
+ __pte_index(ear0
);
247 asm volatile("movgs %0,dampr2" :: "r" (dampr
));
249 printk(KERN_ALERT
" PTE : %8p { %08lx }\n", pte
, val
);
252 die_if_kernel("Oops\n");
256 * We ran out of memory, or some other thing happened to us that made
257 * us unable to handle the page fault gracefully.
260 up_read(&mm
->mmap_sem
);
261 if (!user_mode(__frame
))
263 pagefault_out_of_memory();
267 up_read(&mm
->mmap_sem
);
270 * Send a sigbus, regardless of whether we were in kernel
273 info
.si_signo
= SIGBUS
;
275 info
.si_code
= BUS_ADRERR
;
276 info
.si_addr
= (void *) ear0
;
277 force_sig_info(SIGBUS
, &info
, current
);
279 /* Kernel mode? Handle exceptions or die */
280 if (!user_mode(__frame
))
285 * The fault was caused by a kernel PTE (such as installed by vmalloc or kmap)
290 * Synchronize this task's top level page-table
291 * with the 'reference' page table.
293 * Do _not_ use "tsk" here. We might be inside
294 * an interrupt in the middle of a task switch..
296 int index
= pgd_index(ear0
);
302 pgd
= (pgd_t
*) __get_TTBR();
303 pgd
= (pgd_t
*)__va(pgd
) + index
;
304 pgd_k
= ((pgd_t
*)(init_mm
.pgd
)) + index
;
306 if (!pgd_present(*pgd_k
))
308 //set_pgd(pgd, *pgd_k); /////// gcc ICE's on this line
310 pud_k
= pud_offset(pgd_k
, ear0
);
311 if (!pud_present(*pud_k
))
314 pmd_k
= pmd_offset(pud_k
, ear0
);
315 if (!pmd_present(*pmd_k
))
318 pud
= pud_offset(pgd
, ear0
);
319 pmd
= pmd_offset(pud
, ear0
);
320 set_pmd(pmd
, *pmd_k
);
322 pte_k
= pte_offset_kernel(pmd_k
, ear0
);
323 if (!pte_present(*pte_k
))
327 } /* end do_page_fault() */