mbox series

[v8,0/7] coresight: enable debug module

Message ID 1493719717-27698-1-git-send-email-leo.yan@linaro.org
Headers show
Series coresight: enable debug module | expand

Message

Leo Yan May 2, 2017, 10:08 a.m. UTC
ARMv8 architecture reference manual (ARM DDI 0487A.k) Chapter H7 "The
Sample-based Profiling Extension" has description for sampling
registers, we can utilize these registers to check program counter
value with combined CPU exception level, secure state, etc. So this is
helpful for CPU lockup bugs, e.g. if one CPU has run into infinite loop
with IRQ disabled; the 'hang' CPU cannot switch context and handle any
interrupt, so it cannot handle SMP call for stack dump, etc.

This patch series is to enable coresight debug module with sample-based
registers and register call back notifier for PCSR register dumping
when panic happens, so we can see below dumping info for panic; and
this patch series has considered the conditions for access permission
for debug registers self, so this can avoid access debug registers when
CPU power domain is off; the driver also try to figure out the CPU is
in secure or non-secure state.

Patch 0001 is to document the dt binding; patch 0002 is to document
boot parameters used in kernel command line and add one detailed
document to describe the Coresight debug module implementation, the
clock and power domain impaction on the driver, some examples for
usage.

Patch 0003 is used to fix the func of_get_coresight_platform_data()
doesn't properly drop the reference to the CPU node pointer; and
patch 0004 is refactor to add new function of_coresight_get_cpu().

Patch 0005 is the driver for CPU debug module.

Patch 0006 in this series are to enable debug unit on 96boards Hikey,
Patch 0007 is to enable debug on 96boards DB410c. Have verified on both
two boards.

We can enable debugging with two methods, adding parameters into kernel
command line for build-in module:
  coresight_cpu_debug.enable=1

Or we can wait the system has booted up to use debugfs nodes to enable
debugging:
  # echo 1 > /sys/kernel/debug/coresight_cpu_debug/enable

As result we can get below log after input command:
echo c > /proc/sysrq-trigger:

ARM external debug module:
CPU[0]:
 EDPRSR:  0000000b (Power:On DLK:Unlock)
 EDPCSR:  [<ffff00000808eb54>] handle_IPI+0xe4/0x150
 EDCIDSR: 00000000
 EDVIDSR: 90000000 (State:Non-secure Mode:EL1/0 Width:64bits VMID:0)
CPU[1]:
 EDPRSR:  0000000b (Power:On DLK:Unlock)
 EDPCSR:  [<ffff0000087a64c0>] debug_notifier_call+0x108/0x288
 EDCIDSR: 00000000
 EDVIDSR: 90000000 (State:Non-secure Mode:EL1/0 Width:64bits VMID:0)

[...]

Changes from v7:
* Fix operator priority bug.
* Minor sequence adjustment for function debug_func_exit().

Changes from v6:
* According to Suzuki and Mathieu suggestions, refined debug module
  driver to install panic notifier when insmod module; refined function
  debug_force_cpu_powered_up() for CPU power state checking; some minor
  fixing for output log, adding comments for memory barrier, code
  alignment.

Changes from v5:
* According to Suzuki and Mathieu suggestions, refined debug module
  driver to drop unused structure members, refactored initialization
  code to distinguish hardware implementation features, refactored
  flow for forcing CPU powered up, supported pm_runtime operations.
* Added one new doc file: Documentation/trace/coresight-cpu-debug.txt,
  which is used to describe detailed info for implementation, clock
  and power domain impaction on debug module, and exmaples for common
  usage.
* Removed "idle constraints" from debug driver.

Changes from v4:
* This version is mainly credit to ARM colleagues many contribution
  ideas for better quality (Thanks a lot Suzuki, Mike and Sudeep!).
* According to Suzuki suggestion, refined debug module driver to avoid
  memory leak for drvdata struct, handle PCSAMPLE_MODE=1, use flag
  drvdata.pc_has_offset to indicate if PCSR has offset, minor fixes.
* According to Mathieu suggestion, refined dt binding description.
* Changed driver to support module mode;
* According to Mike suggestion and very appreciate the pseudo code,
  added support to force CPU powered up with register EDPRCR;
* According to discussions, added command line and debugfs nodes to
  support enabling debugging for boot time, or later can dynamically
  enable/disable debugging by debugfs.
* According to Rob Herring suggestion, one minor fixes in DT binding.
* According to Stephen Boyd suggestion, add const quality to structure
  device_node. And used use of_cpu_device_node_get() to replace
  of_get_cpu_node() in patch 0003.

Changes from v3:
* Added Suzuki K Poulose's patch to fix issue for the func
  of_get_coresight_platform_data() doesn't properly drop the reference
  to the CPU node pointer.
