Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932875AbcC3RRM (ORCPT ); Wed, 30 Mar 2016 13:17:12 -0400 Received: from mail-db3on0090.outbound.protection.outlook.com ([157.55.234.90]:54631 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932307AbcC3RQj (ORCPT ); Wed, 30 Mar 2016 13:16:39 -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 , "Rafael J. Wysocki" , Petr Mladek , Russell King , Thomas Gleixner , Aaron Tomlin , Ingo Molnar , Andrew Morton , CC: Chris Metcalf Subject: [PATCH v4 3/4] arch/tile: adopt the new nmi_backtrace framework Date: Wed, 30 Mar 2016 13:16:09 -0400 Message-ID: <1459358170-27745-4-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1459358170-27745-1-git-send-email-cmetcalf@mellanox.com> References: <1459358170-27745-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)(339900001)(199003)(189002)(47776003)(33646002)(42186005)(48376002)(11100500001)(87936001)(50466002)(586003)(86362001)(85426001)(960300001)(76176999)(50986999)(5003940100001)(1220700001)(92566002)(36756003)(1096002)(50226001)(5001770100001)(5001970100001)(4001430100002)(106466001)(189998001)(229853001)(107886002)(6806005)(2950100001)(104016004)(5008740100001)(105606002)(19580405001)(2906002)(4326007)(19580395003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB5PR05MB1687;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AM1FFO11FD037;1:wdKe4WOR1hQDcdM8aYEHaaj9ZHhLXXgL/5fgxw3GC/vJ8/NYa9D7GeJK4/M6NcBy1XBjs2ykEocxnd3SC0Y4Gxima5bSvw8m2WIB407lrudFRtxdmEKMz2GgQ1iMsOlrKV/YiRfBrap8EgdskyEaoNHQePTwa6tLG9MUT7KdU6WxcN6nprFWEJQxyQ8kRkiuqUOtqiESMCCXtCM8qD+DgOxrBouhqS3GFFD38wzJ+CokidA7Bdtvi/RHufDzlbnNMPaPXpRahgX+XUkbzMyKtVNqmoll9UaaMTsjo/B4iUcghHpohKEDBZbXpKgusIF0QuP4Qz5yFIU9Neq6VYOQsaHODAvSSIj/h8c78eThbCw3McT4Koi9M7gURe3Led26PNQS4GlnLuxGVQUA/8/KPLAfZHsrKMMia8zKnm/jRTxrZ7HX2qSN0h6RhtBGonv4XDG+fDhyWN7R6aaKfQ+5Do76CkXT+PtYP8dWaknYwKa6Oz8XupFgxTOiHdPNU/pQ7rnY8ueeGef+SRkLQctfrUvpzzar7/cCuqVfB9EveirY+84M6NBUIc7NIU0zyHAE MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: fc28a246-509c-4567-f895-08d358bf0bdc X-Microsoft-Exchange-Diagnostics: 1;DB5PR05MB1687;2:jrvbFCPD8rgKAHeXOHNAnEZGIxL+ghdWCLnpgaceR9JaabX1HcBC+p/vAqGmwaF3D+tn8Ut2NJVlRRkXNaHD3GZsDZAtJ6pfuO5prUExUAMEIn4o1GLWY8nyMT2bHDz9Dx4ZdmDFb0Qv2OSfrt7RQG1H40Z0ukdzwihGIz6Z3xDNaWhvRXLTh9Bv/3DuImcB;3:Gxye0ooRdsDimJ14TZwkkbt8kpfZe2QrzT+4y1gPHmu/QM4GmwV8YqAULSTPN/9D5Eg5P2ooWTCNoVeQPGObZL94a44JTIAeXNGsImkY9UU3NGGvjqHauUc7NE/q0/nZ4RI37wwJoXrR1OIAKX5lK4N7VpISsJS+su/HMu1e0VKXMeOpHR9N3+klChUahRh+E7S7FxnIwm7YH+ufAcWKMr+M9pRPzuTYuRX6OAaUA/Q=;25:LwNpwuI6rOnm2AWBivwOABgxt6toK3bw3F6SBZgNxL5a1bBgvzbNErSZxndQLZn6nW9LSRgn4p6UH8eUWyBDkTTNXFm9x04V6auDOTiXoddHzjsdtAiPqJjvDPrphThATKuWoMDRLvyfQ4uSzL0xjuNwBmWaGTgCHCJAr91S/FpGul66s9JovUSdIM3Cl3mKYDiEyNl1zoN5tySXGKdPKZSGj7u2PUM8Jj21UPBMvj2QDE0j6lUd6ulQ4NClBjxV+ljKK7xODULoonOYOJ25OKSm7jDm8uRQN9cMWThdjaVlKoOMtWSyi0l2h2bIfymXjCTBIwBuK0Q7QN9IQJtLRn0uM+rsbU7inDp+fk77UZE= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR05MB1687; X-Microsoft-Exchange-Diagnostics: 1;DB5PR05MB1687;20:lfFk06iVk8PbuOGbZvK7jilnd92ntrsKKwe1h0FZJJb+nOn9E49io35Uwfxp1BXTVepHNXvBqvJB2PFORe1Wc2gKc21fqcfRqqA7A5IzTF3//uo1FT3Zw/AqNAhO+LF8HqdiDYCgGS5Ic11gvXSYNBa6VVieitgcUMLdrv/9mMnqA9gFta3GiMDLw0NtRqd/gFGIgoeZxeoZH0p6EfEzUDx4GE6EGPhSFxGS9MmpITWNpNci9vF7z0FtPn+y/tiGY1XZ1aYpSOnhuqx3+YHr2Darr2/3odkcScqxl6LxXACNuV+4WBqQ/UGWU+5NPsHX2DmrrpmDJkXO0NycjgrQgshYpPbNv75+Bjbbatmhnoj2qJNDE4xrR06s1vxwPAmGW/r9+74xuyC4mu7K1mzsyi6tKC0pLCODIQ33Mo3jbMjiHZ73JB80a/lYanNaZBL8K+Uy8vNetQDyri/9uV9wdTk+idpyUu7myUThM6X6LuswZmYyvC5wlw6s0AsMRgJW X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(13018025)(13024025)(5005006)(13017025)(13015025)(8121501046)(13023025)(10201501046)(3002001);SRVR:DB5PR05MB1687;BCL:0;PCL:0;RULEID:;SRVR:DB5PR05MB1687; X-Microsoft-Exchange-Diagnostics: 1;DB5PR05MB1687;4:dE0rAOJBuVaDYYASN2nHFxKUITEA5juKEyJ8vUSRj8DTRKEK6QHglUy0ahb6iTd9G3U/elXvpEgK2kb+DnQg5+iEq7dof7gtNhg/wX8/DrRip5UHJy9BDVQCEfmH+fC2MllOyvU+Y5UCz4+PlGcxtIeb5VfVWQfzePvK/jn6LfMCjxI2UE+ndBXzFh0m0kzuVM37DYdnOi3e0hcD9mjPGMECNj3IO26V48vi5UklG28XCXeayokdPyqb+cMoeLKs5kazb6RppLCxZ1UJ0VWLEB/ItLhs2HAB4vpvJVSheUkJGbedMj4yd0tSjqMIHAWy2WDV5JPa306Z8Dc1qLoTD6Q1fgly6Yv+0D4Dz2sbOWflDBUoqUxo8dz0uw1JQCta68pCuwgUe+PQ7Ljz7fCWBU5Skse+nXyZjFHRv/+jvoW+/lKno69+L6UKPQ0CcavH51qAzI4eeZIXuyjboOqfjQ== X-Forefront-PRVS: 08978A8F5C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB5PR05MB1687;23:VhGoA57VPy3AAeuUR797JKYGksk6bO9urykuoTnMY?= =?us-ascii?Q?RJOlLuzS0mNAFeLU4qyX+6mbu/6R5dDaDM3KfOnBpx6huWoSR8rProHrEBPU?= =?us-ascii?Q?Q+KP93xUHikCksPZRDyqDKfg5CdrzO3gEBaz9wdK1TkxWdlGYTZf1YkAMvPd?= =?us-ascii?Q?AOJUbIK5MhyMa/ZNoN8N0QWaXVDZ0EMR1nKnpBbZdZvH7euLZBM3kCbo7zWi?= =?us-ascii?Q?vSX7q2G8FUadkz4I7Y3aG8MkbZ450yi+JvNlipMjbPsJq7JVVnnjHIk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687;5:gcQHXzptSb64cwIdfcrTepmGwbIYwNMMYcSdHb+2GZ2AQUmUSFZ2JmP9g+fl1xBLKyuBdRvEe1++nupagP/mXey7WkFBeQ86EBqIeXKzffdm73O8wYiJpkrPnOJu8D4dSBAcI+VN21z/r+nOkb6FSA==;24:WHKRm0KuS/Bs6kAJRoR+MQyWRBnYU1sXzV9AAxK9kjkPfrZlFbM8tzzFOAcNgYvfHvOGg0o3ad5/TdHSSNvOS4bZXr7ddE9u0YqDFt6gFj4= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2016 17:16:34.6188 (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: DB5PR05MB1687 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6415 Lines: 216 Previously tile was rolling its own method of capturing backtrace data in the NMI handlers, but it was relying on running printk() from the NMI handler, which is not always safe. So adopt the nmi_backtrace model (with the new cpumask extension) instead. So we can call the nmi_backtrace code directly from the nmi handler, move the nmi_enter()/exit() into the top-level tile NMI handler. The semantics of the routine change slightly since it is now synchronous with the remote cores completing the backtraces. Previously it was asynchronous, but with protection to avoid starting a new remote backtrace if the old one was still in progress. Signed-off-by: Chris Metcalf --- arch/tile/include/asm/irq.h | 4 +-- arch/tile/kernel/pmc.c | 3 -- arch/tile/kernel/process.c | 72 ++++++++++----------------------------------- arch/tile/kernel/traps.c | 7 +++-- 4 files changed, 23 insertions(+), 63 deletions(-) diff --git a/arch/tile/include/asm/irq.h b/arch/tile/include/asm/irq.h index 84a924034bdb..909230a02ea8 100644 --- a/arch/tile/include/asm/irq.h +++ b/arch/tile/include/asm/irq.h @@ -79,8 +79,8 @@ void tile_irq_activate(unsigned int irq, int tile_irq_type); void setup_irq_regs(void); #ifdef __tilegx__ -void arch_trigger_all_cpu_backtrace(bool self); -#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_TILE_IRQ_H */ diff --git a/arch/tile/kernel/pmc.c b/arch/tile/kernel/pmc.c index db62cc34b955..81cf8743a3f3 100644 --- a/arch/tile/kernel/pmc.c +++ b/arch/tile/kernel/pmc.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -29,9 +28,7 @@ int handle_perf_interrupt(struct pt_regs *regs, int fault) if (!perf_irq) panic("Unexpected PERF_COUNT interrupt %d\n", fault); - nmi_enter(); retval = perf_irq(regs, fault); - nmi_exit(); return retval; } diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index b5f30d376ce1..6594df5fed53 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -593,66 +593,18 @@ void show_regs(struct pt_regs *regs) tile_show_stack(&kbt); } -/* To ensure stack dump on tiles occurs one by one. */ -static DEFINE_SPINLOCK(backtrace_lock); -/* To ensure no backtrace occurs before all of the stack dump are done. */ -static atomic_t backtrace_cpus; -/* The cpu mask to avoid reentrance. */ -static struct cpumask backtrace_mask; - -void do_nmi_dump_stack(struct pt_regs *regs) -{ - int is_idle = is_idle_task(current) && !in_interrupt(); - int cpu; - - nmi_enter(); - cpu = smp_processor_id(); - if (WARN_ON_ONCE(!cpumask_test_and_clear_cpu(cpu, &backtrace_mask))) - goto done; - - spin_lock(&backtrace_lock); - if (is_idle) - pr_info("CPU: %d idle\n", cpu); - else - show_regs(regs); - spin_unlock(&backtrace_lock); - atomic_dec(&backtrace_cpus); -done: - nmi_exit(); -} - #ifdef __tilegx__ -void arch_trigger_all_cpu_backtrace(bool self) +void nmi_raise_cpu_backtrace(struct cpumask *in_mask) { struct cpumask mask; HV_Coord tile; unsigned int timeout; int cpu; - int ongoing; HV_NMI_Info info[NR_CPUS]; - ongoing = atomic_cmpxchg(&backtrace_cpus, 0, num_online_cpus() - 1); - if (ongoing != 0) { - pr_err("Trying to do all-cpu backtrace.\n"); - pr_err("But another all-cpu backtrace is ongoing (%d cpus left)\n", - ongoing); - if (self) { - pr_err("Reporting the stack on this cpu only.\n"); - dump_stack(); - } - return; - } - - cpumask_copy(&mask, cpu_online_mask); - cpumask_clear_cpu(smp_processor_id(), &mask); - cpumask_copy(&backtrace_mask, &mask); - - /* Backtrace for myself first. */ - if (self) - dump_stack(); - /* Tentatively dump stack on remote tiles via NMI. */ timeout = 100; + cpumask_copy(&mask, in_mask); while (!cpumask_empty(&mask) && timeout) { for_each_cpu(cpu, &mask) { tile.x = cpu_x(cpu); @@ -663,12 +615,17 @@ void arch_trigger_all_cpu_backtrace(bool self) } mdelay(10); + touch_softlockup_watchdog(); timeout--; } - /* Warn about cpus stuck in ICS and decrement their counts here. */ + /* Warn about cpus stuck in ICS. */ if (!cpumask_empty(&mask)) { for_each_cpu(cpu, &mask) { + + /* Clear the bit as if nmi_cpu_backtrace() ran. */ + cpumask_clear_cpu(cpu, in_mask); + switch (info[cpu].result) { case HV_NMI_RESULT_FAIL_ICS: pr_warn("Skipping stack dump of cpu %d in ICS at pc %#llx\n", @@ -679,16 +636,19 @@ void arch_trigger_all_cpu_backtrace(bool self) cpu); break; case HV_ENOSYS: - pr_warn("Hypervisor too old to allow remote stack dumps.\n"); - goto skip_for_each; + WARN_ONCE(1, "Hypervisor too old to allow remote stack dumps.\n"); + break; default: /* should not happen */ pr_warn("Skipping stack dump of cpu %d [%d,%#llx]\n", cpu, info[cpu].result, info[cpu].pc); break; } } -skip_for_each: - atomic_sub(cpumask_weight(&mask), &backtrace_cpus); } } + +void arch_trigger_cpumask_backtrace(const cpumask_t *mask) +{ + nmi_trigger_cpumask_backtrace(mask, nmi_raise_cpu_backtrace); +} #endif /* __tilegx_ */ diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c index 4d9651c5b1ad..934a7d88eb29 100644 --- a/arch/tile/kernel/traps.c +++ b/arch/tile/kernel/traps.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -392,14 +394,15 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num, void do_nmi(struct pt_regs *regs, int fault_num, unsigned long reason) { + nmi_enter(); switch (reason) { case TILE_NMI_DUMP_STACK: - do_nmi_dump_stack(regs); + nmi_cpu_backtrace(regs); break; default: panic("Unexpected do_nmi type %ld", reason); - return; } + nmi_exit(); } /* Deprecated function currently only used here. */ -- 2.7.2