]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/sh/mm/fault_32.c
sh: Look up the trap vector for the page fault notifier.
[linux-2.6-omap-h63xx.git] / arch / sh / mm / fault_32.c
index 33b43d20e9f6f06a5a967dc11da3b4d8e3f26f59..ef01f45daa8a89fcf85aaccbf6312d545d12a361 100644 (file)
@@ -2,7 +2,7 @@
  * Page fault handler for SH with an MMU.
  *
  *  Copyright (C) 1999  Niibe Yutaka
- *  Copyright (C) 2003 - 2007  Paul Mundt
+ *  Copyright (C) 2003 - 2008  Paul Mundt
  *
  *  Based on linux/arch/i386/mm/fault.c:
  *   Copyright (C) 1995  Linus Torvalds
 #include <linux/mm.h>
 #include <linux/hardirq.h>
 #include <linux/kprobes.h>
+#include <asm/io_trapped.h>
 #include <asm/system.h>
 #include <asm/mmu_context.h>
 #include <asm/tlbflush.h>
 #include <asm/kgdb.h>
 
+static inline int notify_page_fault(struct pt_regs *regs, int trap)
+{
+       int ret = 0;
+
+#ifdef CONFIG_KPROBES
+       if (!user_mode(regs)) {
+               preempt_disable();
+               if (kprobe_running() && kprobe_fault_handler(regs, trap))
+                       ret = 1;
+               preempt_enable();
+       }
+#endif
+
+       return ret;
+}
+
 /*
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
@@ -36,8 +53,8 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
        int fault;
        siginfo_t info;
 
-       trace_hardirqs_on();
-       local_irq_enable();
+       if (notify_page_fault(regs, lookup_exception_vector()))
+               return;
 
 #ifdef CONFIG_SH_KGDB
        if (kgdb_nofault && kgdb_bus_err_hook)
@@ -45,7 +62,6 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
 #endif
 
        tsk = current;
-       mm = tsk->mm;
        si_code = SEGV_MAPERR;
 
        if (unlikely(address >= TASK_SIZE)) {
@@ -64,7 +80,6 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
                pgd = get_TTB() + offset;
                pgd_k = swapper_pg_dir + offset;
 
-               /* This will never happen with the folded page table. */
                if (!pgd_present(*pgd)) {
                        if (!pgd_present(*pgd_k))
                                goto bad_area_nosemaphore;
@@ -74,9 +89,13 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
 
                pud = pud_offset(pgd, address);
                pud_k = pud_offset(pgd_k, address);
-               if (pud_present(*pud) || !pud_present(*pud_k))
-                       goto bad_area_nosemaphore;
-               set_pud(pud, *pud_k);
+
+               if (!pud_present(*pud)) {
+                       if (!pud_present(*pud_k))
+                               goto bad_area_nosemaphore;
+                       set_pud(pud, *pud_k);
+                       return;
+               }
 
                pmd = pmd_offset(pud, address);
                pmd_k = pmd_offset(pud_k, address);
@@ -87,6 +106,14 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
                return;
        }
 
+       /* Only enable interrupts if they were on before the fault */
+       if ((regs->sr & SR_IMASK) != SR_IMASK) {
+               trace_hardirqs_on();
+               local_irq_enable();
+       }
+
+       mm = tsk->mm;
+
        /*
         * If we're in an interrupt or have no user
         * context, we must not take the fault..
@@ -163,6 +190,8 @@ no_context:
        if (fixup_exception(regs))
                return;
 
+       if (handle_trapped_io(regs, address))
+               return;
 /*
  * Oops. The kernel tried to access some bad page. We'll have to
  * terminate things with extreme prejudice.
@@ -259,6 +288,9 @@ asmlinkage int __kprobes __do_page_fault(struct pt_regs *regs,
        pte_t *pte;
        pte_t entry;
 
+       if (notify_page_fault(regs, lookup_exception_vector()))
+               return 0;
+
 #ifdef CONFIG_SH_KGDB
        if (kgdb_nofault && kgdb_bus_err_hook)
                kgdb_bus_err_hook();
@@ -296,6 +328,14 @@ asmlinkage int __kprobes __do_page_fault(struct pt_regs *regs,
                entry = pte_mkdirty(entry);
        entry = pte_mkyoung(entry);
 
+#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SMP)
+       /*
+        * ITLB is not affected by "ldtlb" instruction.
+        * So, we need to flush the entry by ourselves.
+        */
+       local_flush_tlb_one(get_asid(), address & PAGE_MASK);
+#endif
+
        set_pte(pte, entry);
        update_mmu_cache(NULL, address, entry);