* Re: [RESEND PATCH 4.0-rc5 v19 6/6] ARM: Add support for on-demand backtrace of other CPUs [not found] <089101d071d6$4ebe2a90$ec3a7fb0$@alibaba-inc.com> @ 2015-04-08 8:35 ` Hillf Danton 2015-04-08 10:48 ` Daniel Thompson 0 siblings, 1 reply; 3+ messages in thread From: Hillf Danton @ 2015-04-08 8:35 UTC (permalink / raw) To: Daniel Thompson; +Cc: linux-kernel, Russell King, Steven Rostedt > > +void ipi_cpu_backtrace(struct pt_regs *regs) > +{ > + int cpu = smp_processor_id(); > + > + if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) { > + printk_nmi_backtrace_this_cpu_begin(); > + pr_warn("FIQ backtrace for cpu %d\n", cpu); > + if (regs != NULL) > + show_regs(regs); > + else > + dump_stack(); Help more if we could print both register and stack info. > + printk_nmi_backtrace_this_cpu_end(); > + > + cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask)); > + } > +} ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RESEND PATCH 4.0-rc5 v19 6/6] ARM: Add support for on-demand backtrace of other CPUs 2015-04-08 8:35 ` [RESEND PATCH 4.0-rc5 v19 6/6] ARM: Add support for on-demand backtrace of other CPUs Hillf Danton @ 2015-04-08 10:48 ` Daniel Thompson 0 siblings, 0 replies; 3+ messages in thread From: Daniel Thompson @ 2015-04-08 10:48 UTC (permalink / raw) To: Hillf Danton; +Cc: linux-kernel, Russell King, Steven Rostedt On 08/04/15 09:35, Hillf Danton wrote: >> >> +void ipi_cpu_backtrace(struct pt_regs *regs) >> +{ >> + int cpu = smp_processor_id(); >> + >> + if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) { >> + printk_nmi_backtrace_this_cpu_begin(); >> + pr_warn("FIQ backtrace for cpu %d\n", cpu); >> + if (regs != NULL) >> + show_regs(regs); >> + else >> + dump_stack(); > > Help more if we could print both register and stack info. I think this code already prints as much as it can in all cases. The arch/arm implementation of show_regs() calls dump_stack() internally so the first case does show register and stack info. In the second case, where regs is NULL because we have been called directly from task context, there aren't any saved regs for us to show. Daniel. ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 4.0-rc5 v19 0/6] irq/arm: Implement arch_trigger_all_cpu_backtrace @ 2015-03-24 16:53 Daniel Thompson 2015-04-07 15:37 ` [RESEND PATCH " Daniel Thompson 0 siblings, 1 reply; 3+ messages in thread From: Daniel Thompson @ 2015-03-24 16:53 UTC (permalink / raw) To: Thomas Gleixner, Jason Cooper Cc: Daniel Thompson, Russell King, Will Deacon, Catalin Marinas, Marc Zyngier, Stephen Boyd, John Stultz, Steven Rostedt, linux-kernel, linux-arm-kernel, patches, linaro-kernel, Sumit Semwal, Dirk Behme, Daniel Drake, Dmitry Pervushin, Tim Sander Jason/Thomas: This would be a resend except Steven Rostedt noticed a redundant memory barrier I had copied from the x86 code. The redundant barrier is now removed and there are no other changes since the code was posted a fortnight ago. Any chance of taking the first five of these patches via the irqchip route? The x86 patch has an ack from Ingo, printk has no explicit maintainer and I've done plenty of bisectability tests on the patchset so leaving the last patch for the next dev. cycle should be no trouble. This patchset modifies the GIC driver to allow it, on supported platforms, to route IPI interrupts to FIQ. It then uses this feature to implement arch_trigger_all_cpu_backtrace for arm. In order to neatly bring in the changes for the arm we also rearrange some of the existing x86 NMI code to make it architecture neutral. The patchset http://thread.gmane.org/gmane.linux.kernel/1897765 , which makes sched_clock() NMI/FIQ-safe, should be treated as a prerequisite for the sixth and final patch in the series (which enables the feature on ARM). Although sched_clock() is not called directly by any of the code that runs from a FIQ handler it is possible for sched_clock() to be called indirectly when the function tracer is enabled. The patches have been runtime tested on two systems capable of supporting FIQ (Freescale i.MX6 and STiH416) and two that do not (vexpress-a9 and Qualcomm Snapdragon 600), the changes to the x86 logic were tested on qemu and all patches have been compile tested on x86, arm and arm64. Note: On platforms not capable of supporting FIQ, the IPI to generate a backtrace will fall back to using IRQ for propagation instead. The backtrace logic contains a timeout to we will not permanently wedge the requesting CPU if other CPUs are not responsive. v19: * Remove redundant memory barrier inherited from the x86 code (Steven Rostedt). v18: * Move printk_nmi_ functions out of printk.c and into their own file, nmi_callback.c (Joe Perches/Steven Rostedt). * Rename printk_nmi_ functions so their name matches their new home (Joe Perches) v17: * Rename bl_migration_lock/unlock to gic_migration_lock/unlock (Nicolas Pitre). v16: * Significant clean up of the printk patches (Thomas Gleixner). Replacing macros with real functions, CONFIG_ARCH_WANT_NMI_PRINTK -> CONFIG_PRINTK_NMI, prefixing global functions with printk_nmi, removing pointless exports, removing cpu_mask from the interfaces, removal of just-in-time initialization of trace buffers, prevented call sites having to save state, rolled up variable declarations into single lines. * Dropped the sched_clock() patches from *this* patchset and managed them separately (http://thread.gmane.org/gmane.linux.kernel/1879261 ). The cross-dependancies between the patches are minimal; the backtrace code only calls sched_clock() if we are ftracing and backtracing is normally only triggered to report information about about a broken system (although users can type SysRq-l for amusement, most use it to find out why the system it dead). * Squashed together the final two patches. Essentially these duplicated the x86 code and slavishly avoided changing it before, in the next patch, fixing it to work better on ARM. It seems better that the code just works first time! v15: * Added a patch to make sched_clock safe to call from NMI (Stephen Boyd). Note that sched_clock() is not called by the NMI handlers that have been added for the arm but it could be called if tools such as ftrace are deployed. * Fixed some warnings picked up during bisectability testing. v14: * Moved a nmi_vprintk() and friends from arch/x86/kernel/apic/hw_nmi.c to printk.c (Steven Rostedt) v13: * Updated the code to print the backtrace to replicate Steven Rostedt's x86 work to make SysRq-l safe. This is pretty much a total rewrite of patches 4 and 5. v12: * Squash first two patches into a single one and re-describe (Thomas Gleixner). * Improve description of "irqchip: gic: Make gic_raise_softirq FIQ-safe" (Thomas Gleixner). v11: * Optimized gic_raise_softirq() by replacing a register read with a memory read (Jason Cooper). v10: * Add a further patch to optimize away some of the locking on systems where CONFIG_BL_SWITCHER is not set (Marc Zyngier). Compiles OK with exynos_defconfig (which is the only defconfig to set this option). * Whitespace fixes in patch 4. That patch previously used spaces for alignment of new constants but the rest of the file used tabs. v9: * Improved documentation and structure of initial patch (now initial two patches) to make gic_raise_softirq() safe to call from FIQ (Thomas Gleixner). * Avoid masking interrupts during gic_raise_softirq(). The use of the read lock makes this redundant (because we can safely re-enter the function). v8: * Fixed build on arm64 causes by a spurious include file in irq-gic.c. v7-2 (accidentally released twice with same number): * Fixed boot regression on vexpress-a9 (reported by Russell King). * Rebased on v3.18-rc3; removed one patch from set that is already included in mainline. * Dropped arm64/fiq.h patch from the set (still useful but not related to issuing backtraces). v7: * Re-arranged code within the patch series to fix a regression introduced midway through the series and corrected by a later patch (testing by Olof's autobuilder). Tested offending patch in isolation using defconfig identified by the autobuilder. v6: * Renamed svc_entry's call_trace argument to just trace (example code from Russell King). * Fixed mismatched ENDPROC() in __fiq_abt (example code from Russell King). * Modified usr_entry to optional avoid calling into the trace code and used this in FIQ entry from usr path. Modified corresponding exit code to avoid calling into trace code and the scheduler (example code from Russell King). * Ensured the default FIQ register state is restored when the default FIQ handler is reinstalled (example code from Russell King). * Renamed no_fiq_insn to dfl_fiq_insn to reflect the effect of adopting a default FIQ handler. * Re-instated fiq_safe_migration_lock and associated logic in gic_raise_softirq(). gic_raise_softirq() is called by wake_up_klogd() in the console unlock logic. v5: * Rebased on 3.17-rc4. * Removed a spurious line from the final "glue it together" patch that broke the build. v4: * Replaced push/pop with stmfd/ldmfd respectively (review of Nicolas Pitre). * Really fix bad pt_regs pointer generation in __fiq_abt. * Remove fiq_safe_migration_lock and associated logic in gic_raise_softirq() (review of Russell King) * Restructured to introduce the default FIQ handler first, before the new features (review of Russell King). v3: * Removed redundant header guards from arch/arm64/include/asm/fiq.h (review of Catalin Marinas). * Moved svc_exit_via_fiq macro to entry-header.S (review of Nicolas Pitre). v2: * Restructured to sit nicely on a similar FYI patchset from Russell King. It now effectively replaces the work in progress final patch with something much more complete. * Implemented (and tested) a Thumb-2 implementation of svc_exit_via_fiq (review of Nicolas Pitre) * Dropped the GIC group 0 workaround patch. The issue of FIQ interrupts being acknowledged by the IRQ handler does still exist but should be harmless because the IRQ handler will still wind up calling ipi_cpu_backtrace(). * Removed any dependency on CONFIG_FIQ; all cpu backtrace effectively becomes a platform feature (although the use of non-maskable interrupts to implement it is best effort rather than guaranteed). * Better comments highlighting usage of RAZ/WI registers (and parts of registers) in the GIC code. Changes *before* v1: * This patchset is a hugely cut-down successor to "[PATCH v11 00/19] arm: KGDB NMI/FIQ support". Thanks to Thomas Gleixner for suggesting the new structure. For historic details see: https://lkml.org/lkml/2014/9/2/227 * Fix bug in __fiq_abt (no longer passes a bad struct pt_regs value). In fixing this we also remove the useless indirection previously found in the fiq_handler macro. * Make default fiq handler "always on" by migrating from fiq.c to traps.c and replace do_unexp_fiq with the new handler (review of Russell King). * Add arm64 version of fiq.h (review of Russell King) * Removed conditional branching and code from irq-gic.c, this is replaced by much simpler code that relies on the GIC specification's heavy use of read-as-zero/write-ignored (review of Russell King) Daniel Thompson (6): irqchip: gic: Optimize locking in gic_raise_softirq irqchip: gic: Make gic_raise_softirq FIQ-safe irqchip: gic: Introduce plumbing for IPI FIQ printk: Simple implementation for NMI backtracing x86/nmi: Use common printk functions ARM: Add support for on-demand backtrace of other CPUs arch/arm/Kconfig | 1 + arch/arm/include/asm/hardirq.h | 2 +- arch/arm/include/asm/irq.h | 5 + arch/arm/include/asm/smp.h | 3 + arch/arm/kernel/smp.c | 81 ++++++++++++++++ arch/arm/kernel/traps.c | 8 +- arch/x86/Kconfig | 1 + arch/x86/kernel/apic/hw_nmi.c | 101 ++------------------ drivers/irqchip/irq-gic.c | 203 +++++++++++++++++++++++++++++++++++++--- include/linux/irqchip/arm-gic.h | 8 ++ include/linux/printk.h | 20 ++++ init/Kconfig | 3 + kernel/printk/Makefile | 1 + kernel/printk/nmi_backtrace.c | 147 +++++++++++++++++++++++++++++ 14 files changed, 473 insertions(+), 111 deletions(-) create mode 100644 kernel/printk/nmi_backtrace.c -- 2.1.0 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [RESEND PATCH 4.0-rc5 v19 0/6] irq/arm: Implement arch_trigger_all_cpu_backtrace 2015-03-24 16:53 [PATCH 4.0-rc5 v19 0/6] irq/arm: Implement arch_trigger_all_cpu_backtrace Daniel Thompson @ 2015-04-07 15:37 ` Daniel Thompson 2015-04-07 15:38 ` [RESEND PATCH 4.0-rc5 v19 6/6] ARM: Add support for on-demand backtrace of other CPUs Daniel Thompson 0 siblings, 1 reply; 3+ messages in thread From: Daniel Thompson @ 2015-04-07 15:37 UTC (permalink / raw) To: Thomas Gleixner, Jason Cooper Cc: Daniel Thompson, Russell King, Will Deacon, Catalin Marinas, Marc Zyngier, Stephen Boyd, John Stultz, Steven Rostedt, linux-kernel, linux-arm-kernel, patches, linaro-kernel, Sumit Semwal, Dirk Behme, Daniel Drake, Dmitry Pervushin, Tim Sander Jason/Thomas: Any chance of taking the first five of these patches via the irqchip route? The x86 patch has an ack from Ingo, printk has no explicit maintainer and I've done plenty of bisectability tests on the patchset so leaving the last patch for the next dev. cycle should be no trouble. This patchset modifies the GIC driver to allow it, on supported platforms, to route IPI interrupts to FIQ. It then uses this feature to implement arch_trigger_all_cpu_backtrace for arm. In order to neatly bring in the changes for the arm we also rearrange some of the existing x86 NMI code to make it architecture neutral. The patchset http://thread.gmane.org/gmane.linux.kernel/1897765 , which makes sched_clock() NMI/FIQ-safe, should be treated as a prerequisite for the sixth and final patch in the series (which enables the feature on ARM). Although sched_clock() is not called directly by any of the code that runs from a FIQ handler it is possible for sched_clock() to be called indirectly when the function tracer is enabled. The patches have been runtime tested on two systems capable of supporting FIQ (Freescale i.MX6 and STiH416) and two that do not (vexpress-a9 and Qualcomm Snapdragon 600), the changes to the x86 logic were tested on qemu and all patches have been compile tested on x86, arm and arm64. Note: On platforms not capable of supporting FIQ, the IPI to generate a backtrace will fall back to using IRQ for propagation instead. The backtrace logic contains a timeout to we will not permanently wedge the requesting CPU if other CPUs are not responsive. v19: * Remove redundant memory barrier inherited from the x86 code (Steven Rostedt). v18: * Move printk_nmi_ functions out of printk.c and into their own file, nmi_callback.c (Joe Perches/Steven Rostedt). * Rename printk_nmi_ functions so their name matches their new home (Joe Perches) v17: * Rename bl_migration_lock/unlock to gic_migration_lock/unlock (Nicolas Pitre). v16: * Significant clean up of the printk patches (Thomas Gleixner). Replacing macros with real functions, CONFIG_ARCH_WANT_NMI_PRINTK -> CONFIG_PRINTK_NMI, prefixing global functions with printk_nmi, removing pointless exports, removing cpu_mask from the interfaces, removal of just-in-time initialization of trace buffers, prevented call sites having to save state, rolled up variable declarations into single lines. * Dropped the sched_clock() patches from *this* patchset and managed them separately (http://thread.gmane.org/gmane.linux.kernel/1879261 ). The cross-dependancies between the patches are minimal; the backtrace code only calls sched_clock() if we are ftracing and backtracing is normally only triggered to report information about about a broken system (although users can type SysRq-l for amusement, most use it to find out why the system it dead). * Squashed together the final two patches. Essentially these duplicated the x86 code and slavishly avoided changing it before, in the next patch, fixing it to work better on ARM. It seems better that the code just works first time! v15: * Added a patch to make sched_clock safe to call from NMI (Stephen Boyd). Note that sched_clock() is not called by the NMI handlers that have been added for the arm but it could be called if tools such as ftrace are deployed. * Fixed some warnings picked up during bisectability testing. v14: * Moved a nmi_vprintk() and friends from arch/x86/kernel/apic/hw_nmi.c to printk.c (Steven Rostedt) v13: * Updated the code to print the backtrace to replicate Steven Rostedt's x86 work to make SysRq-l safe. This is pretty much a total rewrite of patches 4 and 5. v12: * Squash first two patches into a single one and re-describe (Thomas Gleixner). * Improve description of "irqchip: gic: Make gic_raise_softirq FIQ-safe" (Thomas Gleixner). v11: * Optimized gic_raise_softirq() by replacing a register read with a memory read (Jason Cooper). v10: * Add a further patch to optimize away some of the locking on systems where CONFIG_BL_SWITCHER is not set (Marc Zyngier). Compiles OK with exynos_defconfig (which is the only defconfig to set this option). * Whitespace fixes in patch 4. That patch previously used spaces for alignment of new constants but the rest of the file used tabs. v9: * Improved documentation and structure of initial patch (now initial two patches) to make gic_raise_softirq() safe to call from FIQ (Thomas Gleixner). * Avoid masking interrupts during gic_raise_softirq(). The use of the read lock makes this redundant (because we can safely re-enter the function). v8: * Fixed build on arm64 causes by a spurious include file in irq-gic.c. v7-2 (accidentally released twice with same number): * Fixed boot regression on vexpress-a9 (reported by Russell King). * Rebased on v3.18-rc3; removed one patch from set that is already included in mainline. * Dropped arm64/fiq.h patch from the set (still useful but not related to issuing backtraces). v7: * Re-arranged code within the patch series to fix a regression introduced midway through the series and corrected by a later patch (testing by Olof's autobuilder). Tested offending patch in isolation using defconfig identified by the autobuilder. v6: * Renamed svc_entry's call_trace argument to just trace (example code from Russell King). * Fixed mismatched ENDPROC() in __fiq_abt (example code from Russell King). * Modified usr_entry to optional avoid calling into the trace code and used this in FIQ entry from usr path. Modified corresponding exit code to avoid calling into trace code and the scheduler (example code from Russell King). * Ensured the default FIQ register state is restored when the default FIQ handler is reinstalled (example code from Russell King). * Renamed no_fiq_insn to dfl_fiq_insn to reflect the effect of adopting a default FIQ handler. * Re-instated fiq_safe_migration_lock and associated logic in gic_raise_softirq(). gic_raise_softirq() is called by wake_up_klogd() in the console unlock logic. v5: * Rebased on 3.17-rc4. * Removed a spurious line from the final "glue it together" patch that broke the build. v4: * Replaced push/pop with stmfd/ldmfd respectively (review of Nicolas Pitre). * Really fix bad pt_regs pointer generation in __fiq_abt. * Remove fiq_safe_migration_lock and associated logic in gic_raise_softirq() (review of Russell King) * Restructured to introduce the default FIQ handler first, before the new features (review of Russell King). v3: * Removed redundant header guards from arch/arm64/include/asm/fiq.h (review of Catalin Marinas). * Moved svc_exit_via_fiq macro to entry-header.S (review of Nicolas Pitre). v2: * Restructured to sit nicely on a similar FYI patchset from Russell King. It now effectively replaces the work in progress final patch with something much more complete. * Implemented (and tested) a Thumb-2 implementation of svc_exit_via_fiq (review of Nicolas Pitre) * Dropped the GIC group 0 workaround patch. The issue of FIQ interrupts being acknowledged by the IRQ handler does still exist but should be harmless because the IRQ handler will still wind up calling ipi_cpu_backtrace(). * Removed any dependency on CONFIG_FIQ; all cpu backtrace effectively becomes a platform feature (although the use of non-maskable interrupts to implement it is best effort rather than guaranteed). * Better comments highlighting usage of RAZ/WI registers (and parts of registers) in the GIC code. Changes *before* v1: * This patchset is a hugely cut-down successor to "[PATCH v11 00/19] arm: KGDB NMI/FIQ support". Thanks to Thomas Gleixner for suggesting the new structure. For historic details see: https://lkml.org/lkml/2014/9/2/227 * Fix bug in __fiq_abt (no longer passes a bad struct pt_regs value). In fixing this we also remove the useless indirection previously found in the fiq_handler macro. * Make default fiq handler "always on" by migrating from fiq.c to traps.c and replace do_unexp_fiq with the new handler (review of Russell King). * Add arm64 version of fiq.h (review of Russell King) * Removed conditional branching and code from irq-gic.c, this is replaced by much simpler code that relies on the GIC specification's heavy use of read-as-zero/write-ignored (review of Russell King) Daniel Thompson (6): irqchip: gic: Optimize locking in gic_raise_softirq irqchip: gic: Make gic_raise_softirq FIQ-safe irqchip: gic: Introduce plumbing for IPI FIQ printk: Simple implementation for NMI backtracing x86/nmi: Use common printk functions ARM: Add support for on-demand backtrace of other CPUs arch/arm/Kconfig | 1 + arch/arm/include/asm/hardirq.h | 2 +- arch/arm/include/asm/irq.h | 5 + arch/arm/include/asm/smp.h | 3 + arch/arm/kernel/smp.c | 81 ++++++++++++++++ arch/arm/kernel/traps.c | 8 +- arch/x86/Kconfig | 1 + arch/x86/kernel/apic/hw_nmi.c | 101 ++------------------ drivers/irqchip/irq-gic.c | 203 +++++++++++++++++++++++++++++++++++++--- include/linux/irqchip/arm-gic.h | 8 ++ include/linux/printk.h | 20 ++++ init/Kconfig | 3 + kernel/printk/Makefile | 1 + kernel/printk/nmi_backtrace.c | 147 +++++++++++++++++++++++++++++ 14 files changed, 473 insertions(+), 111 deletions(-) create mode 100644 kernel/printk/nmi_backtrace.c -- 2.1.0 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [RESEND PATCH 4.0-rc5 v19 6/6] ARM: Add support for on-demand backtrace of other CPUs 2015-04-07 15:37 ` [RESEND PATCH " Daniel Thompson @ 2015-04-07 15:38 ` Daniel Thompson 0 siblings, 0 replies; 3+ messages in thread From: Daniel Thompson @ 2015-04-07 15:38 UTC (permalink / raw) To: Thomas Gleixner, Jason Cooper Cc: Daniel Thompson, Russell King, Will Deacon, Catalin Marinas, Marc Zyngier, Stephen Boyd, John Stultz, Steven Rostedt, linux-kernel, linux-arm-kernel, patches, linaro-kernel, Sumit Semwal, Dirk Behme, Daniel Drake, Dmitry Pervushin, Tim Sander Replicate the x86 code to trigger a backtrace using an NMI and hook it up to IPI on ARM. The code differs slightly from the code on x86 because, on ARM, we do now know at compile time whether a platform is capable of supporting FIQ. We must avoid using an IPI to request a backtrace from the CPU on which the backtrace was requested if interrupts are disabled and fall back to generating it directly. In addition the implementation of arch_trigger_all_cpu_backtrace() the patch also includes a few small items of plumbing that must be hooked up for the new code to work. Credit: Russell King provided the initial prototype implementing this feature for ARM. Today the patch has been reworked and, mostly, rewriten to keep it aligned with x86. However this patch does still include some code from Russell's original prototype. Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org> Cc: Russell King <linux@arm.linux.org.uk> Cc: Steven Rostedt <rostedt@goodmis.org> --- arch/arm/Kconfig | 1 + arch/arm/include/asm/hardirq.h | 2 +- arch/arm/include/asm/irq.h | 5 +++ arch/arm/include/asm/smp.h | 3 ++ arch/arm/kernel/smp.c | 81 ++++++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/traps.c | 3 ++ 6 files changed, 94 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9f1f09a2bc9b..f3c95a44945d 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -76,6 +76,7 @@ config ARM select OLD_SIGACTION select OLD_SIGSUSPEND3 select PERF_USE_VMALLOC + select PRINTK_NMI_BACKTRACE select RTC_LIB select SYS_SUPPORTS_APM_EMULATION # Above selects are sorted alphabetically; please add new ones diff --git a/arch/arm/include/asm/hardirq.h b/arch/arm/include/asm/hardirq.h index fe3ea776dc34..5df33e30ae1b 100644 --- a/arch/arm/include/asm/hardirq.h +++ b/arch/arm/include/asm/hardirq.h @@ -5,7 +5,7 @@ #include <linux/threads.h> #include <asm/irq.h> -#define NR_IPI 8 +#define NR_IPI 9 typedef struct { unsigned int __softirq_pending; diff --git a/arch/arm/include/asm/irq.h b/arch/arm/include/asm/irq.h index 53c15dec7af6..be1d07d59ee9 100644 --- a/arch/arm/include/asm/irq.h +++ b/arch/arm/include/asm/irq.h @@ -35,6 +35,11 @@ extern void (*handle_arch_irq)(struct pt_regs *); extern void set_handle_irq(void (*handle_irq)(struct pt_regs *)); #endif +#ifdef CONFIG_SMP +extern void arch_trigger_all_cpu_backtrace(bool); +#define arch_trigger_all_cpu_backtrace(x) arch_trigger_all_cpu_backtrace(x) +#endif + #endif #endif diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h index 18f5a554134f..b076584ac0fa 100644 --- a/arch/arm/include/asm/smp.h +++ b/arch/arm/include/asm/smp.h @@ -18,6 +18,8 @@ # error "<asm/smp.h> included in non-SMP build" #endif +#define SMP_IPI_FIQ_MASK 0x0100 + #define raw_smp_processor_id() (current_thread_info()->cpu) struct seq_file; @@ -79,6 +81,7 @@ extern void arch_send_call_function_single_ipi(int cpu); extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask); +extern void ipi_cpu_backtrace(struct pt_regs *regs); extern int register_ipi_completion(struct completion *completion, int cpu); struct smp_operations { diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 86ef244c5a24..7eb6241e99d1 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -26,6 +26,7 @@ #include <linux/completion.h> #include <linux/cpufreq.h> #include <linux/irq_work.h> +#include <linux/seq_buf.h> #include <linux/atomic.h> #include <asm/smp.h> @@ -72,6 +73,7 @@ enum ipi_msg_type { IPI_CPU_STOP, IPI_IRQ_WORK, IPI_COMPLETION, + IPI_CPU_BACKTRACE, }; static DECLARE_COMPLETION(cpu_running); @@ -456,6 +458,7 @@ static const char *ipi_types[NR_IPI] __tracepoint_string = { S(IPI_CPU_STOP, "CPU stop interrupts"), S(IPI_IRQ_WORK, "IRQ work interrupts"), S(IPI_COMPLETION, "completion interrupts"), + S(IPI_CPU_BACKTRACE, "backtrace interrupts"), }; static void smp_cross_call(const struct cpumask *target, unsigned int ipinr) @@ -570,6 +573,8 @@ void handle_IPI(int ipinr, struct pt_regs *regs) unsigned int cpu = smp_processor_id(); struct pt_regs *old_regs = set_irq_regs(regs); + BUILD_BUG_ON(SMP_IPI_FIQ_MASK != BIT(IPI_CPU_BACKTRACE)); + if ((unsigned)ipinr < NR_IPI) { trace_ipi_entry(ipi_types[ipinr]); __inc_irq_stat(cpu, ipi_irqs[ipinr]); @@ -623,6 +628,12 @@ void handle_IPI(int ipinr, struct pt_regs *regs) irq_exit(); break; + case IPI_CPU_BACKTRACE: + irq_enter(); + ipi_cpu_backtrace(regs); + irq_exit(); + break; + default: pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr); @@ -717,3 +728,73 @@ static int __init register_cpufreq_notifier(void) core_initcall(register_cpufreq_notifier); #endif + +/* For reliability, we're prepared to waste bits here. */ +static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly; + +void arch_trigger_all_cpu_backtrace(bool include_self) +{ + int i; + int this_cpu = get_cpu(); + + if (0 != printk_nmi_backtrace_prepare()) { + /* + * If there is already an nmi printk sequence in + * progress then just give up... + */ + put_cpu(); + return; + } + + cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask); + + /* + * If irqs are disabled on the current processor and + * IPI_CPU_BACKTRACE is delivered using IRQ then we aren't be able to + * react to IPI_CPU_BACKTRACE until we leave this function. This + * would force us to get stuck and, eventually, timeout. We avoid + * the timeout (and the resulting failure to print useful information) + * by calling the backtrace logic directly whenever irqs are disabled. + */ + if (include_self && irqs_disabled()) { + ipi_cpu_backtrace(in_interrupt() ? get_irq_regs() : NULL); + include_self = false; + } + + if (!include_self) + cpumask_clear_cpu(this_cpu, to_cpumask(backtrace_mask)); + + if (!cpumask_empty(to_cpumask(backtrace_mask))) { + pr_info("Sending FIQ to %s CPUs:\n", + (include_self ? "all" : "other")); + smp_cross_call(to_cpumask(backtrace_mask), IPI_CPU_BACKTRACE); + } + + /* Wait for up to 10 seconds for all CPUs to do the backtrace */ + for (i = 0; i < 10 * 1000; i++) { + if (cpumask_empty(to_cpumask(backtrace_mask))) + break; + mdelay(1); + touch_softlockup_watchdog(); + } + + printk_nmi_backtrace_complete(); + put_cpu(); +} + +void ipi_cpu_backtrace(struct pt_regs *regs) +{ + int cpu = smp_processor_id(); + + if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) { + printk_nmi_backtrace_this_cpu_begin(); + pr_warn("FIQ backtrace for cpu %d\n", cpu); + if (regs != NULL) + show_regs(regs); + else + dump_stack(); + printk_nmi_backtrace_this_cpu_end(); + + cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask)); + } +} diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index b35e220ae1b1..1836415b8a5c 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -483,6 +483,9 @@ asmlinkage void __exception_irq_entry handle_fiq_as_nmi(struct pt_regs *regs) #ifdef CONFIG_ARM_GIC gic_handle_fiq_ipi(); #endif +#ifdef CONFIG_SMP + ipi_cpu_backtrace(regs); +#endif nmi_exit(); -- 2.1.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-08 10:48 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <089101d071d6$4ebe2a90$ec3a7fb0$@alibaba-inc.com> 2015-04-08 8:35 ` [RESEND PATCH 4.0-rc5 v19 6/6] ARM: Add support for on-demand backtrace of other CPUs Hillf Danton 2015-04-08 10:48 ` Daniel Thompson 2015-03-24 16:53 [PATCH 4.0-rc5 v19 0/6] irq/arm: Implement arch_trigger_all_cpu_backtrace Daniel Thompson 2015-04-07 15:37 ` [RESEND PATCH " Daniel Thompson 2015-04-07 15:38 ` [RESEND PATCH 4.0-rc5 v19 6/6] ARM: Add support for on-demand backtrace of other CPUs Daniel Thompson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).