* According to Suzuki suggestion, added code to handl the corner case
  for ARMv8 CPU with aarch32 mode.
* According to Suzuki suggestion, changed compatible string to
  "arm,coresight-cpu-debug".
* According to Mathieu suggestion, added "power-domains" as optional
  properties.

Changes from v2:
* According to Mathieu Poirier suggestion, applied some minor fixes.
* Added two extra patches for enabling debug module on Hikey.

Changes from v1:
* According to Mike Leach suggestion, removed the binding for debug
  module clocks which have been directly provided by CPU clocks.
* According to Mathieu Poirier suggestion, added function
  of_coresight_get_cpu() and some minor refactors for debug module
  driver.

Changes from RFC:
* According to Mike Leach suggestion, added check for EDPRSR to avoid
  lockup; added supporting EDVIDSR and EDCIDSR registers.
* According to Mark Rutland and Mathieu Poirier suggestion, rewrote
  the documentation for DT binding.
* According to Mark and Mathieu suggestion, refined debug driver.


Leo Yan (6):
  coresight: bindings for CPU debug module
  doc: Add documentation for Coresight CPU debug
  coresight: refactor with function of_coresight_get_cpu
  coresight: add support for CPU debug module
  arm64: dts: hi6220: register debug module
  arm64: dts: qcom: msm8916: Add debug unit

Suzuki K Poulose (1):
  coresight: of_get_coresight_platform_data: Add missing of_node_put

 Documentation/admin-guide/kernel-parameters.txt    |   7 +
 .../bindings/arm/coresight-cpu-debug.txt           |  49 ++
 Documentation/trace/coresight-cpu-debug.txt        | 174 ++++++
 arch/arm64/boot/dts/hisilicon/hi6220.dtsi          |  64 ++
 arch/arm64/boot/dts/qcom/msm8916.dtsi              |  32 +
 drivers/hwtracing/coresight/Kconfig                |  14 +
 drivers/hwtracing/coresight/Makefile               |   1 +
 drivers/hwtracing/coresight/coresight-cpu-debug.c  | 670 +++++++++++++++++++++
 drivers/hwtracing/coresight/of_coresight.c         |  40 +-
 include/linux/coresight.h                          |   2 +
 10 files changed, 1041 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/coresight-cpu-debug.txt
 create mode 100644 Documentation/trace/coresight-cpu-debug.txt
 create mode 100644 drivers/hwtracing/coresight/coresight-cpu-debug.c

-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Sudeep Holla May 5, 2017, 1:55 p.m. UTC | #1
On 02/05/17 11:08, Leo Yan wrote:
> Coresight includes debug module and usually the module connects with CPU

> debug logic. ARMv8 architecture reference manual (ARM DDI 0487A.k) has

> description for related info in "Part H: External Debug".

> 

> Chapter H7 "The Sample-based Profiling Extension" introduces several

> sampling registers, e.g. we can check program counter value with

> combined CPU exception level, secure state, etc. So this is helpful for

> analysis CPU lockup scenarios, e.g. if one CPU has run into infinite

> loop with IRQ disabled. In this case the CPU cannot switch context and

> handle any interrupt (including IPIs), as the result it cannot handle

> SMP call for stack dump.

> 

> This patch is to enable coresight debug module, so firstly this driver

> is to bind apb clock for debug module and this is to ensure the debug

> module can be accessed from program or external debugger. And the driver

> uses sample-based registers for debug purpose, e.g. when system triggers

> panic, the driver will dump program counter and combined context

> registers (EDCIDSR, EDVIDSR); by parsing context registers so can

> quickly get to know CPU secure state, exception level, etc.

> 

> Some of the debug module registers are located in CPU power domain, so

> this requires the CPU power domain stays on when access related debug

> registers, but the power management for CPU power domain is quite

> dependent on SoC integration for power management. For the platforms

> which with sane power controller implementations, this driver follows

> the method to set EDPRCR to try to pull the CPU out of low power state

> and then set 'no power down request' bit so the CPU has no chance to

> lose power.

> 

> If the SoC has not followed up this design well for power management

> controller, the user should use the command line parameter or sysfs

> to constrain all or partial idle states to ensure the CPU power

> domain is enabled and access coresight CPU debug component safely.

> 

> Signed-off-by: Leo Yan <leo.yan@linaro.org>

> ---

>  drivers/hwtracing/coresight/Kconfig               |  14 +

>  drivers/hwtracing/coresight/Makefile              |   1 +

>  drivers/hwtracing/coresight/coresight-cpu-debug.c | 670 ++++++++++++++++++++++

>  3 files changed, 685 insertions(+)

>  create mode 100644 drivers/hwtracing/coresight/coresight-cpu-debug.c

> 

> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig

