Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / arch / powerpc / mm / fault.c
index 99b2f2775658b61059e74f45de3d451eb0d739c4..08d659a9fcdbf16026e7dfc2af9306416028c671 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/perf_event.h>
 #include <linux/ratelimit.h>
 #include <linux/context_tracking.h>
+#include <linux/hugetlb.h>
 
 #include <asm/firmware.h>
 #include <asm/page.h>
@@ -113,22 +114,37 @@ static int store_updates_sp(struct pt_regs *regs)
 #define MM_FAULT_CONTINUE      -1
 #define MM_FAULT_ERR(sig)      (sig)
 
-static int do_sigbus(struct pt_regs *regs, unsigned long address)
+static int do_sigbus(struct pt_regs *regs, unsigned long address,
+                    unsigned int fault)
 {
        siginfo_t info;
+       unsigned int lsb = 0;
 
        up_read(&current->mm->mmap_sem);
 
-       if (user_mode(regs)) {
-               current->thread.trap_nr = BUS_ADRERR;
-               info.si_signo = SIGBUS;
-               info.si_errno = 0;
-               info.si_code = BUS_ADRERR;
-               info.si_addr = (void __user *)address;
-               force_sig_info(SIGBUS, &info, current);
-               return MM_FAULT_RETURN;
+       if (!user_mode(regs))
+               return MM_FAULT_ERR(SIGBUS);
+
+       current->thread.trap_nr = BUS_ADRERR;
+       info.si_signo = SIGBUS;
+       info.si_errno = 0;
+       info.si_code = BUS_ADRERR;
+       info.si_addr = (void __user *)address;
+#ifdef CONFIG_MEMORY_FAILURE
+       if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
+               pr_err("MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
+                       current->comm, current->pid, address);
+               info.si_code = BUS_MCEERR_AR;
        }
-       return MM_FAULT_ERR(SIGBUS);
+
+       if (fault & VM_FAULT_HWPOISON_LARGE)
+               lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
+       if (fault & VM_FAULT_HWPOISON)
+               lsb = PAGE_SHIFT;
+#endif
+       info.si_addr_lsb = lsb;
+       force_sig_info(SIGBUS, &info, current);
+       return MM_FAULT_RETURN;
 }
 
 static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)
@@ -169,11 +185,8 @@ static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)
                return MM_FAULT_RETURN;
        }
 
-       /* Bus error. x86 handles HWPOISON here, we'll add this if/when
-        * we support the feature in HW
-        */
-       if (fault & VM_FAULT_SIGBUS)
-               return do_sigbus(regs, addr);
+       if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE))
+               return do_sigbus(regs, addr, fault);
 
        /* We don't understand the fault code, this is fatal */
        BUG();