Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[pandora-kernel.git] / arch / um / kernel / trap.c
index 26f15c4..3850d53 100644 (file)
@@ -18,8 +18,9 @@
 #include "asm/current.h"
 #include "asm/irq.h"
 #include "sysdep/sigcontext.h"
-#include "user_util.h"
 #include "kern_util.h"
+#include "as-layout.h"
+#include "arch.h"
 #include "kern.h"
 #include "chan_kern.h"
 #include "mconsole_kern.h"
@@ -71,27 +72,28 @@ good_area:
                goto out;
 
        /* Don't require VM_READ|VM_EXEC for write faults! */
-        if(!is_write && !(vma->vm_flags & (VM_READ | VM_EXEC)))
-                goto out;
+       if(!is_write && !(vma->vm_flags & (VM_READ | VM_EXEC)))
+               goto out;
 
        do {
+               int fault;
 survive:
-               switch (handle_mm_fault(mm, vma, address, is_write)){
-               case VM_FAULT_MINOR:
-                       current->min_flt++;
-                       break;
-               case VM_FAULT_MAJOR:
-                       current->maj_flt++;
-                       break;
-               case VM_FAULT_SIGBUS:
-                       err = -EACCES;
-                       goto out;
-               case VM_FAULT_OOM:
-                       err = -ENOMEM;
-                       goto out_of_memory;
-               default:
+               fault = handle_mm_fault(mm, vma, address, is_write);
+               if (unlikely(fault & VM_FAULT_ERROR)) {
+                       if (fault & VM_FAULT_OOM) {
+                               err = -ENOMEM;
+                               goto out_of_memory;
+                       } else if (fault & VM_FAULT_SIGBUS) {
+                               err = -EACCES;
+                               goto out;
+                       }
                        BUG();
                }
+               if (fault & VM_FAULT_MAJOR)
+                       current->maj_flt++;
+               else
+                       current->min_flt++;
+
                pgd = pgd_offset(mm, address);
                pud = pud_offset(pgd, address);
                pmd = pmd_offset(pud, address);
@@ -156,20 +158,23 @@ static void segv_handler(int sig, union uml_pt_regs *regs)
  * the info in the regs. A pointer to the info then would
  * give us bad data!
  */
-unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, void *sc)
+unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
+                  union uml_pt_regs *regs)
 {
        struct siginfo si;
        void *catcher;
        int err;
-        int is_write = FAULT_WRITE(fi);
-        unsigned long address = FAULT_ADDRESS(fi);
+       int is_write = FAULT_WRITE(fi);
+       unsigned long address = FAULT_ADDRESS(fi);
 
-        if(!is_user && (address >= start_vm) && (address < end_vm)){
-                flush_tlb_kernel_vm();
-                return(0);
-        }
-       else if(current->mm == NULL)
-               panic("Segfault with no mm");
+       if(!is_user && (address >= start_vm) && (address < end_vm)){
+               flush_tlb_kernel_vm();
+               return 0;
+       }
+       else if(current->mm == NULL) {
+               show_regs(container_of(regs, struct pt_regs, regs));
+               panic("Segfault with no mm");
+       }
 
        if (SEGV_IS_FIXABLE(&fi) || SEGV_MAYBE_FIXABLE(&fi))
                err = handle_page_fault(address, ip, is_write, is_user, &si.si_code);
@@ -182,26 +187,28 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, void *sc)
 
        catcher = current->thread.fault_catcher;
        if(!err)
-               return(0);
+               return 0;
        else if(catcher != NULL){
                current->thread.fault_addr = (void *) address;
                do_longjmp(catcher, 1);
        }
        else if(current->thread.fault_addr != NULL)
                panic("fault_addr set but no fault catcher");
-        else if(!is_user && arch_fixup(ip, sc))
-               return(0);
+       else if(!is_user && arch_fixup(ip, regs))
+               return 0;
 
-       if(!is_user)
+       if(!is_user) {
+               show_regs(container_of(regs, struct pt_regs, regs));
                panic("Kernel mode fault at addr 0x%lx, ip 0x%lx",
                      address, ip);
+       }
 
        if (err == -EACCES) {
                si.si_signo = SIGBUS;
                si.si_errno = 0;
                si.si_code = BUS_ADRERR;
                si.si_addr = (void __user *)address;
-                current->thread.arch.faultinfo = fi;
+               current->thread.arch.faultinfo = fi;
                force_sig_info(SIGBUS, &si, current);
        } else if (err == -ENOMEM) {
                printk("VM: killing process %s\n", current->comm);
@@ -210,10 +217,10 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, void *sc)
                BUG_ON(err != -EFAULT);
                si.si_signo = SIGSEGV;
                si.si_addr = (void __user *) address;
-                current->thread.arch.faultinfo = fi;
+               current->thread.arch.faultinfo = fi;
                force_sig_info(SIGSEGV, &si, current);
        }
-       return(0);
+       return 0;
 }
 
 void relay_signal(int sig, union uml_pt_regs *regs)
@@ -223,12 +230,12 @@ void relay_signal(int sig, union uml_pt_regs *regs)
 
        if(!UPT_IS_USER(regs)){
                if(sig == SIGBUS)
-                       printk("Bus error - the /dev/shm or /tmp mount likely "
-                              "just ran out of space\n");
+                       printk("Bus error - the host /dev/shm or /tmp mount "
+                              "likely just ran out of space\n");
                panic("Kernel mode signal %d", sig);
        }
 
-        current->thread.arch.faultinfo = *UPT_FAULTINFO(regs);
+       current->thread.arch.faultinfo = *UPT_FAULTINFO(regs);
        force_sig(sig, current);
 }