> index 130cb21..8d55d6d 100644

> --- a/drivers/hwtracing/coresight/Kconfig

> +++ b/drivers/hwtracing/coresight/Kconfig

> @@ -89,4 +89,18 @@ config CORESIGHT_STM

>  	  logging useful software events or data coming from various entities

>  	  in the system, possibly running different OSs

>  

> +config CORESIGHT_CPU_DEBUG

> +	tristate "CoreSight CPU Debug driver"

> +	depends on ARM || ARM64

> +	depends on DEBUG_FS

> +	help

> +	  This driver provides support for coresight debugging module. This

> +	  is primarily used to dump sample-based profiling registers when

> +	  system triggers panic, the driver will parse context registers so

> +	  can quickly get to know program counter (PC), secure state,

> +	  exception level, etc. Before use debugging functionality, platform

> +	  needs to ensure the clock domain and power domain are enabled

> +	  properly, please refer Documentation/trace/coresight-cpu-debug.txt

> +	  for detailed description and the example for usage.

> +

>  endif

> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile

> index af480d9..433d590 100644

> --- a/drivers/hwtracing/coresight/Makefile

> +++ b/drivers/hwtracing/coresight/Makefile

> @@ -16,3 +16,4 @@ obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \

>  					coresight-etm4x-sysfs.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

> diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c

> new file mode 100644

> index 0000000..b77456d

> --- /dev/null

> +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c


[...]

> +static int debug_probe(struct amba_device *adev, const struct amba_id *id)

> +{

> +	void __iomem *base;

> +	struct device *dev = &adev->dev;

> +	struct debug_drvdata *drvdata;

> +	struct resource *res = &adev->res;

> +	struct device_node *np = adev->dev.of_node;

> +	int ret;

> +

> +	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);

> +	if (!drvdata)

> +		return -ENOMEM;

> +

> +	drvdata->cpu = np ? of_coresight_get_cpu(np) : 0;

> +	if (per_cpu(debug_drvdata, drvdata->cpu)) {

> +		dev_err(dev, "CPU%d drvdata has been initialized, "

> +			"may be caused by binding wrong CPU node in the DT\n",

> +			drvdata->cpu);

> +		return -EBUSY;

> +	}

> +

> +	drvdata->dev = &adev->dev;

> +	amba_set_drvdata(adev, drvdata);

> +

> +	/* Validity for the resource is already checked by the AMBA core */

> +	base = devm_ioremap_resource(dev, res);

> +	if (IS_ERR(base))

> +		return PTR_ERR(base);

> +

> +	drvdata->base = base;

> +

> +	get_online_cpus();

> +	per_cpu(debug_drvdata, drvdata->cpu) = drvdata;

> +	ret = smp_call_function_single(drvdata->cpu, debug_init_arch_data,

> +				       drvdata, 1);

> +	put_online_cpus();

> +

> +	if (ret) {

> +		dev_err(dev, "CPU%d debug arch init failed\n", drvdata->cpu);

> +		goto err;

> +	}

> +

> +	if (!drvdata->edpcsr_present) {

> +		dev_err(dev, "CPU%d sample-based profiling isn't implemented\n",

> +			drvdata->cpu);

> +		ret = -ENXIO;

> +		goto err;

> +	}

> +

> +	if (!debug_count++) {

> +		ret = debug_func_init();

> +		if (ret)

> +			goto err_func_init;

> +	}

> +

> +	mutex_lock(&debug_lock);

> +	if (!debug_enable)

> +		pm_runtime_put(dev);

> +	mutex_unlock(&debug_lock);

> +


Just curious as why this is not registered under coresight bus using
coresight_register ? It would be good to group all the coresight devices
under that bus if possible.

--
Regards,
Sudeep
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sudeep Holla May 5, 2017, 3:04 p.m. UTC | #2
On 05/05/17 15:48, Mathieu Poirier wrote:
> On Fri, May 05, 2017 at 02:55:17PM +0100, Sudeep Holla wrote:


[...]

>>

>> Just curious as why this is not registered under coresight bus using

>> coresight_register ? It would be good to group all the coresight devices

>> under that bus if possible.

> 

> The only thing this driver has in common with the coresight framework is the

> name, everything else is completely different.  Coupling them together (because

> of the name) would introduce a lot of hacks and make the code unintelligible. 

> 


I guessed so from the quick glance at it as it needs descriptors with
notion of source, sink and links to register. However I felt odd to not
group under the same "coresight" bus. As someone with least knowledge
on coresight, I would check under "sys/bus/coresight" to check available
devices on the system.

Anyways that's just my thoughts though I agree with you. It may need
more refactoring to support that and it will look hackish if we try to
do that with the code as it stands.

-- 
Regards,
Sudeep
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html