From patchwork Tue Sep 15 14:40:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 7186351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5F34D9F32B for ; Tue, 15 Sep 2015 14:42:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E70D2041C for ; Tue, 15 Sep 2015 14:42:30 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9267820608 for ; Tue, 15 Sep 2015 14:42:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZbrPc-0002Kn-So; Tue, 15 Sep 2015 14:40:48 +0000 Received: from mail-wi0-f173.google.com ([209.85.212.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZbrPZ-00025x-L0 for linux-arm-kernel@lists.infradead.org; Tue, 15 Sep 2015 14:40:46 +0000 Received: by wicfx3 with SMTP id fx3so30519726wic.0 for ; Tue, 15 Sep 2015 07:40:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s2UqR/rcGLmi7NSA0r2qH/ocA2ic7wMG7eE0w2qw9/g=; b=B43DhClgvXrSDnDVCl7Sx/H6mf7YvZRP1xqU2oWNYQ5GSlFocCJS9ghBGiFEHj8+xQ tVmKWKFf0d7Df435b42TOYtFXbvzyRAg+ZoIA0q/NFbN4iip5ndSlmfGkSnbfvuLAP+3 f+b3NK0SZR7aTwdDUe3cZrmzB1W7G0HeF532zmoKXYCCY9qggVd5HuerT3eouqmtbCxJ 4w0ckf84mcL3XXTrsKRCF2Nep/352z9BjEC7q2IWu7LZCtGtkmVyixZoX17eLTDqbJTr Xi3fhZ2tBL30k5mS3EjJMWe22CNFgxPxxCRDShjBLxfAVBP3Ja9jqVzOU8drYG2QQos3 7csw== X-Gm-Message-State: ALoCoQlY82cKTtlzuiivWCUHCgt1bs+krsiTUHQD9qcUBlZneB1QShdf4W38Jf/fqU32mSZYgi74 X-Received: by 10.180.87.198 with SMTP id ba6mr8177186wib.39.1442328023852; Tue, 15 Sep 2015 07:40:23 -0700 (PDT) Received: from wychelm.lan (cpc4-aztw19-0-0-cust71.18-1.cable.virginm.net. [82.33.25.72]) by smtp.gmail.com with ESMTPSA id ft3sm20248448wib.17.2015.09.15.07.40.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2015 07:40:23 -0700 (PDT) From: Daniel Thompson To: Russell King Subject: [PATCH v3] arm: Fix backtrace generation when IPI is masked Date: Tue, 15 Sep 2015 15:40:05 +0100 Message-Id: <1442328005-13661-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442222294-2756-1-git-send-email-daniel.thompson@linaro.org> References: <1442222294-2756-1-git-send-email-daniel.thompson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150915_074045_951228_8ACCDB08 X-CRM114-Status: GOOD ( 16.65 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Thompson , linaro-kernel@lists.linaro.org, patches@linaro.org, Hillf Danton , linux-kernel@vger.kernel.org, Thomas Gleixner , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently on ARM when is triggered from an interrupt handler (e.g. a SysRq issued using UART or kbd) the main CPU will wedge for ten seconds with interrupts masked before issuing a backtrace for every CPU except itself. The new backtrace code introduced by commit 96f0e00378d4 ("ARM: add basic support for on-demand backtrace of other CPUs") does not work correctly when run from an interrupt handler because IPI_CPU_BACKTRACE is used to generate the backtrace on all CPUs but cannot preempt the current calling context. This can be fixed by detecting that the calling context cannot be preempted and issuing the backtrace directly in this case. Issuing directly leaves us without any pt_regs to pass to nmi_cpu_backtrace() so we also modify the generic code to call dump_stack() when its argument is NULL. Signed-off-by: Daniel Thompson Acked-by: Hillf Danton Acked-by: Thomas Gleixner --- Notes: Changes in v3: * Added comments to describe how raise_nmi() and nmi_cpu_backtrace() interact with backtrace_mask (Russell King). Changes in v2: * Improved commit message to better describe the changes to the generic code (Hillf Danton). arch/arm/kernel/smp.c | 9 +++++++++ lib/nmi_backtrace.c | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) -- 2.4.3 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 48185a773852..0c4e7fdb9636 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -748,6 +748,15 @@ core_initcall(register_cpufreq_notifier); static void raise_nmi(cpumask_t *mask) { + /* + * Generate the backtrace directly if we are running in a calling + * context that is not preemptible by the backtrace IPI. Note + * that nmi_cpu_backtrace() automatically removes the current cpu + * from mask. + */ + if (cpumask_test_cpu(smp_processor_id(), mask) && irqs_disabled()) + nmi_cpu_backtrace(NULL); + smp_cross_call(mask, IPI_CPU_BACKTRACE); } diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c index 88d3d32e5923..6019c53c669e 100644 --- a/lib/nmi_backtrace.c +++ b/lib/nmi_backtrace.c @@ -43,6 +43,12 @@ static void print_seq_line(struct nmi_seq_buf *s, int start, int end) printk("%.*s", (end - start) + 1, buf); } +/* + * When raise() is called it will be is 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 (*raise)(cpumask_t *mask)) { @@ -149,7 +155,10 @@ bool nmi_cpu_backtrace(struct pt_regs *regs) /* Replace printk to write into the NMI seq */ this_cpu_write(printk_func, nmi_vprintk); pr_warn("NMI backtrace for cpu %d\n", cpu); - show_regs(regs); + if (regs) + show_regs(regs); + else + dump_stack(); this_cpu_write(printk_func, printk_func_save); cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));