OSDN Git Service

Merge 4.4.143 into android-4.4
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / arch / mips / kernel / traps.c
index 1b90121..da69974 100644 (file)
@@ -56,6 +56,7 @@
 #include <asm/pgtable.h>
 #include <asm/ptrace.h>
 #include <asm/sections.h>
+#include <asm/siginfo.h>
 #include <asm/tlbdebug.h>
 #include <asm/traps.h>
 #include <asm/uaccess.h>
@@ -706,6 +707,32 @@ asmlinkage void do_ov(struct pt_regs *regs)
        exception_exit(prev_state);
 }
 
+/*
+ * Send SIGFPE according to FCSR Cause bits, which must have already
+ * been masked against Enable bits.  This is impotant as Inexact can
+ * happen together with Overflow or Underflow, and `ptrace' can set
+ * any bits.
+ */
+void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
+                    struct task_struct *tsk)
+{
+       struct siginfo si = { .si_addr = fault_addr, .si_signo = SIGFPE };
+
+       if (fcr31 & FPU_CSR_INV_X)
+               si.si_code = FPE_FLTINV;
+       else if (fcr31 & FPU_CSR_DIV_X)
+               si.si_code = FPE_FLTDIV;
+       else if (fcr31 & FPU_CSR_OVF_X)
+               si.si_code = FPE_FLTOVF;
+       else if (fcr31 & FPU_CSR_UDF_X)
+               si.si_code = FPE_FLTUND;
+       else if (fcr31 & FPU_CSR_INE_X)
+               si.si_code = FPE_FLTRES;
+       else
+               si.si_code = __SI_FAULT;
+       force_sig_info(SIGFPE, &si, tsk);
+}
+
 int process_fpemu_return(int sig, void __user *fault_addr, unsigned long fcr31)
 {
        struct siginfo si = { 0 };
@@ -715,27 +742,7 @@ int process_fpemu_return(int sig, void __user *fault_addr, unsigned long fcr31)
                return 0;
 
        case SIGFPE:
-               si.si_addr = fault_addr;
-               si.si_signo = sig;
-               /*
-                * Inexact can happen together with Overflow or Underflow.
-                * Respect the mask to deliver the correct exception.
-                */
-               fcr31 &= (fcr31 & FPU_CSR_ALL_E) <<
-                        (ffs(FPU_CSR_ALL_X) - ffs(FPU_CSR_ALL_E));
-               if (fcr31 & FPU_CSR_INV_X)
-                       si.si_code = FPE_FLTINV;
-               else if (fcr31 & FPU_CSR_DIV_X)
-                       si.si_code = FPE_FLTDIV;
-               else if (fcr31 & FPU_CSR_OVF_X)
-                       si.si_code = FPE_FLTOVF;
-               else if (fcr31 & FPU_CSR_UDF_X)
-                       si.si_code = FPE_FLTUND;
-               else if (fcr31 & FPU_CSR_INE_X)
-                       si.si_code = FPE_FLTRES;
-               else
-                       si.si_code = __SI_FAULT;
-               force_sig_info(sig, &si, current);
+               force_fcr31_sig(fcr31, fault_addr, current);
                return 1;
 
        case SIGBUS:
@@ -798,13 +805,13 @@ static int simulate_fp(struct pt_regs *regs, unsigned int opcode,
        /* Run the emulator */
        sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
                                       &fault_addr);
-       fcr31 = current->thread.fpu.fcr31;
 
        /*
-        * We can't allow the emulated instruction to leave any of
-        * the cause bits set in $fcr31.
+        * We can't allow the emulated instruction to leave any
+        * enabled Cause bits set in $fcr31.
         */
-       current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
+       fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
+       current->thread.fpu.fcr31 &= ~fcr31;
 
        /* Restore the hardware register state */
        own_fpu(1);
@@ -830,7 +837,7 @@ asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
                goto out;
 
        /* Clear FCSR.Cause before enabling interrupts */
-       write_32bit_cp1_register(CP1_STATUS, fcr31 & ~FPU_CSR_ALL_X);
+       write_32bit_cp1_register(CP1_STATUS, fcr31 & ~mask_fcr31_x(fcr31));
        local_irq_enable();
 
        die_if_kernel("FP exception in kernel code", regs);
@@ -852,13 +859,13 @@ asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
                /* Run the emulator */
                sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
                                               &fault_addr);
