Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64...
[linux-2.6-microblaze.git] / arch / arm64 / mm / fault.c
index 1b35b8b..37b95df 100644 (file)
@@ -174,12 +174,33 @@ static bool is_el1_instruction_abort(unsigned int esr)
        return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_CUR;
 }
 
+static inline bool is_permission_fault(unsigned int esr, struct pt_regs *regs,
+                                      unsigned long addr)
+{
+       unsigned int ec       = ESR_ELx_EC(esr);
+       unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE;
+
+       if (ec != ESR_ELx_EC_DABT_CUR && ec != ESR_ELx_EC_IABT_CUR)
+               return false;
+
+       if (fsc_type == ESR_ELx_FSC_PERM)
+               return true;
+
+       if (addr < USER_DS && system_uses_ttbr0_pan())
+               return fsc_type == ESR_ELx_FSC_FAULT &&
+                       (regs->pstate & PSR_PAN_BIT);
+
+       return false;
+}
+
 /*
  * The kernel tried to access some page that wasn't present.
  */
 static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr,
                              unsigned int esr, struct pt_regs *regs)
 {
+       const char *msg;
+
        /*
         * Are we prepared to handle this kernel fault?
         * We are almost certainly not prepared to handle instruction faults.
@@ -191,9 +212,20 @@ static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr,
         * No handler, we'll have to terminate things with extreme prejudice.
         */
        bust_spinlocks(1);
-       pr_alert("Unable to handle kernel %s at virtual address %08lx\n",
-                (addr < PAGE_SIZE) ? "NULL pointer dereference" :
-                "paging request", addr);
+
+       if (is_permission_fault(esr, regs, addr)) {
+               if (esr & ESR_ELx_WNR)
+                       msg = "write to read-only memory";
+               else
+                       msg = "read from unreadable memory";
+       } else if (addr < PAGE_SIZE) {
+               msg = "NULL pointer dereference";
+       } else {
+               msg = "paging request";
+       }
+
+       pr_alert("Unable to handle kernel %s at virtual address %08lx\n", msg,
+                addr);
 
        show_pte(mm, addr);
        die("Oops", regs, esr);
@@ -287,21 +319,6 @@ out:
        return fault;
 }
 
-static inline bool is_permission_fault(unsigned int esr, struct pt_regs *regs)
-{
-       unsigned int ec       = ESR_ELx_EC(esr);
-       unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE;
-
-       if (ec != ESR_ELx_EC_DABT_CUR && ec != ESR_ELx_EC_IABT_CUR)
-               return false;
-
-       if (system_uses_ttbr0_pan())
-               return fsc_type == ESR_ELx_FSC_FAULT &&
-                       (regs->pstate & PSR_PAN_BIT);
-       else
-               return fsc_type == ESR_ELx_FSC_PERM;
-}
-
 static bool is_el0_instruction_abort(unsigned int esr)
 {
        return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_LOW;
@@ -339,7 +356,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
                mm_flags |= FAULT_FLAG_WRITE;
        }
 
-       if (addr < USER_DS && is_permission_fault(esr, regs)) {
+       if (addr < USER_DS && is_permission_fault(esr, regs, addr)) {
                /* regs->orig_addr_limit may be 0 if we entered from EL0 */
                if (regs->orig_addr_limit == KERNEL_DS)
                        die("Accessing user space memory with fs=KERNEL_DS", regs, esr);