fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / ia64 / mm / fault.c
index f713370..5cb5ab6 100644 (file)
@@ -9,46 +9,51 @@
 #include <linux/mm.h>
 #include <linux/smp_lock.h>
 #include <linux/interrupt.h>
+#include <linux/kprobes.h>
 #include <linux/vs_memory.h>
 
 #include <asm/pgtable.h>
 #include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
+#include <asm/kdebug.h>
 
 extern void die (char *, struct pt_regs *, long);
 
-/*
- * This routine is analogous to expand_stack() but instead grows the
- * register backing store (which grows towards higher addresses).
- * Since the register backing store is access sequentially, we
- * disallow growing the RBS by more than a page at a time.  Note that
- * the VM_GROWSUP flag can be set on any VM area but that's fine
- * because the total process size is still limited by RLIMIT_STACK and
- * RLIMIT_AS.
- */
-static inline long
-expand_backing_store (struct vm_area_struct *vma, unsigned long address)
+#ifdef CONFIG_KPROBES
+ATOMIC_NOTIFIER_HEAD(notify_page_fault_chain);
+
+/* Hook to register for page fault notifications */
+int register_page_fault_notifier(struct notifier_block *nb)
 {
-       unsigned long grow;
-
-       grow = PAGE_SIZE >> PAGE_SHIFT;
-       if (address - vma->vm_start > current->signal->rlim[RLIMIT_STACK].rlim_cur
-           || (((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) >
-               current->signal->rlim[RLIMIT_AS].rlim_cur))
-               return -ENOMEM;
-       if (!vx_vmpages_avail(vma->vm_mm, grow) ||
-               ((vma->vm_flags & VM_LOCKED) &&
-               !vx_vmlocked_avail(vma->vm_mm, grow)))
-               return -ENOMEM;
-       vma->vm_end += PAGE_SIZE;
-       vx_vmpages_add(vma->vm_mm, grow);
-       if (vma->vm_flags & VM_LOCKED)
-               vx_vmlocked_add(vma->vm_mm, grow);
-       __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, grow);
-       return 0;
+       return atomic_notifier_chain_register(&notify_page_fault_chain, nb);
 }
 
+int unregister_page_fault_notifier(struct notifier_block *nb)
+{
+       return atomic_notifier_chain_unregister(&notify_page_fault_chain, nb);
+}
+
+static inline int notify_page_fault(enum die_val val, const char *str,
+                       struct pt_regs *regs, long err, int trap, int sig)
+{
+       struct die_args args = {
+               .regs = regs,
+               .str = str,
+               .err = err,
+               .trapnr = trap,
+               .signr = sig
+       };
+       return atomic_notifier_call_chain(&notify_page_fault_chain, val, &args);
+}
+#else
+static inline int notify_page_fault(enum die_val val, const char *str,
+                       struct pt_regs *regs, long err, int trap, int sig)
+{
+       return NOTIFY_DONE;
+}
+#endif
+
 /*
  * Return TRUE if ADDRESS points at a page in the kernel's mapped segment
  * (inside region 5, on ia64) and that page is present.
@@ -81,7 +86,7 @@ mapped_kernel_page_is_present (unsigned long address)
        return pte_present(pte);
 }
 
-void
+void __kprobes
 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
 {
        int signal = SIGSEGV, code = SEGV_MAPERR;
@@ -90,6 +95,9 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
        struct siginfo si;
        unsigned long mask;
 
+       /* mmap_sem is performance critical.... */
+       prefetchw(&mm->mmap_sem);
+
        /*
         * If we're in an interrupt or have no user context, we must not take the fault..
         */
@@ -108,6 +116,13 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
                goto bad_area_no_up;
 #endif
 
+       /*
+        * This is to handle the kprobes on user space access instructions
+        */
+       if (notify_page_fault(DIE_PAGE_FAULT, "page fault", regs, code, TRAP_BRKPT,
+                                       SIGSEGV) == NOTIFY_STOP)
+               return;
+
        down_read(&mm->mmap_sem);
 
        vma = find_vma_prev(mm, address, &prev_vma);
@@ -132,9 +147,11 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
 #              error File is out of sync with <linux/mm.h>.  Please update.
 #      endif
 
+       if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
+               goto bad_area;
+
        mask = (  (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
-               | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT)
-               | (((isr >> IA64_ISR_R_BIT) & 1UL) << VM_READ_BIT));
+               | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
 
        if ((vma->vm_flags & mask) != mask)
                goto bad_area;
@@ -182,7 +199,13 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
                if (REGION_NUMBER(address) != REGION_NUMBER(vma->vm_start)
                    || REGION_OFFSET(address) >= RGN_MAP_LIMIT)
                        goto bad_area;
-               if (expand_backing_store(vma, address))
+               /*
+                * Since the register backing store is accessed sequentially,
+                * we disallow growing it by more than a page at a time.
+                */
+               if (address > vma->vm_end + PAGE_SIZE - sizeof(long))
+                       goto bad_area;
+               if (expand_upwards(vma, address))
                        goto bad_area;
        }
        goto good_area;
@@ -215,18 +238,18 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
        }
 
   no_context:
-       if (isr & IA64_ISR_SP) {
+       if ((isr & IA64_ISR_SP)
+           || ((isr & IA64_ISR_NA) && (isr & IA64_ISR_CODE_MASK) == IA64_ISR_CODE_LFETCH))
+       {
                /*
-                * This fault was due to a speculative load set the "ed" bit in the psr to
-                * ensure forward progress (target register will get a NaT).
+                * This fault was due to a speculative load or lfetch.fault, set the "ed"
+                * bit in the psr to ensure forward progress.  (Target register will get a
+                * NaT for ld.s, lfetch will be canceled.)
                 */
                ia64_psr(regs)->ed = 1;
                return;
        }
 
-       if (ia64_done_with_exception(regs))
-               return;
-
        /*
         * Since we have no vma's for region 5, we might get here even if the address is
         * valid, due to the VHPT walker inserting a non present translation that becomes
@@ -237,6 +260,9 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
        if (REGION_NUMBER(address) == 5 && mapped_kernel_page_is_present(address))
                return;
 
+       if (ia64_done_with_exception(regs))
+               return;
+
        /*
         * Oops. The kernel tried to access some bad page. We'll have to terminate things
         * with extreme prejudice.
@@ -255,7 +281,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
 
   out_of_memory:
        up_read(&mm->mmap_sem);
-       if (current->pid == 1) {
+       if (is_init(current)) {
                yield();
                down_read(&mm->mmap_sem);
                goto survive;