-               fcr31 = current->thread.fpu.fcr31;
 
                /*
-                * We can't allow the emulated instruction to leave any of
-                * the cause bits set in $fcr31.
+                * We can't allow the emulated instruction to leave any
+                * enabled Cause bits set in $fcr31.
                 */
-               current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
+               fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
+               current->thread.fpu.fcr31 &= ~fcr31;
 
                /* Restore the hardware register state */
                own_fpu(1);     /* Using the FPU again.  */
@@ -874,7 +881,7 @@ out:
        exception_exit(prev_state);
 }
 
-void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
+void do_trap_or_bp(struct pt_regs *regs, unsigned int code, int si_code,
        const char *str)
 {
        siginfo_t info = { 0 };
@@ -931,7 +938,13 @@ void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
        default:
                scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
                die_if_kernel(b, regs);
-               force_sig(SIGTRAP, current);
+               if (si_code) {
+                       info.si_signo = SIGTRAP;
+                       info.si_code = si_code;
+                       force_sig_info(SIGTRAP, &info, current);
+               } else {
+                       force_sig(SIGTRAP, current);
+               }
        }
 }
 
@@ -1015,7 +1028,7 @@ asmlinkage void do_bp(struct pt_regs *regs)
                break;
        }
 
-       do_trap_or_bp(regs, bcode, "Break");
+       do_trap_or_bp(regs, bcode, TRAP_BRKPT, "Break");
 
 out:
        set_fs(seg);
@@ -1057,7 +1070,7 @@ asmlinkage void do_tr(struct pt_regs *regs)
                        tcode = (opcode >> 6) & ((1 << 10) - 1);
        }
 
-       do_trap_or_bp(regs, tcode, "Trap");
+       do_trap_or_bp(regs, tcode, 0, "Trap");
 
 out:
        set_fs(seg);
@@ -1431,13 +1444,13 @@ asmlinkage void do_cpu(struct pt_regs *regs)
 
                sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 0,
                                               &fault_addr);
-               fcr31 = current->thread.fpu.fcr31;
 
                /*
                 * We can't allow the emulated instruction to leave
-                * any of the cause bits set in $fcr31.
+                * any enabled Cause bits set in $fcr31.
                 */
-               current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
+               fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
+               current->thread.fpu.fcr31 &= ~fcr31;
 
                /* Send a signal if required.  */
                if (!process_fpemu_return(sig, fault_addr, fcr31) && !err)
@@ -1508,6 +1521,7 @@ asmlinkage void do_mdmx(struct pt_regs *regs)
  */
 asmlinkage void do_watch(struct pt_regs *regs)
 {
+       siginfo_t info = { .si_signo = SIGTRAP, .si_code = TRAP_HWBKPT };
        enum ctx_state prev_state;
        u32 cause;
 
@@ -1528,7 +1542,7 @@ asmlinkage void do_watch(struct pt_regs *regs)
        if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
                mips_read_watch_registers();
                local_irq_enable();
-               force_sig(SIGTRAP, current);
+               force_sig_info(SIGTRAP, &info, current);
        } else {
                mips_clear_watch_registers();
                local_irq_enable();
@@ -2127,6 +2141,13 @@ void per_cpu_trap_init(bool is_boot_cpu)
         *  o read IntCtl.IPFDC to determine the fast debug channel interrupt
         */
        if (cpu_has_mips_r2_r6) {
+               /*
+                * We shouldn't trust a secondary core has a sane EBASE register
+                * so use the one calculated by the boot CPU.
+                */
+               if (!is_boot_cpu)
+                       write_c0_ebase(ebase);
+
                cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
                cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
                cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
@@ -2230,7 +2251,7 @@ void __init trap_init(void)
 
        /*
         * Copy the generic exception handlers to their final destination.
-        * This will be overriden later as suitable for a particular
+        * This will be overridden later as suitable for a particular
         * configuration.
         */
        set_handler(0x180, &except_vec3_generic, 0x80);