2 * linux/arch/arm/mm/fault-armv.c
4 * Copyright (C) 1995 Linus Torvalds
5 * Modifications for ARM processor (c) 1995-2001 Russell King
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #include <linux/config.h>
12 #include <linux/signal.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
17 #include <linux/types.h>
18 #include <linux/ptrace.h>
19 #include <linux/mman.h>
21 #include <linux/interrupt.h>
22 #include <linux/proc_fs.h>
23 #include <linux/bitops.h>
24 #include <linux/init.h>
26 #include <asm/system.h>
27 #include <asm/uaccess.h>
28 #include <asm/pgalloc.h>
29 #include <asm/pgtable.h>
31 extern void show_pte(struct mm_struct *mm, unsigned long addr);
32 extern int do_page_fault(unsigned long addr, int error_code,
33 struct pt_regs *regs);
34 extern int do_translation_fault(unsigned long addr, int error_code,
35 struct pt_regs *regs);
36 extern void do_bad_area(struct task_struct *tsk, struct mm_struct *mm,
37 unsigned long addr, int error_code,
38 struct pt_regs *regs);
40 #ifdef CONFIG_ALIGNMENT_TRAP
41 extern int do_alignment(unsigned long addr, int error_code, struct pt_regs *regs);
43 #define do_alignment do_bad
48 * Some section permission faults need to be handled gracefully.
49 * They can happen due to a __{get,put}_user during an oops.
52 do_sect_fault(unsigned long addr, int error_code, struct pt_regs *regs)
54 struct task_struct *tsk = current;
55 do_bad_area(tsk, tsk->active_mm, addr, error_code, regs);
60 * Hook for things that need to trap external faults. Note that
61 * we don't guarantee that this will be the final version of the
64 int (*external_fault)(unsigned long addr, struct pt_regs *regs);
67 do_external_fault(unsigned long addr, int error_code, struct pt_regs *regs)
70 return external_fault(addr, regs);
75 * This abort handler always returns "fault".
78 do_bad(unsigned long addr, int error_code, struct pt_regs *regs)
83 static const struct fsr_info {
84 int (*fn)(unsigned long addr, int error_code, struct pt_regs *regs);
88 { do_bad, SIGSEGV, "vector exception" },
89 { do_alignment, SIGILL, "alignment exception" },
90 { do_bad, SIGKILL, "terminal exception" },
91 { do_alignment, SIGILL, "alignment exception" },
92 { do_external_fault, SIGBUS, "external abort on linefetch" },
93 { do_translation_fault, SIGSEGV, "section translation fault" },
94 { do_external_fault, SIGBUS, "external abort on linefetch" },
95 { do_page_fault, SIGSEGV, "page translation fault" },
96 { do_external_fault, SIGBUS, "external abort on non-linefetch" },
97 { do_bad, SIGSEGV, "section domain fault" },
98 { do_external_fault, SIGBUS, "external abort on non-linefetch" },
99 { do_bad, SIGSEGV, "page domain fault" },
100 { do_bad, SIGBUS, "external abort on translation" },
101 { do_sect_fault, SIGSEGV, "section permission fault" },
102 { do_bad, SIGBUS, "external abort on translation" },
103 { do_page_fault, SIGSEGV, "page permission fault" }
107 * Dispatch a data abort to the relevant handler.
110 do_DataAbort(unsigned long addr, int error_code, struct pt_regs *regs, int fsr)
112 const struct fsr_info *inf = fsr_info + (fsr & 15);
114 if (!inf->fn(addr, error_code, regs))
117 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
118 inf->name, fsr, addr);
119 force_sig(inf->sig, current);
120 show_pte(current->mm, addr);
121 die_if_kernel("Oops", regs, 0);
125 do_PrefetchAbort(unsigned long addr, struct pt_regs *regs)
127 do_translation_fault(addr, 0, regs);
131 * We take the easy way out of this problem - we make the
132 * PTE uncacheable. However, we leave the write buffer on.
134 static void adjust_pte(struct vm_area_struct *vma, unsigned long address)
140 pgd = pgd_offset(vma->vm_mm, address);
146 pmd = pmd_offset(pgd, address);
152 pte = pte_offset(pmd, address);
156 * If this page isn't present, or is already setup to
157 * fault (ie, is old), we can safely ignore any issues.
159 if (pte_present(entry) && pte_val(entry) & L_PTE_CACHEABLE) {
160 flush_cache_page(vma, address);
161 pte_val(entry) &= ~L_PTE_CACHEABLE;
163 flush_tlb_page(vma, address);
179 make_coherent(struct vm_area_struct *vma, unsigned long addr, struct page *page)
181 struct vm_area_struct *mpnt;
182 struct mm_struct *mm = vma->vm_mm;
183 unsigned long pgoff = (addr - vma->vm_start) >> PAGE_SHIFT;
187 * If we have any shared mappings that are in the same mm
188 * space, then we need to handle them specially to maintain
191 for (mpnt = page->mapping->i_mmap_shared; mpnt;
192 mpnt = mpnt->vm_next_share) {
196 * If this VMA is not in our MM, we can ignore it.
197 * Note that we intentionally don't mask out the VMA
198 * that we are fixing up.
200 if (mpnt->vm_mm != mm || mpnt == vma)
204 * If the page isn't in this VMA, we can also ignore it.
206 if (pgoff < mpnt->vm_pgoff)
209 off = pgoff - mpnt->vm_pgoff;
210 if (off >= (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT)
214 * Ok, it is within mpnt. Fix it up.
216 adjust_pte(mpnt, mpnt->vm_start + (off << PAGE_SHIFT));
220 adjust_pte(vma, addr);
224 * Take care of architecture specific things when placing a new PTE into
225 * a page table, or changing an existing PTE. Basically, there are two
226 * things that we need to take care of:
228 * 1. If PG_dcache_dirty is set for the page, we need to ensure
229 * that any cache entries for the kernels virtual memory
230 * range are written back to the page.
231 * 2. If we have multiple shared mappings of the same space in
232 * an object, we need to deal with the cache aliasing issues.
234 * Note that the page_table_lock will be held.
236 void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
238 unsigned long pfn = pte_pfn(pte);
243 page = pfn_to_page(pfn);
245 if (test_and_clear_bit(PG_dcache_dirty, &page->flags)) {
246 unsigned long kvirt = (unsigned long)page_address(page);
247 cpu_cache_clean_invalidate_range(kvirt, kvirt + PAGE_SIZE, 0);
250 make_coherent(vma, addr, page);