Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755231AbcCPRCj (ORCPT ); Wed, 16 Mar 2016 13:02:39 -0400 Received: from mail-db3on0088.outbound.protection.outlook.com ([157.55.234.88]:11707 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753458AbcCPRCh (ORCPT ); Wed, 16 Mar 2016 13:02:37 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; mellanox.com; dkim=none (message not signed) header.d=none;mellanox.com; dmarc=fail action=none header.from=mellanox.com; From: Chris Metcalf To: Peter Zijlstra , Russell King , Thomas Gleixner , Aaron Tomlin , Ingo Molnar , Andrew Morton , Daniel Thompson , , , CC: Chris Metcalf Subject: [PATCH v2 1/4] nmi_backtrace: add more trigger_*_cpu_backtrace() methods Date: Wed, 16 Mar 2016 13:02:10 -0400 Message-ID: <1458147733-29338-2-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1458147733-29338-1-git-send-email-cmetcalf@mellanox.com> References: <1458147733-29338-1-git-send-email-cmetcalf@mellanox.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:12.216.194.146;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(11100500001)(87936001)(36756003)(50466002)(4326007)(85426001)(86362001)(2950100001)(104016004)(2906002)(6806005)(42186005)(5008740100001)(2201001)(5003940100001)(575784001)(50986999)(76176999)(48376002)(1096002)(1220700001)(586003)(33646002)(19580395003)(92566002)(5001970100001)(47776003)(5001770100001)(229853001)(107886002)(19580405001)(106466001)(189998001)(105606002)(960300001)(921003)(1121003)(83996005)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB1693;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AM1FFO11FD021;1:7cMXvWyoaz1RKbAV2B2Rd9a0fECK3GHhqkRvrxzoNZ38JazAheTWMpGeI9Sh+LtncgsvQAHxUhu6bHbudeuk73zsNYTWKs2FSY74V9FDMRQUgSMC4dUst7+efSBES/tTve9sAax9uPiws++xJ1cVgxcdGx1vgYvjVLLXRo8afg7BCQF2liDqxfM11lRqSStJVNvaaP5DCqcj/Znq6ENP0aNGj2oxz6MPbkRS0y+v6GHdhtjI3TMkvXzO5lxeyfDuvbxQRJxdJ2NKpaH3WIZjjfPSXzuOJqjUjjSoyttMpvnbJ+giacztOPTGfzBFlnLyABLN1GAkq9CincnaydjHamL4DwkT4qjYiqbP3nz2lXQ65jiOAr0d1YtZ9/rUzk4RRq6BU0YhHLbvhYCtXbxD3zUAeMJnBIZmpLa0SqJJFO0NM2KwjV6hwypoYqXiv/JigQLEL42m2AV1H6oB0srdRu+GjlxiIqu98QN7O7yrP1k4T4RNtI2H3lQzF/XyBNyi7uqc7yI7d9O+rKl5e+AtW50EvkjVz3gUKyNYqWTd7zQ= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 64eb7134-3cfb-4241-9960-08d34dbcc39a X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1693;2:P6edZ3g6FGNlcNB3OvK7JJN+N54Ltvd3Tl1fcNY20WIkPTs8ETJ8m5P5wkBGJbqxcCquiLvGOPZNywHJpw1/JkWCA4EgbuOo69pRTnASNHtVE3wrLiDGqZ0eSGZ4Z6Z1PsprY6kBENLoP4JRrPYGXQrVVMTRcx1Y7uxla7xMrAl1b7r7LtX0wafJAybOVKn6;3:8r48RC52FOngLofKHrLTyz7hxk3th5F7nBynk3zLKKWz4ZwxJnZWRfapBpus1Qjg8R5XwR40vI7B2XL9/wm7eZSAue5FBgytbDS1EwRawJ7qXWzFdcCep63cpDJQocciAorO26LpgdTjb/MLczbPi6v9wSPp9JyI1B5LBT39KYCCHKO52WGZVpfD11Kw3ipOZASf+5mlZ8VmUgUdKifYQWMTkmkoQIVvaHKhvAD2l40=;25:gI1Eyvhj7woZSx48MXpz28NjNhwpYk36AqQNEUh0o1TX1GQTAxucFqcftNJY+H9HwomsVwREf+Dzh8j8bjHH0uU5MBXOWWf2EvjZfNHqaiYd5CMzZiIJpsfT4Ig/eWoOwRZBwfNpyantjBkRJMpcb1n0pVjBS+r/nF4fJt54+hcF3Xgd+eovFkIjy+3cJTgsHwLGjupp/F6rVJkofQXPdl+pnIgsqVC5yGr0YeoFO1uR098JPu1NjONEvnUxnQ2g/Na5uIyAdZATMjVpD3Egw1K25aGwys5KeCP3LJIX/yq0cPfLAUxn7kbEYcKfmlet41RuWg5wdBuCB0CfkkiCLg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1693; X-MLNXRule-EZCH-Linux: Rule triggered X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1693;20:1sT0GD6y8VJeh2FWZo1tQao94Nf8EraQkHg8PcDDohTXEyHgljyNLRGpNN1Hc48/2sE5cereIJb4z8T2D7Q2gRa4jDnGUd5xaoqxec5oiFH+PS09BuUbyeJdDYlBFJyoCo5k6SDykGl1nd1iWEwzRcy7sKV9SHSn4+YlM/0JOkBKAS+qimX2hLV9HvQa8FFWus2aLfAjgxWqW+bqNc/JLnyiOv3nHEcXd0p7UTdu8mN0BkCztsNz8+V4Eby+G6OxBtQkBe7BS+XSu5d65YKt5ntXmQAgUMCU4N1mYocl5n4ujPJ5DRuEgCp9mxHYbo1mOLPwLMLZPzzLLaKOSRn4cCIQmFHbYmpZxVjwOBPE+ULlOkfoxswkWruW3+z7YXZAcWWEc2iajaPZ4nmw8oZCjHUB+stldoA4XMUSbSoYcVz+kF22UbTNwRWWiUJTSkNymYSd7U2dUuhyCe0iTm8yoCXRm0qYA0SNU40deup73rxNT7rtJxLf0x7oTsP05n4z X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(13023025)(13017025)(13024025)(13015025)(13018025)(8121501046)(3002001)(10201501046);SRVR:VI1PR05MB1693;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1693; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1693;4:8O0z/QUU3IGxGX6aMUIBz0HOQ/rqvYf78KZGAM05Je7fANl1gqoTubjTrpF/yB8bEqBj6QcmOuBGmddK3caA9pmY4J4A1CIG6Nz6trO0n8MpPc5HlhsAjLD8cv7IBz+ZEiPsO+unpBQ9KCTX7vo95gTqzu+f3ZNNePJ57O5xGziAvjnevpm0ci4nvWFoZUPaVWyeqQRhzVVK2095Wq1jqiurqQlO9lVMU5ZwXxn2w7wXa69kJusS1Vq3qgx9MqHZl81MtHXERpd8oDEyNfintfd4C1FNRs9UdwHZO5DPCtslJuJQfOtY4zdK82Mm3szAQ/R0+8zFJWXD2e7ipCoFY4hU3N2pH7q3QSbyiIs/KAb7sxpx1CwPeV67CjyamnTKL1iJAPAsrU0KbFsKhHCZurG55DN5hb+oADc25+Z6GEoykuBF7FYQw7ly+hQiaZIC5Ue/gQ8GzkgstQHUa1bwVQ== X-Forefront-PRVS: 08831F51DC X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR05MB1693;23:0eHDe7Nkjiq9V4YWjHOUU/yfXVdpAY+qY3ifkDPBH?= =?us-ascii?Q?wzpwDPeYINUkEE8yUpEfEctaXFvZS1XMCjpaybnjdQ8tVvo8ujdkb3XEjHut?= =?us-ascii?Q?KSFnWdbnEJDK5emfTLyuBjowQ/we6zcGjk0SIkqhE0FrBONHJg7GNHp6TE8D?= =?us-ascii?Q?aHgz1uaIvHSxErFo8Ojv0zAQsXvP9SPNvUdak+J3SmBtWiyVDyhCQQlqzxLb?= =?us-ascii?Q?mc3FT/HbBVoHEh9eD+mrHWYiPl3Cfn1X8WJmYIi/40ziWvCNKL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FhiTOAA6MKH121j65cgs0U3nrcuVa592rfnTbwO?= =?us-ascii?Q?vTi/AijqF2DF9I=3D?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1693;5:grcRGPRILwH7ddmjGcgEXiG4pNgQ5v6r09j6RgNJ/Y2yEzgCWB+iFXgLpiypjFC95T2kczU9lzLzFKGHv5AcbGi1BIiAsdzps/HNqeJ7FiU5+d3d9m+UVHQ+0R4eYRBcsmg8TtJd3LIRakGuRVbnuw==;24:hqfwmZ85XRHk+0xdbMgedvockM1LHT8FEIuYvX3QUapVxwwdBYEHbp2hP1m+zM3XeF+GxVT55su5PStvy4UoFO72/vkLb/IwdN61CqKRt0g= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2016 17:02:31.5883 (UTC) X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a652971c-7d2e-4d9b-a6a4-d149256f461b;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1693 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7778 Lines: 236 Currently you can only request a backtrace of either all cpus, or all cpus but yourself. It can also be helpful to request a remote backtrace of a single cpu, and since we want that, the logical extension is to support a cpumask as the underlying primitive. This change modifies the existing lib/nmi_backtrace.c code to take a cpumask as its basic primitive, and modifies the linux/nmi.h code to use either the old "all/all_but_self" arch methods, or the new "cpumask" method, depending on which is available. The existing clients of nmi_backtrace (arm and x86) are converted to using the new cpumask approach in this change. Signed-off-by: Chris Metcalf --- arch/arm/include/asm/irq.h | 4 +-- arch/arm/kernel/smp.c | 4 +-- arch/x86/include/asm/irq.h | 4 +-- arch/x86/kernel/apic/hw_nmi.c | 6 ++--- include/linux/nmi.h | 63 ++++++++++++++++++++++++++++++++++--------- lib/nmi_backtrace.c | 15 +++++------ 6 files changed, 65 insertions(+), 31 deletions(-) diff --git a/arch/arm/include/asm/irq.h b/arch/arm/include/asm/irq.h index 1bd9510de1b9..13f9a9a17eca 100644 --- a/arch/arm/include/asm/irq.h +++ b/arch/arm/include/asm/irq.h @@ -36,8 +36,8 @@ 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) +extern void arch_trigger_cpumask_backtrace(const cpumask_t *mask); +#define arch_trigger_cpumask_backtrace(x) arch_trigger_cpumask_backtrace(x) #endif static inline int nr_legacy_irqs(void) diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 37312f6749f3..208125658e56 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -758,7 +758,7 @@ static void raise_nmi(cpumask_t *mask) smp_cross_call(mask, IPI_CPU_BACKTRACE); } -void arch_trigger_all_cpu_backtrace(bool include_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask) { - nmi_trigger_all_cpu_backtrace(include_self, raise_nmi); + nmi_trigger_cpumask_backtrace(mask, raise_nmi); } diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h index e7de5c9a4fbd..18bdc8cc5c63 100644 --- a/arch/x86/include/asm/irq.h +++ b/arch/x86/include/asm/irq.h @@ -50,8 +50,8 @@ extern int vector_used_by_percpu_irq(unsigned int vector); extern void init_ISA_irqs(void); #ifdef CONFIG_X86_LOCAL_APIC -void arch_trigger_all_cpu_backtrace(bool); -#define arch_trigger_all_cpu_backtrace arch_trigger_all_cpu_backtrace +void arch_trigger_cpumask_backtrace(const struct cpumask *mask); +#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace #endif #endif /* _ASM_X86_IRQ_H */ diff --git a/arch/x86/kernel/apic/hw_nmi.c b/arch/x86/kernel/apic/hw_nmi.c index 045e424fb368..63f0b69ad6a6 100644 --- a/arch/x86/kernel/apic/hw_nmi.c +++ b/arch/x86/kernel/apic/hw_nmi.c @@ -27,15 +27,15 @@ u64 hw_nmi_get_sample_period(int watchdog_thresh) } #endif -#ifdef arch_trigger_all_cpu_backtrace +#ifdef arch_trigger_cpumask_backtrace static void nmi_raise_cpu_backtrace(cpumask_t *mask) { apic->send_IPI_mask(mask, NMI_VECTOR); } -void arch_trigger_all_cpu_backtrace(bool include_self) +void arch_trigger_cpumask_backtrace(const cpumask_t *mask) { - nmi_trigger_all_cpu_backtrace(include_self, nmi_raise_cpu_backtrace); + nmi_trigger_cpumask_backtrace(mask, nmi_raise_cpu_backtrace); } static int diff --git a/include/linux/nmi.h b/include/linux/nmi.h index 7ec5b86735f3..951875f4f072 100644 --- a/include/linux/nmi.h +++ b/include/linux/nmi.h @@ -31,38 +31,75 @@ static inline void hardlockup_detector_disable(void) {} #endif /* - * Create trigger_all_cpu_backtrace() out of the arch-provided - * base function. Return whether such support was available, + * Create trigger_all_cpu_backtrace() etc out of the arch-provided + * base function(s). Return whether such support was available, * to allow calling code to fall back to some other mechanism: */ -#ifdef arch_trigger_all_cpu_backtrace static inline bool trigger_all_cpu_backtrace(void) { +#if defined(arch_trigger_all_cpu_backtrace) arch_trigger_all_cpu_backtrace(true); - return true; +#elif defined(arch_trigger_cpumask_backtrace) + arch_trigger_cpumask_backtrace(cpu_online_mask); + return true; +#else + return false; +#endif } + static inline bool trigger_allbutself_cpu_backtrace(void) { +#if defined(arch_trigger_all_cpu_backtrace) arch_trigger_all_cpu_backtrace(false); return true; -} - -/* generic implementation */ -void nmi_trigger_all_cpu_backtrace(bool include_self, - void (*raise)(cpumask_t *mask)); -bool nmi_cpu_backtrace(struct pt_regs *regs); +#elif defined(arch_trigger_cpumask_backtrace) + cpumask_var_t mask; + int cpu = get_cpu(); + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) + return false; + cpumask_copy(mask, cpu_online_mask); + cpumask_clear_cpu(cpu, mask); + arch_trigger_cpumask_backtrace(mask); + put_cpu(); + free_cpumask_var(mask); + return true; #else -static inline bool trigger_all_cpu_backtrace(void) -{ return false; +#endif } -static inline bool trigger_allbutself_cpu_backtrace(void) + +static inline bool trigger_cpumask_backtrace(struct cpumask *mask) { +#if defined(arch_trigger_cpumask_backtrace) + arch_trigger_cpumask_backtrace(mask); + return true; +#else return false; +#endif } + +static inline bool trigger_single_cpu_backtrace(int cpu) +{ +#if defined(arch_trigger_cpumask_backtrace) + cpumask_var_t mask; + + if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) + return false; + cpumask_set_cpu(cpu, mask); + arch_trigger_cpumask_backtrace(mask); + free_cpumask_var(mask); + return true; +#else + return false; #endif +} + +/* generic implementation */ +void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, + void (*raise)(cpumask_t *mask)); +bool nmi_cpu_backtrace(struct pt_regs *regs); #ifdef CONFIG_LOCKUP_DETECTOR int hw_nmi_is_cpu_stuck(struct pt_regs *); diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c index 6019c53c669e..db63ac75eba0 100644 --- a/lib/nmi_backtrace.c +++ b/lib/nmi_backtrace.c @@ -18,7 +18,7 @@ #include #include -#ifdef arch_trigger_all_cpu_backtrace +#ifdef arch_trigger_cpumask_backtrace /* For reliability, we're prepared to waste bits here. */ static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly; static cpumask_t printtrace_mask; @@ -44,12 +44,12 @@ static void print_seq_line(struct nmi_seq_buf *s, int start, int end) } /* - * When raise() is called it will be is passed a pointer to the + * When raise() is called it will be passed a pointer to the * backtrace_mask. Architectures that call nmi_cpu_backtrace() * directly from their raise() functions may rely on the mask * they are passed being updated as a side effect of this call. */ -void nmi_trigger_all_cpu_backtrace(bool include_self, +void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, void (*raise)(cpumask_t *mask)) { struct nmi_seq_buf *s; @@ -64,10 +64,7 @@ void nmi_trigger_all_cpu_backtrace(bool include_self, return; } - cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask); - if (!include_self) - cpumask_clear_cpu(this_cpu, to_cpumask(backtrace_mask)); - + cpumask_copy(to_cpumask(backtrace_mask), mask); cpumask_copy(&printtrace_mask, to_cpumask(backtrace_mask)); /* @@ -80,8 +77,8 @@ void nmi_trigger_all_cpu_backtrace(bool include_self, } if (!cpumask_empty(to_cpumask(backtrace_mask))) { - pr_info("Sending NMI to %s CPUs:\n", - (include_self ? "all" : "other")); + pr_info("Sending NMI from CPU %d to CPUs %*pbl:\n", + this_cpu, nr_cpumask_bits, to_cpumask(backtrace_mask)); raise(to_cpumask(backtrace_mask)); } -- 2.7.2