Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753223AbcCVRUT (ORCPT ); Tue, 22 Mar 2016 13:20:19 -0400 Received: from mail-db3on0085.outbound.protection.outlook.com ([157.55.234.85]:25568 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751721AbcCVRUD (ORCPT ); Tue, 22 Mar 2016 13:20:03 -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" , Russell King , Thomas Gleixner , Aaron Tomlin , Ingo Molnar , Andrew Morton , CC: Chris Metcalf Subject: [PATCH v3 3/4] arch/tile: adopt the new nmi_backtrace framework Date: Tue, 22 Mar 2016 13:19:38 -0400 Message-ID: <1458667179-19630-4-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1458667179-19630-1-git-send-email-cmetcalf@mellanox.com> References: <1458667179-19630-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)(1110001)(1109001)(339900001)(199003)(189002)(4001430100002)(5008740100001)(86362001)(189998001)(5001770100001)(50466002)(6806005)(76176999)(11100500001)(48376002)(36756003)(50986999)(104016004)(2950100001)(5001970100001)(92566002)(107886002)(960300001)(1220700001)(1096002)(2906002)(586003)(47776003)(87936001)(19580395003)(85426001)(33646002)(4326007)(19580405001)(105606002)(106466001)(42186005)(229853001)(50226001);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR05MB1691;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AM1FFO11FD055;1:A75ugd9N3KS1TwuvRpmOegHvTHp/ZZ8cvK0dM2FGuaaxhrzTUurXCLiNIt/8eg+pREQGaf1xmixShjyefvfQ91Yr0eWD75uPJAWNHDrxyyh43O8WKn6Rpa9HFEJjgcdENjwhyKpWGP5vKe8mGDbgMZE9YVWs3kqXcDhg6EtTvTIQRqzbv/Mm1EjEoX5Kqe23ZDfr8DL7gsRaGfR/23WFXN8VHuFC7KPHtK2dIZ4vkmsLtXhDwV6Z7Z3KBLs7MBspiYNUM9PsFutZMXlszPpflLsoCkqLVMIVsiBJnKUzUf49qUlLsoSWXyQ4N/oGX8kv/M+O9dydjpxowir/8ydHqSzwaIdzvhIKfi7uiQZixyYQ3IwGU6zOiNjLqt9zeaJEVaePFFQuf3jGVDYBkMAiSs4s6p1I0hYAB5PfFly4z5m+20IWoY1m8U1JHLdQdRXX3NDtYHSIVbMh1cQCYFb8k4Zt5Pzu8vFcCuP+2P1ONCIZ5oNNi3MoMqyShtZH6MTYDHZTE19mHDL2nHZcNxPUYe5L2Dz3Mfm4IYLYpfXDlPedrNM9i3T6cH5Tt70v3guo MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 5cc6b285-0d38-4323-e6b8-08d3527631d7 X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1691;2:/ScGpb8aDl16Ejj4KhDkxYiRlgBwR4k9gHlKQ0aPX52xxlmK0Ks93HZVTX0lNZi374kiEHJtrJUNNh9FPjF8yEK5VA3hqECShXec5U96+h1fhmSswkEm9Zyggo33gGs7Rdqepzqyt73t3yKOcpEobB3DJUa1Lp89cxhojoAT+GIVC4H806j2PYeP0FrEpY8b;3:uLXSkqWbQeebXf/rAHey1xGhalJyORfeddfBmbw3d89muKc7yEeWApgbOQUeN5gNKBQkwymCA+NT9OSunXQxqpJLO4OkTBHaKMus/+gpX+w5Itmxw2/UYlRvVQPbX26I3n6RQEE0yEiT1G0RBC6gOPUe9B4xTbO445G7fD1BB6kYQ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B4lOdXFdkJKv7U2J/NWM3TRlXuSmhWTefaGIfk4rHfBPgv5yXgamSrYKCcRGHS2sJCxXkgRgVQHJjbMrdZpm4T6qQFu02dSNqPEwrvkjJbvoOOCn8hG7Ye5nxZEeYoFdr/NHaNexR3qn6Yr0lhejO5BUpug+9qPv23QpAldJw7amTP5/8os8g9Zd+NH5S9dKlB4HcbNNllj9 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(13023025)(13017025)(5005006)(13018025)(13015025)(13024025)(8121501046)(3002001)(10201501046);SRVR:HE1PR05MB1691;BCL:0;PCL:0;RULEID:;SRVR:HE1PR05MB1691; X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1691;4:v/h3odse8BikrFW1Qu6FGP4kzjj8lZGIsUGZIjZiHbSgPtzcWkEG8+7bDUhsLzyEGUqH0W7u27x2rQDlCtbh5jfiUwq54XYjqdvlmtGHD780r1DzKTDQdrRWHKTaEId3S9l2+mbKERQi1NDpE+n6kF7+4qM2yH16+AdsLb+UiQe5rGcbN7yrVEqrAYucEK49Wo66pm5B/QvxWJq54vfqxyg9IyyE008CrlE4jxR+Y4j30TZA7eCVmIh2rrITVY1WsDnGy42h3a52aBdVA1v+AcsOXwzpI/o/qVBAqfs6mM2h/t/FNGC/Ae9cF7bGSSnUM0h1JkjyHhMSJejYBZ24bPeY+6ixQKQXktVt3fndUNc9n85/1KEzW5mxFaPHfUsHS8jxkkabCBoIfmv3OIluF17rykRYU6WeVBf0UUyTo44IajPzZ3uqQgcaydHcdL7WgMCD/PqetC8EH69s1Nk5IA== X-Forefront-PRVS: 08897B549D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR05MB1691;23:CQzazAp0YosNeTphzAXYxjjlllDYF4X3BJWc/v8gU?= =?us-ascii?Q?LGdVjLNc+v79MNHqPLV5lgQnZPusddsv+wUudKVKcSpRXVMSxf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f5ztqJzLeTBFJ4eFQfNp09P2JS8ctIvYZv6C3uGBO?= =?us-ascii?Q?/iq+d97QtbErnb80V7tbUbRHv259wIi7UPRy/Er8ioWooa8F3L8FV5xbH5Gp?= =?us-ascii?Q?EAn9ZHm0u5x3VQZyNCLyncZInc1eC26o1cZT12A44ZkFlSLwQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1691;5:G+xqEeVVK0X6G2QzkJXYLd3zum9NtDJRj4fi/uGrQOfTIiyGpBBtwMcy8EQtdkKIF0TFUVVO4Cugw0ap5M8qDU5kZ/VpVvHDhS5PQj2G4k81AddYUtMDLSX1H4U17nMcMFOV17f1mCrdr0a7LzFOdg==;24:Hymqj/c0QUG4m9ADi9fM1hXMynXgE0cypaGjdKrGIV7YK4wJ8JhxyVg8hLOQ4THdzDkmkT6yuTWOjJayacSNML9YdsSJNtdIpZPo/NaBZf4= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2016 17:19:58.0855 (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: HE1PR05MB1691 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