From patchwork Sat Jun 3 14:42:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 101324 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp203944qgd; Sat, 3 Jun 2017 07:44:13 -0700 (PDT) X-Received: by 10.99.38.133 with SMTP id m127mr8489612pgm.72.1496501053010; Sat, 03 Jun 2017 07:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496501053; cv=none; d=google.com; s=arc-20160816; b=bDgRFkl95XTJLDT4hCEkWuPRoViNu7OhdSD8t8IVwiQ47qex+5xjL+Q/I/dW0jTYcL 6k7G+6S/dHSnJM0fQpXz5GklPEJuo7AtADdQAXsNChQj4cMMuFVctmtsFiMW/ghpOK8K llXoBYTefO7x1cQANdigiFeckfcfSgB3yLxso3DxhUobEFWpo4AV/7pH1aM8OcbCiLfP w+VwP6l05fOyFbRks9LKX40cTdQV6+TFoYkmrXvz5iUYXTe7yf5VaSca7BlgJqI87jKG 0ZFxfDrCgnqsmmayxxQyPNsVgwYygy+YtA3UzpRGX88/3cVDcB9R/DXpQgoJU1nXZYpx NIYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=crVAaDtTjWepJzg3AXFuKv6aWoT85Qd5rBzItCR15og=; b=0If6f8CDFGAxyPBFPnsWcEMRM7VPxCvqj+pSmc4MiUaUKmBOo6r2mEnud2ZiYofT3M /3A+xmkay/gwDKrDk+JyLkPZv4k0uUPCqlYvrLhqivHQRKiQJ1lVF3qj7+PD6kuydUiy GWAWZMvqPVf8XZBEGeOTYNbVqEClUG0IFEvCXj/d8/iXVq2zse35VqRytlJENTkbCQQN NgoGwmofyL5PvvNRLx6tSqzdnzlhEFFs1aE295sO11v+9i01JzAY6KiwOx9Bc2Ikb2X/ FCzThaqfzzoPveXwc14ghVQ6ORqVhP4LS/Uvo3Z4inOCDGE4aURhmae5l4uZgkHhtqgn 7NIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si2514676plk.369.2017.06.03.07.44.12; Sat, 03 Jun 2017 07:44:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751201AbdFCOnc (ORCPT + 25 others); Sat, 3 Jun 2017 10:43:32 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:33142 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750765AbdFCOna (ORCPT ); Sat, 3 Jun 2017 10:43:30 -0400 Received: by mail-pf0-f174.google.com with SMTP id 83so6368705pfr.0 for ; Sat, 03 Jun 2017 07:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=crVAaDtTjWepJzg3AXFuKv6aWoT85Qd5rBzItCR15og=; b=QS+3GeK9Tfpiu+8rN+Sabu597yo9hIYireNtvrLTY9IKw3mrRrAWMJdzeRAOaQjcMN YUu/Mh35YdzXY/BMKUmrl0jvlOJq/hwqv+DiAYxbZu5jZT10Dv2f5FrHyrq2nVT6/v2/ a4YEYlnTnYVSbSu8KHV8pjEmTkCpoWEZ8lXHo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=crVAaDtTjWepJzg3AXFuKv6aWoT85Qd5rBzItCR15og=; b=Qco+IF3UqBQe1x/WsJ4tN/j8vA2QMOfN2SjaTpTGGcRq+lz6D05WDNY5AXdKh83lJC td7TBI1Jt8z6NQNZcaT+Ldv8vwFfJKEyYz15dpgh8ZERPTCdnkcX0aM/qS5Da8GKHd2C T9I9FHs/SdDWdsB9k3R1Imwb60GGLF/9+lmD/w4pO/n8NjJvAv83NAVV33lSPABtQy2q 81dGzZxS+ZM2jKQtMu7wyBiViudHWfYephjsRD43Ddz3DYZDhnjkrPHaqeJQ+DeQvMbE dHVcYp/Qo/cFjRrc31rZwoAzADT4EKrGlvOWzx97kDif5lVwwX/686erXRTW83VX3KrL hq/Q== X-Gm-Message-State: AODbwcDbpfMHw/InDM5iozTZF/dkAj4+V8vqqYmQF26DuAAYhS/t3Uaw RsQPpUQhZCrHOdXr X-Received: by 10.84.208.102 with SMTP id f35mr2345432plh.92.1496501009401; Sat, 03 Jun 2017 07:43:29 -0700 (PDT) Received: from localhost.localdomain (li1568-49.members.linode.com. [139.162.88.49]) by smtp.gmail.com with ESMTPSA id s68sm43510861pgc.5.2017.06.03.07.43.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 03 Jun 2017 07:43:28 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , Will Deacon , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mike Leach , Chunyan Zhang Cc: Leo Yan Subject: [PATCH v1 1/4] coresight: support panic dump functionality Date: Sat, 3 Jun 2017 22:42:53 +0800 Message-Id: <1496500976-18362-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496500976-18362-1-git-send-email-leo.yan@linaro.org> References: <1496500976-18362-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After kernel panic happens, coresight has many useful info can be used for analysis. For example, the trace info from ETB RAM can be used to check the CPU execution flows before crash. So we can save the tracing data from sink devices, and rely on kdump to extract them from vmcore file. This patch is to add a simple framework to support panic dump functionality; it registers panic notifier, and provide the general APIs {coresight_add_panic_cb|coresight_del_panic_cb} as helper functions so any coresight device can add itself into dump list or delete as needed; usually these two functions can be used when a session is started or when it ends. When kernel panic happened, the panic notifier iterates dump list and calls every node for the device callback function to dump device specific info. Generally all the panic dump specific stuff are related to the sinks devices, so this initial version code it only supports sink devices. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/Kconfig | 10 ++ drivers/hwtracing/coresight/Makefile | 1 + drivers/hwtracing/coresight/coresight-panic-dump.c | 130 +++++++++++++++++++++ drivers/hwtracing/coresight/coresight-priv.h | 10 ++ include/linux/coresight.h | 2 + 5 files changed, 153 insertions(+) create mode 100644 drivers/hwtracing/coresight/coresight-panic-dump.c -- 2.7.4 diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index 8d55d6d..8890023 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -103,4 +103,14 @@ config CORESIGHT_CPU_DEBUG properly, please refer Documentation/trace/coresight-cpu-debug.txt for detailed description and the example for usage. +config CORESIGHT_PANIC_DUMP + bool "CoreSight Panic Dump driver" + depends on ARM || ARM64 + depends on CORESIGHT_LINKS_AND_SINKS + help + This driver provides panic dump functionality for coresight + devices; when kernel panic happens, we can use callback functions + to save trace data to memory. Finally can rely on kdump to extract + out these trace data from kernel dump file. + endif diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index 433d590..0ac3216 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \ obj-$(CONFIG_CORESIGHT_QCOM_REPLICATOR) += coresight-replicator-qcom.o obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o +obj-$(CONFIG_CORESIGHT_PANIC_DUMP) += coresight-panic-dump.o diff --git a/drivers/hwtracing/coresight/coresight-panic-dump.c b/drivers/hwtracing/coresight/coresight-panic-dump.c new file mode 100644 index 0000000..23869ff --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-panic-dump.c @@ -0,0 +1,130 @@ +/* + * Copyright(C) 2017 Linaro Limited. All rights reserved. + * Author: Leo Yan + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_MUTEX(coresight_panic_lock); +static struct list_head coresight_panic_list; +static struct notifier_block coresight_panic_nb; + +struct coresight_panic_node { + char *name; + struct coresight_device *csdev; + struct list_head list; +}; + +static int coresight_panic_notify(struct notifier_block *nb, + unsigned long mode, void *_unused) +{ + int ret = 0, err; + struct coresight_panic_node *node; + struct coresight_device *csdev; + u32 type; + + mutex_lock(&coresight_panic_lock); + + list_for_each_entry(node, &coresight_panic_list, list) { + csdev = node->csdev; + type = csdev->type; + + dev_info(&csdev->dev, "invoke panic dump...\n"); + + switch (type) { + case CORESIGHT_DEV_TYPE_SINK: + case CORESIGHT_DEV_TYPE_LINKSINK: + err = sink_ops(csdev)->panic_cb(csdev); + if (err) + ret = err; + break; + default: + dev_err(&csdev->dev, + "Unsupported type for panic dump\n"); + break; + } + } + + mutex_unlock(&coresight_panic_lock); + return ret; +} + +int coresight_add_panic_cb(struct coresight_device *csdev) +{ + struct coresight_panic_node *node; + + node = kzalloc(sizeof(struct coresight_panic_node), GFP_KERNEL); + if (!node) + return -ENOMEM; + + node->name = kstrndup(dev_name(&csdev->dev), 16, GFP_KERNEL); + if (!node->name) { + kfree(node); + return -ENOMEM; + } + node->csdev = csdev; + + mutex_lock(&coresight_panic_lock); + list_add_tail(&node->list, &coresight_panic_list); + mutex_unlock(&coresight_panic_lock); + + return 0; +} + +void coresight_del_panic_cb(struct coresight_device *csdev) +{ + struct coresight_panic_node *node; + + mutex_lock(&coresight_panic_lock); + + list_for_each_entry(node, &coresight_panic_list, list) { + if (node->csdev == csdev) { + list_del(&node->list); + kfree(node->name); + kfree(node); + mutex_unlock(&coresight_panic_lock); + return; + } + } + + dev_err(&csdev->dev, "Failed to find panic node.\n"); + mutex_unlock(&coresight_panic_lock); +} + +static int __init coresight_panic_init(void) +{ + int ret; + + INIT_LIST_HEAD(&coresight_panic_list); + + coresight_panic_nb.notifier_call = coresight_panic_notify; + ret = atomic_notifier_chain_register(&panic_notifier_list, + &coresight_panic_nb); + if (ret) + return ret; + + return 0; +} +subsys_initcall(coresight_panic_init); diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index 5f662d8..e6ed3e9 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -122,4 +122,14 @@ static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; } static inline int etm_writel_cp14(u32 off, u32 val) { return 0; } #endif +#ifdef CONFIG_CORESIGHT_PANIC_DUMP +extern int coresight_add_panic_cb(struct coresight_device *csdev); +extern void coresight_del_panic_cb(struct coresight_device *csdev); +#else +static inline int coresight_add_panic_cb(struct coresight_device *csdev) +{ return 0; } +static inline void coresight_del_panic_cb(struct coresight_device *csdev) +{ return; } +#endif + #endif diff --git a/include/linux/coresight.h b/include/linux/coresight.h index d950dad..31fcaeb 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -189,6 +189,7 @@ struct coresight_device { * @set_buffer: initialises buffer mechanic before a trace session. * @reset_buffer: finalises buffer mechanic after a trace session. * @update_buffer: update buffer pointers after a trace session. + * @panic_cb: hooks callback function for panic notifier. */ struct coresight_ops_sink { int (*enable)(struct coresight_device *csdev, u32 mode); @@ -205,6 +206,7 @@ struct coresight_ops_sink { void (*update_buffer)(struct coresight_device *csdev, struct perf_output_handle *handle, void *sink_config); + int (*panic_cb)(struct coresight_device *csdev); }; /**