Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / arch / x86 / kernel / signal.c
index f9804080ccb36c3b95345a0c53cfe2cd392cfcd1..1ea14fd53933bae96dc5f8e3fec99575a3c3c454 100644 (file)
@@ -616,7 +616,8 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
 static void
 handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 {
-       bool failed;
+       bool stepping, failed;
+
        /* Are we from a system call? */
        if (syscall_get_nr(current, regs) >= 0) {
                /* If so, check system call restarting.. */
@@ -640,12 +641,13 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
        }
 
        /*
-        * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
-        * flag so that register information in the sigcontext is correct.
+        * If TF is set due to a debugger (TIF_FORCED_TF), clear TF now
+        * so that register information in the sigcontext is correct and
+        * then notify the tracer before entering the signal handler.
         */
-       if (unlikely(regs->flags & X86_EFLAGS_TF) &&
-           likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
-               regs->flags &= ~X86_EFLAGS_TF;
+       stepping = test_thread_flag(TIF_SINGLESTEP);
+       if (stepping)
+               user_disable_single_step(current);
 
        failed = (setup_rt_frame(ksig, regs) < 0);
        if (!failed) {
@@ -656,10 +658,8 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
                 * it might disable possible debug exception from the
                 * signal handler.
                 *
-                * Clear TF when entering the signal handler, but
-                * notify any tracer that was single-stepping it.
-                * The tracer may want to single-step inside the
-                * handler too.
+                * Clear TF for the case when it wasn't set by debugger to
+                * avoid the recursive send_sigtrap() in SIGTRAP handler.
                 */
                regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
                /*
@@ -668,7 +668,7 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
                if (used_math())
                        fpu_reset_state(current);
        }
-       signal_setup_done(failed, ksig, test_thread_flag(TIF_SINGLESTEP));
+       signal_setup_done(failed, ksig, stepping);
 }
 
 #ifdef CONFIG_X86_32