sched: Fix __schedule_bug() output when called from an interrupt
PATCH 1/1 sched: Fix __schedule_bug() output when called from an interrupt
If schedule is called from an interrupt handler __schedule_bug() will call show_regs() with the registers saved during the interrupt handling done in do_IRQ(). This means we'll see the registers and the backtrace for the process that was interrupted and not the full backtrace explaining who called schedule().
This is due to 838225b (sched: use show_regs() to improve __schedule_bug() output, 2007-10-24) which improperly assumed that get_irq_regs() would return the registers for the current stack because it is being called from within an interrupt handler. Simply remove the show_reg() code so that we dump a backtrace for the interrupt handler that called schedule().
---
I ran across this when I was presented with a scheduling while atomic log with a stacktrace pointing at spin_unlock_irqrestore(). It made no sense and I had to guess what interrupt handler could be called and poke around for someone calling schedule() in an interrupt handler. A simple test of putting an msleep() in an interrupt handler works better with this patch because you can actually see the msleep() call in the backtrace.
kernel/sched/core.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
kernel/sched/core.c +1 -7
@@ -3101,8 +3101,6 @@ EXPORT_SYMBOL(sub_preempt_count);*/ static noinline void __schedule_bug(struct task_struct *prev) { -struct pt_regs *regs =get_irq_regs (); -if (oops_in_progress)return ;
@@ -3113,11 +3111,7 @@ static noinline void __schedule_bug(struct task_struct *prev)print_modules ();if (irqs_disabled ())print_irqtrace_events (prev); - -if (regs) -show_regs (regs); -else -dump_stack (); +dump_stack (); }/*
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Commit-ID: 6135fc1eb4b1c9ae5f535507ed59591bab51e630 Gitweb: http://git.kernel.org/tip/6135fc1eb4b1c9ae5f535507ed59591bab51e630 Author: Stephen Boyd <[email protected]> AuthorDate: Wed, 28 Mar 2012 17:10:47 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Mar 2012 08:34:45 +0200
sched: Fix __schedule_bug() output when called from an interrupt
If schedule is called from an interrupt handler __schedule_bug() will call show_regs() with the registers saved during the interrupt handling done in do_IRQ(). This means we'll see the registers and the backtrace for the process that was interrupted and not the full backtrace explaining who called schedule().
This is due to 838225b ("sched: use show_regs() to improve __schedule_bug() output", 2007-10-24) which improperly assumed that get_irq_regs() would return the registers for the current stack because it is being called from within an interrupt handler. Simply remove the show_reg() code so that we dump a backtrace for the interrupt handler that called schedule().
[ I ran across this when I was presented with a scheduling while
atomic log with a stacktrace pointing at spin_unlock_irqrestore(). It made no sense and I had to guess what interrupt handler could be called and poke around for someone calling schedule() in an interrupt handler. A simple test of putting an msleep() in an interrupt handler works better with this patch because you can actually see the msleep() call in the backtrace. ]
--- kernel/sched/core.c | 8 +------- 1 files changed, 1 insertions(+), 7 deletions(-)
kernel/sched/core.c +1 -7
@@ -3099,8 +3099,6 @@ EXPORT_SYMBOL(sub_preempt_count);*/ static noinline void __schedule_bug(struct task_struct *prev) { -struct pt_regs *regs =get_irq_regs (); -if (oops_in_progress)return ;
@@ -3111,11 +3109,7 @@ static noinline void __schedule_bug(struct task_struct *prev)print_modules ();if (irqs_disabled ())print_irqtrace_events (prev); - -if (regs) -show_regs (regs); -else -dump_stack (); +dump_stack (); }/*
Chris Metcalf
Acked-byQuoted 30 lines · tip-bot for Stephen Boyd
Commit-ID: 6135fc1eb4b1c9ae5f535507ed59591bab51e630 Gitweb: http://git.kernel.org/tip/6135fc1eb4b1c9ae5f535507ed59591bab51e630 Author: Stephen Boyd <[email protected]> AuthorDate: Wed, 28 Mar 2012 17:10:47 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Mar 2012 08:34:45 +0200sched: Fix
__schedule_bug()output when called from an interruptIf schedule is called from an interrupt handler
__schedule_bug()will callshow_regs()with the registers saved during the interrupt handling done indo_IRQ(). This means we'll see the registers and the backtrace for the process that was interrupted and not the full backtrace explaining who calledschedule().This is due to 838225b ("sched: use
show_regs()to improve__schedule_bug()output", 2007-10-24) which improperly assumed thatget_irq_regs()would return the registers for the current stack because it is being called from within an interrupt handler. Simply remove theshow_reg()code so that we dump a backtrace for the interrupt handler that calledschedule().[ I ran across this when I was presented with a scheduling while
atomic log with a stacktrace pointing atspin_unlock_irqrestore(). It made no sense and I had to guess what interrupt handler could be called and poke around for someone callingschedule()in an interrupt handler. A simple test of putting anmsleep()in an interrupt handler works better with this patch because you can actually see themsleep()call in the backtrace. ]
Quoted 6 lines
Also-reported-by Chris Metcalf <[email protected]>Signed-off-by Stephen Boyd <[email protected]>Cc Satyam Sharma <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
We have been using this same exact patch internally for a while now, and by a curious fluke of timing, I sent email to Ingo and to Satyam Sharma pointing out that we really should re-look at the original change just yesterday :-)
Signature · 2 lines
Chris Metcalf, Tilera Corp. http://www.tilera.com