]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling
authorJonathan (Zhixiong) Zhang <zjzhang@codeaurora.org>
Thu, 8 Jun 2017 17:25:27 +0000 (18:25 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 9 Aug 2017 14:23:29 +0000 (16:23 +0200)
Add VM_FAULT_HWPOISON[_LARGE] handling to the arm64 page fault
handler. Handling of VM_FAULT_HWPOISON[_LARGE] is very similar
to VM_FAULT_OOM, the only difference is that a different si_code
(BUS_MCEERR_AR) is passed to user space and si_addr_lsb field is
initialized.

BugLink: http://launchpad.net/bugs/1696852
Signed-off-by: Jonathan (Zhixiong) Zhang <zjzhang@codeaurora.org>
Signed-off-by: Tyler Baicar <tbaicar@codeaurora.org>
(fix new __do_user_fault call-site)
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
Acked-by: Steve Capper <steve.capper@arm.com>
Tested-by: Manoj Iyer <manoj.iyer@canonical.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit e7c600f149b89e06073ab50f4f12e79828d3d2f0)
Signed-off-by: Manoj Iyer <manoj.iyer@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
arch/arm64/mm/fault.c

index 14213c5f5c491f76e3b1637a5505bf712a7a6754..9910fe2f82e43b0ad0717f7ce9f10ba85c73d6e7 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/highmem.h>
 #include <linux/perf_event.h>
 #include <linux/preempt.h>
+#include <linux/hugetlb.h>
 
 #include <asm/bug.h>
 #include <asm/cpufeature.h>
@@ -208,10 +209,11 @@ static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr,
  */
 static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
                            unsigned int esr, unsigned int sig, int code,
-                           struct pt_regs *regs)
+                           struct pt_regs *regs, int fault)
 {
        struct siginfo si;
        const struct fault_info *inf;
+       unsigned int lsb = 0;
 
        if (unhandled_signal(tsk, sig) && show_unhandled_signals_ratelimited()) {
                inf = esr_to_fault_info(esr);
@@ -228,6 +230,17 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
        si.si_errno = 0;
        si.si_code = code;
        si.si_addr = (void __user *)addr;
+       /*
+        * Either small page or large page may be poisoned.
+        * In other words, VM_FAULT_HWPOISON_LARGE and
+        * VM_FAULT_HWPOISON are mutually exclusive.
+        */
+       if (fault & VM_FAULT_HWPOISON_LARGE)
+               lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
+       else if (fault & VM_FAULT_HWPOISON)
+               lsb = PAGE_SHIFT;
+       si.si_addr_lsb = lsb;
+
        force_sig_info(sig, &si, tsk);
 }
 
@@ -243,7 +256,7 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re
         */
        if (user_mode(regs)) {
                inf = esr_to_fault_info(esr);
-               __do_user_fault(tsk, addr, esr, inf->sig, inf->code, regs);
+               __do_user_fault(tsk, addr, esr, inf->sig, inf->code, regs, 0);
        } else
                __do_kernel_fault(mm, addr, esr, regs);
 }
@@ -449,6 +462,9 @@ retry:
                 */
                sig = SIGBUS;
                code = BUS_ADRERR;
+       } else if (fault & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE)) {
+               sig = SIGBUS;
+               code = BUS_MCEERR_AR;
        } else {
                /*
                 * Something tried to access memory that isn't in our memory
@@ -459,7 +475,7 @@ retry:
                        SEGV_ACCERR : SEGV_MAPERR;
        }
 
-       __do_user_fault(tsk, addr, esr, sig, code, regs);
+       __do_user_fault(tsk, addr, esr, sig, code, regs, fault);
        return 0;
 
 no_context: