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: 53675 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id A104222A0D for ; Tue, 15 Sep 2015 14:40:26 +0000 (UTC) Received: by lanb10 with SMTP id b10sf61724700lan.3 for ; Tue, 15 Sep 2015 07:40:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=s2UqR/rcGLmi7NSA0r2qH/ocA2ic7wMG7eE0w2qw9/g=; b=ZAeodnlAfZ6i5E6hhGrp5J82o5mpw3uQqpNs/cKpwbdPs5AgT0X4recIXjHStAHWbe 0/Uq5ZF5Skxs+zqkqJlfdg+7WMOu2B6wlwPFNWGbvdCZfkleGFESAPwDHMIl8nXxweYa hgyp+F3F/wieeAxJHhlL5+E5q4aQtkZ4gDi3R8frdu7KonoQlGNfQlMGG6pi95+Jw+O8 WPbF+L1kPK0YPB8W8cafYqLoXKDirrOZruRkbUu0uMUEHKIcFzUF0knnYpZI50jWWFsf 9Eopip0nCnrNw+ipbQ2A/HAxrNXWQy4OGt+WmpXy53QcMip9R1ncSgnVPY5TPbSFT5vL mN5Q== X-Gm-Message-State: ALoCoQlKFQrnJWmkWDaTvxGEydyCELxO1+PHpoDeDS5CnNxuCABRjStySctRr6CJ1ABvTC95olP6 X-Received: by 10.180.99.196 with SMTP id es4mr863679wib.1.1442328025615; Tue, 15 Sep 2015 07:40:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.179.8 with SMTP id dc8ls810914lac.12.gmail; Tue, 15 Sep 2015 07:40:25 -0700 (PDT) X-Received: by 10.152.2.135 with SMTP id 7mr9563015lau.62.1442328025452; Tue, 15 Sep 2015 07:40:25 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id an5si14035276lac.166.2015.09.15.07.40.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2015 07:40:25 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbpo4 with SMTP id o4so86668108lbp.2 for ; Tue, 15 Sep 2015 07:40:25 -0700 (PDT) X-Received: by 10.152.170.225 with SMTP id ap1mr12599784lac.72.1442328025260; Tue, 15 Sep 2015 07:40:25 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1845948lbq; Tue, 15 Sep 2015 07:40:24 -0700 (PDT) X-Received: by 10.194.179.137 with SMTP id dg9mr10419938wjc.55.1442328024434; Tue, 15 Sep 2015 07:40:24 -0700 (PDT) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com. [209.85.212.170]) by mx.google.com with ESMTPS id ta5si24859202wic.124.2015.09.15.07.40.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2015 07:40:24 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.170 as permitted sender) client-ip=209.85.212.170; Received: by wicfx3 with SMTP id fx3so32045710wic.1 for ; Tue, 15 Sep 2015 07:40:24 -0700 (PDT) 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 Cc: Daniel Thompson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, Thomas Gleixner , Hillf Danton 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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));