From patchwork Mon Sep 14 13:26:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 53554 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 4E4B322B17 for ; Mon, 14 Sep 2015 13:26:51 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf41307839wic.3 for ; Mon, 14 Sep 2015 06:26:50 -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=1UpRUdIOxv2ypsg2nORfA+6AsUPK0qKsdcW6quoNPXk=; b=CBjP+ih+dZloQfv0WrjkBunE6go+b4AJIOea24ppQTDcpAHpOmmpf60ykFhZLCUi72 3N5npx3nqGuibrsWNrZdA/CFr0ZfpBZnlR5genbhWVBpyh/H0aawhcvNojjF7EJr9Asu 8aK9qs51LxWniw6fowXG+4sdUTjz05bEAcjBZnBpVprYxcSlQQtc03xEgO3yLg+6A/6Z VzoOexv9etTzzqosZZ9KPylZqOxrhuURwb24DfFV1UGMV0OFevkdpF+5A8JOnE9nOzLs ZP2Ul92yJ7Q8B08o7Duf974UqxmiFdOF4b6cj/ENfqN00O+xalMCb9NNcP0qLrX0VeEc 2i6w== X-Gm-Message-State: ALoCoQks6u41wdPlH0xmWrrCozL+WyqMqL9R8sO+8/gEhOwtbBbJ7KYkrEt3w4DbYR5VRUUFnRzo X-Received: by 10.112.144.99 with SMTP id sl3mr3054115lbb.12.1442237210415; Mon, 14 Sep 2015 06:26:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.8.133 with SMTP id dk5ls594468lad.75.gmail; Mon, 14 Sep 2015 06:26:50 -0700 (PDT) X-Received: by 10.152.23.4 with SMTP id i4mr13736388laf.60.1442237210263; Mon, 14 Sep 2015 06:26:50 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id wq7si9705561lbc.105.2015.09.14.06.26.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:26:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbpo4 with SMTP id o4so67485640lbp.2 for ; Mon, 14 Sep 2015 06:26:50 -0700 (PDT) X-Received: by 10.112.146.104 with SMTP id tb8mr11858937lbb.35.1442237210012; Mon, 14 Sep 2015 06:26:50 -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 w3csp1200372lbq; Mon, 14 Sep 2015 06:26:49 -0700 (PDT) X-Received: by 10.180.102.74 with SMTP id fm10mr26972553wib.25.1442237209182; Mon, 14 Sep 2015 06:26:49 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com. [209.85.212.179]) by mx.google.com with ESMTPS id l10si18648230wjr.34.2015.09.14.06.26.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:26:49 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179; Received: by wicgb1 with SMTP id gb1so141857670wic.1 for ; Mon, 14 Sep 2015 06:26:48 -0700 (PDT) X-Received: by 10.180.106.4 with SMTP id gq4mr26774138wib.42.1442237208859; Mon, 14 Sep 2015 06:26:48 -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 ht5sm14415869wib.10.2015.09.14.06.26.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:26:47 -0700 (PDT) From: Daniel Thompson To: linux-arm-kernel@lists.infradead.org Cc: Daniel Thompson , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal , Marc Zyngier , Andrew Thoelke , Dave Martin , Russell King Subject: [RFC PATCH v2 2/7] arm64: Add support for on-demand backtrace of other CPUs Date: Mon, 14 Sep 2015 14:26:16 +0100 Message-Id: <1442237181-17064-3-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442237181-17064-1-git-send-email-daniel.thompson@linaro.org> References: <1442237181-17064-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.171 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 arm64 has no implementation of arch_trigger_all_cpu_backtace. The patch provides one using library code recently added by Russell King for for the majority of the implementation. Currently this is realized using regular irqs but could, in the future, be implemented using NMI-like mechanisms. Note: There is a small (and nasty) change to the generic code to ensure good stack traces. The generic code currently assumes that show_regs() will include a stack trace but arch/arm64 does not do this so we must add extra code here. Ideas on a better approach here would be very welcome (is there any appetite to change arm64 show_regs() or should we just tease out the dump code into a callback?). Signed-off-by: Daniel Thompson Cc: Russell King --- arch/arm64/include/asm/hardirq.h | 2 +- arch/arm64/include/asm/irq.h | 3 +++ arch/arm64/kernel/smp.c | 26 ++++++++++++++++++++++++++ lib/nmi_backtrace.c | 8 ++++++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/hardirq.h b/arch/arm64/include/asm/hardirq.h index 2bb7009bdac7..0af4cdb4b5a9 100644 --- a/arch/arm64/include/asm/hardirq.h +++ b/arch/arm64/include/asm/hardirq.h @@ -20,7 +20,7 @@ #include #include -#define NR_IPI 5 +#define NR_IPI 6 typedef struct { unsigned int __softirq_pending; diff --git a/arch/arm64/include/asm/irq.h b/arch/arm64/include/asm/irq.h index bbb251b14746..6b2724b2a803 100644 --- a/arch/arm64/include/asm/irq.h +++ b/arch/arm64/include/asm/irq.h @@ -21,4 +21,7 @@ static inline void acpi_irq_init(void) } #define acpi_irq_init acpi_irq_init +extern void arch_trigger_all_cpu_backtrace(bool); +#define arch_trigger_all_cpu_backtrace(x) arch_trigger_all_cpu_backtrace(x) + #endif diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index dbdaacddd9a5..0f37a33499e2 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,7 @@ enum ipi_msg_type { IPI_CPU_STOP, IPI_TIMER, IPI_IRQ_WORK, + IPI_CPU_BACKTRACE, }; /* @@ -623,6 +625,7 @@ static const char *ipi_types[NR_IPI] __tracepoint_string = { S(IPI_CPU_STOP, "CPU stop interrupts"), S(IPI_TIMER, "Timer broadcast interrupts"), S(IPI_IRQ_WORK, "IRQ work interrupts"), + S(IPI_CPU_BACKTRACE, "backtrace interrupts"), }; static void smp_cross_call(const struct cpumask *target, unsigned int ipinr) @@ -743,6 +746,12 @@ void handle_IPI(int ipinr, struct pt_regs *regs) break; #endif + case IPI_CPU_BACKTRACE: + irq_enter(); + nmi_cpu_backtrace(regs); + irq_exit(); + break; + default: pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr); break; @@ -794,3 +803,20 @@ int setup_profiling_timer(unsigned int multiplier) { return -EINVAL; } + +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. + */ + if (cpumask_test_cpu(smp_processor_id(), mask) && irqs_disabled()) + nmi_cpu_backtrace(NULL); + + smp_cross_call(mask, IPI_CPU_BACKTRACE); +} + +void arch_trigger_all_cpu_backtrace(bool include_self) +{ + nmi_trigger_all_cpu_backtrace(include_self, raise_nmi); +} diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c index be0466a80d0b..29f7c4585f7f 100644 --- a/lib/nmi_backtrace.c +++ b/lib/nmi_backtrace.c @@ -149,10 +149,14 @@ 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); - if (regs) + if (regs) { show_regs(regs); - else +#ifdef CONFIG_ARM64 + show_stack(NULL, NULL); +#endif + } else { dump_stack(); + } this_cpu_write(printk_func, printk_func_save); cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));