Skip to contentSkip to conversation

Coresight for Kernel panic and watchdog reset

PATCH In review Linu Cherian 5 participants 26 messages Sep 29, 2023 – Nov 9, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Coresight for Kernel panic and watchdog reset

This patch series is rebased on v6.6-rc3 and is dependent on the below two patches.
- coresight: tmc: Make etr buffer mode user configurable from sysfs[1]
- coresight: Fix run time warnings while reusing ETR buffer[2]

Changelog from RFC v3:
* Converted the Coresight ETM driver change to a named configuration. RFC tag has been removed with this change.
* Fixed yaml issues reported by "make dt_binding_check"
* Added names for reserved memory regions 0 and 1
* Added prevalidation checks for metadata processing
* Fixed a regression introduced in RFC v3
- TMC Status register was getting saved wrongly
* Reverted memremap attribute changes from _WB to _WC to match with the dma map attributes
* Introduced reserved buffer mode specific .sync op.
This fixes a possible crash when reserved buffer mode was used in normal trace capture, due to unwanted dma maintenance operations.

RFC V3 is posted here:
https://lore.kernel.org/linux-arm-kernel/[email protected]/T/

Using Coresight for Kernel panic and Watchdog reset
===================================================
This patch series is about extending Linux coresight driver support to address kernel panic and watchdog reset scenarios. This would help coresight users to debug kernel panic and watchdog reset using coresight trace data.

Coresight trace capture: Kernel panic
-------------------------------------
From the coresight driver point of view, addressing the kernel panic situation has four main requirements.

a. Support for allocation of trace buffer pages from reserved memory area.
Platform can advertise this using a new device tree property added to relevant coresight nodes.

b. Support for stopping coresight blocks at the time of panic

c. Saving required metadata in the specified format

d. Support for reading trace data captured at the time of panic

Allocation of trace buffer pages from reserved RAM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A new optional device tree property "memory-region" is added to the ETR/ETF device nodes, that would give the base address and size of trace buffer.

Static allocation of trace buffers would ensure that both IOMMU enabled and disabled cases are handled. Also, platforms that support persistent RAM will allow users to read trace data in the subsequent boot without booting the crashdump kernel.

Note:
For ETR sink devices, this reserved region will be used for both trace capture and trace data retrieval.
For ETF sink devices, internal SRAM would be used for trace capture, and they would be synced to reserved region for retrieval.

Note: Patches 1 & 2 adds support for this.

Disabling coresight blocks at the time of panic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In order to avoid the situation of losing relevant trace data after a kernel panic, it would be desirable to stop the coresight blocks at the time of panic.

This can be achieved by configuring the comparator, CTI and sink devices as below,

Comparator(triggers on kernel panic) --->External out --->CTI --

								|	
		 ETR/ETF stop <------External In <--------------

Note:

* Patch 6 provides the necessary ETR configuration.
* Patch 7 provides the necessary ETM configuration.

Saving metadata at the time of kernel panic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Coresight metadata involves all additional data that are required for a successful trace decode in addition to the trace data. This involves ETR/ETF, ETE register snapshot etc.

A new optional device property "memory-region" is added to the ETR/ETF/ETE device nodes for this.

Note: Patches 3 & 4 adds support for this.

Reading trace data captured at the time of panic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Trace data captured at the time of panic, can be read from rebooted kernel or from crashdump kernel using the below mentioned interface.

Note: Patch 5 adds support for this.

Steps for reading trace data captured in previous boot
++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. cd /sys/bus/coresight/devices/tmc_etrXX/

2. Change to special mode called, read_prevboot.

#echo 1 > read_prevboot

3. Dump trace buffer data to a file,

#dd if=/dev/tmc_etrXX of=~/cstrace.bin

4. Reset back to normal mode

#echo 0 > read_prevboot

General flow of trace capture and decode incase of kernel panic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Enable source and sink on all the cores using the sysfs interface. ETR sink will have trace buffers allocated from reserved memory, by selecting "resrv" buffer mode from sysfs.

2. Run relevant tests.

3. On a kernel panic, all coresight blocks are disabled, necessary metadata is synced by kernel panic handler.

System would eventually reboot or boot a crashdump kernel.

4. For platforms that supports crashdump kernel, raw trace data can be dumped using the coresight sysfs interface from the crashdump kernel itself. Persistent RAM is not a requirement in this case.

5. For platforms that supports persistent RAM, trace data can be dumped using the coresight sysfs interface in the subsequent Linux boot. Crashdump kernel is not a requirement in this case. Persistent RAM ensures that trace data is intact across reboot.

Coresight trace capture: Watchdog reset
---------------------------------------
The main difference between addressing the watchdog reset and kernel panic case are below,

a. Saving coresight metadata need to be taken care by the
SCP(system control processor) firmware in the specified format, instead of kernel.

b. Reserved memory region given by firmware for trace buffer and metadata
has to be in persistent RAM.
Note: This is a requirement for watchdog reset case but optional in kernel panic case.

Watchdog reset can be supported only on platforms that meet the above two requirements.

Testing Kernel panic on Linux 6.6
---------------------------------
1. Enable the preloaded ETM configuration

#mount -t configfs configs /config
#panic_addr=cat /proc/kallsyms | grep "\<panic\>" | awk '{print $1}' #cd /config/cs-syscfg/features/gen_etrig/params
#echo "0x$panic_addr" > address/value
#echo 1 > /config/cs-syscfg/configurations/panicstop/enable

2. Configure CTI using sysfs interface

#./cti_setup.sh

#cat cti_setup.sh

cd /sys/bus/coresight/devices/

  ap_cti_config () {
    #ETM trig out[0] trigger to Channel 0
    echo 0 4 > channels/trigin_attach
  }

  etf_cti_config () {
    #ETF Flush in trigger from Channel 0
    echo 0 1 > channels/trigout_attach
    echo 1 > channels/trig_filter_enable
  }

  etr_cti_config () {
    #ETR Flush in from Channel 0 
    echo 0 1 > channels/trigout_attach
    echo 1 > channels/trig_filter_enable
  }

ctidevs=find . -name "cti*"

for i in $ctidevs
do
cd $i

connection=find . -name "ete*"
if [ ! -z "$connection" ]
then
echo "AP CTI config for $i"
ap_cti_config
fi

connection=find . -name "tmc_etf*"
if [ ! -z "$connection" ]
then
echo "ETF CTI config for $i"
etf_cti_config
fi

connection=find . -name "tmc_etr*"
if [ ! -z "$connection" ]
then
echo "ETR CTI config for $i"
etr_cti_config
fi

cd ..
done

Note: CTI connections are SOC specific and hence the above script is added just for reference.

3. Choose reserved buffer mode for ETR buffer
#echo "resrv" > /sys/bus/coresight/devices/tmc_etr0/buf_mode_preferred

4. Start Coresight tracing on cores 1 and 2 using sysfs interface

5. Run some application on core 1
#taskset -c 1 dd if=/dev/urandom of=/dev/null &

6. Invoke kernel panic on core 2
#echo 1 > /proc/sys/kernel/panic
#taskset -c 2 echo c > /proc/sysrq-trigger

7. From rebooted kernel, enable previous boot mode

#echo 1 > /sys/bus/coresight/devices/tmc_etr0/read_prevboot

8. Read trace data
#dd if=/dev/tmc_etr0 of=/trace/cstrace.bin

9. Run opencsd decoder tools/scripts to generate the instruction trace.

Sample Core 1 instruction trace dump:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	A                                  etm4_enable_hw: ffff800008ae1dd4
	CONTEXT EL2                        etm4_enable_hw: ffff800008ae1dd4
	I                                  etm4_enable_hw: ffff800008ae1dd4:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1dd8:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1ddc:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1de0:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1de4:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1de8:
	d503233f   paciasp
	I                                  etm4_enable_hw: ffff800008ae1dec:
	a9be7bfd   stp     x29, x30, [sp, #-32]!
	I                                  etm4_enable_hw: ffff800008ae1df0:
	910003fd   mov     x29, sp
	I                                  etm4_enable_hw: ffff800008ae1df4:
	a90153f3   stp     x19, x20, [sp, #16]
	I                                  etm4_enable_hw: ffff800008ae1df8:
	2a0003f4   mov     w20, w0
	I                                  etm4_enable_hw: ffff800008ae1dfc:
	900085b3   adrp    x19, ffff800009b95000 <reserved_mem+0xc48>
	I                                  etm4_enable_hw: ffff800008ae1e00:
	910f4273   add     x19, x19, #0x3d0
	I                                  etm4_enable_hw: ffff800008ae1e04:
	f8747a60   ldr     x0, [x19, x20, lsl #3]
	E                                  etm4_enable_hw: ffff800008ae1e08:
	b4000140   cbz     x0, ffff800008ae1e30 <etm4_starting_cpu+0x50>
	I    149.039572921                 etm4_enable_hw: ffff800008ae1e30:
	a94153f3   ldp     x19, x20, [sp, #16]
	I    149.039572921                 etm4_enable_hw: ffff800008ae1e34:
	52800000   mov     w0, #0x0                        // #0
	I    149.039572921                 etm4_enable_hw: ffff800008ae1e38:
	a8c27bfd   ldp     x29, x30, [sp], #32

	..snip

	    149.052324811           chacha_block_generic: ffff800008642d80:
	9100a3e0   add     x0,
	I    149.052324811           chacha_block_generic: ffff800008642d84:
	b86178a2   ldr     w2, [x5, x1, lsl #2]
	I    149.052324811           chacha_block_generic: ffff800008642d88:
	8b010803   add     x3, x0, x1, lsl #2
	I    149.052324811           chacha_block_generic: ffff800008642d8c:
	b85fc063   ldur    w3, [x3, #-4]
	I    149.052324811           chacha_block_generic: ffff800008642d90:
	0b030042   add     w2, w2, w3
	I    149.052324811           chacha_block_generic: ffff800008642d94:
	b8217882   str     w2, [x4, x1, lsl #2]
	I    149.052324811           chacha_block_generic: ffff800008642d98:
	91000421   add     x1, x1, #0x1
	I    149.052324811           chacha_block_generic: ffff800008642d9c:
	f100443f   cmp     x1, #0x11

Sample Core 2 instruction trace dump(kernel panic triggered core):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	A                                  etm4_enable_hw: ffff800008ae1dd4
	CONTEXT EL2                        etm4_enable_hw: ffff800008ae1dd4
	I                                  etm4_enable_hw: ffff800008ae1dd4:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1dd8:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1ddc:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1de0:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1de4:
	d503201f   nop
	I                                  etm4_enable_hw: ffff800008ae1de8:
	d503233f   paciasp
	I                                  etm4_enable_hw: ffff800008ae1dec:
	a9be7bfd   stp     x29, x30, [sp, #-32]!
	I                                  etm4_enable_hw: ffff800008ae1df0:
	910003fd   mov     x29, sp
	I                                  etm4_enable_hw: ffff800008ae1df4:
	a90153f3   stp     x19, x20, [sp, #16]
	I                                  etm4_enable_hw: ffff800008ae1df8:
	2a0003f4   mov     w20, w0
	I                                  etm4_enable_hw: ffff800008ae1dfc:
	900085b3   adrp    x19, ffff800009b95000 <reserved_mem+0xc48>
	I                                  etm4_enable_hw: ffff800008ae1e00:
	910f4273   add     x19, x19, #0x3d0
	I                                  etm4_enable_hw: ffff800008ae1e04:
	f8747a60   ldr     x0, [x19, x20, lsl #3]
	E                                  etm4_enable_hw: ffff800008ae1e08:
	b4000140   cbz     x0, ffff800008ae1e30 <etm4_starting_cpu+0x50>
	I    149.046243445                 etm4_enable_hw: ffff800008ae1e30:
	a94153f3   ldp     x19, x20, [sp, #16]
	I    149.046243445                 etm4_enable_hw: ffff800008ae1e34:
	52800000   mov     w0, #0x0                        // #0
	I    149.046243445                 etm4_enable_hw: ffff800008ae1e38:
	a8c27bfd   ldp     x29, x30, [sp], #32
	I    149.046243445                 etm4_enable_hw: ffff800008ae1e3c:
	d50323bf   autiasp
	E    149.046243445                 etm4_enable_hw: ffff800008ae1e40:
	d65f03c0   ret
	A                                ete_sysreg_write: ffff800008adfa18

	..snip

	I     149.05422547                          panic: ffff800008096300:
	a90363f7   stp     x23, x24, [sp, #48]
	I     149.05422547                          panic: ffff800008096304:
	6b00003f   cmp     w1, w0
	I     149.05422547                          panic: ffff800008096308:
	3a411804   ccmn    w0, #0x1, #0x4, ne  // ne = any
	N     149.05422547                          panic: ffff80000809630c:
	540001e0   b.eq    ffff800008096348 <panic+0xe0>  // b.none
	I     149.05422547                          panic: ffff800008096310:
	f90023f9   str     x25, [sp, #64]
	E     149.05422547                          panic: ffff800008096314:
	97fe44ef   bl      ffff8000080276d0 <panic_smp_self_stop>
	A                                           panic: ffff80000809634c
	I     149.05422547                          panic: ffff80000809634c:
	910102d5   add     x21, x22, #0x40
	I     149.05422547                          panic: ffff800008096350:
	52800020   mov     w0, #0x1                        // #1
	E     149.05422547                          panic: ffff800008096354:
	94166b8b   bl      ffff800008631180 <bust_spinlocks>
	N    149.054225518                 bust_spinlocks: ffff800008631180:
	340000c0   cbz     w0, ffff800008631198 <bust_spinlocks+0x18>
	I    149.054225518                 bust_spinlocks: ffff800008631184:
	f000a321   adrp    x1, ffff800009a98000 <pbufs.0+0xbb8>
	I    149.054225518                 bust_spinlocks: ffff800008631188:
	b9405c20   ldr     w0, [x1, #92]
	I    149.054225518                 bust_spinlocks: ffff80000863118c:
	11000400   add     w0, w0, #0x1
	I    149.054225518                 bust_spinlocks: ffff800008631190:
	b9005c20   str     w0, [x1, #92]
	E    149.054225518                 bust_spinlocks: ffff800008631194:
	d65f03c0   ret
	A                                           panic: ffff800008096358

TODO
----
* Explore changing CTI sysfs script to system configuration manager profile
* Reading tracedata from crashdump kernel is not tested.
* Perf based trace capture and decode is not tested.

Links:
1. https://lore.kernel.org/linux-arm-kernel/[email protected]/
2. https://lore.kernel.org/linux-arm-kernel/[email protected]/T/

Linu Cherian (7):
dt-bindings: arm: coresight-tmc: Add "memory-region" property
coresight: tmc-etr: Add support to use reserved trace memory
coresight: core: Add provision for panic callbacks
coresight: tmc: Enable panic sync handling
coresight: tmc: Add support for reading tracedata from previous boot
coresight: tmc: Stop trace capture on FlIn
coresight: config: Add preloaded configuration

 .../bindings/arm/arm,coresight-tmc.yaml       |  19 ++
 drivers/hwtracing/coresight/Makefile          |   2 +-
 .../coresight/coresight-cfg-preload.c         |   2 +
 .../coresight/coresight-cfg-preload.h         |   2 +
 .../hwtracing/coresight/coresight-cfg-pstop.c |  83 +++++
 drivers/hwtracing/coresight/coresight-core.c  |  32 ++
 .../coresight/coresight-etm4x-core.c          |   1 +
 .../hwtracing/coresight/coresight-tmc-core.c  | 158 +++++++++-
 .../hwtracing/coresight/coresight-tmc-etf.c   | 126 +++++++-
 .../hwtracing/coresight/coresight-tmc-etr.c   | 292 +++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   |  50 +++
 include/linux/coresight.h                     |  25 ++
 12 files changed, 786 insertions(+), 6 deletions(-)
 create mode 100644 drivers/hwtracing/coresight/coresight-cfg-pstop.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/7 dt-bindings: arm: coresight-tmc: Add "memory-region" property

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

---
 .../bindings/arm/arm,coresight-tmc.yaml       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +19 -0
index cb8dceaca70e..45ca4d02d73e 100644
@@ -101,6 +101,22 @@ properties:
           and ETF configurations.
         $ref: /schemas/graph.yaml#/properties/port
 
+  memory-region:
+    items:
+      - description: Reserved trace buffer memory for ETR and ETF sinks.
+          For ETR, this reserved memory region is used for trace data capture.
+          Same region is used for trace data retention as well after a panic
+          or watchdog reset.
+          For ETF, this reserved memory region is used for retention of trace
+          data synced from internal SRAM after a panic or watchdog reset.
+
+      - description: Reserved meta data memory. Used for ETR and ETF sinks.
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem
+
 required:
   - compatible
   - reg
@@ -115,6 +131,9 @@ examples:
     etr@20070000 {
         compatible = "arm,coresight-tmc", "arm,primecell";
         reg = <0x20070000 0x1000>;
+        memory-region = <&etr_trace_mem_reserved>,
+                       <&etr_mdata_mem_reserved>;
+        memory-region-names = "trace-mem", "metadata-mem";
 
         clocks = <&oscclk6a>;
         clock-names = "apb_pclk";
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Quoted 10 lines · Linu Cherian

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

Quoted 8 lines

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

---

Where is the changelog? This is supposed to be v4 or something later. Please, keep proper versioning and changelog.

Quoted 16 lines
 .../bindings/arm/arm,coresight-tmc.yaml       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +5 -0
index cb8dceaca70e..45ca4d02d73e 100644
@@ -101,6 +101,22 @@ properties:
           and ETF configurations.
         $ref: /schemas/graph.yaml#/properties/port
 
+  memory-region:
+    items:
+      - description: Reserved trace buffer memory for ETR and ETF sinks.
+          For ETR, this reserved memory region is used for trace data capture.
+          Same region is used for trace data retention as well after a panic

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 118

Quoted 10 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +10 -0
+          or watchdog reset.
+          For ETF, this reserved memory region is used for retention of trace
+          data synced from internal SRAM after a panic or watchdog reset.
+
+      - description: Reserved meta data memory. Used for ETR and ETF sinks.
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem

Drop the 'mem' suffixes.

Best regards,
Krzysztof

#3 lore raw

RE: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Hi Krzysztof,

Quoted 33 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Saturday, September 30, 2023 8:59 PM
To: Linu Cherian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

External Email

----------------------------------------------------------------------

Quoted 16 lines · Linu Cherian

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

Quoted 5 lines
Quoted 2 lines

---

Where is the changelog? This is supposed to be v4 or something later. Please, keep proper versioning and changelog.

Sure, will add the changelog from next version onwards.

Yeah, the last version was RFC v3 and the RFC tag has been dropped from this version onwards. Hence started this version with V1.

Quoted 23 lines

Review

Quoted 5 lines
 .../bindings/arm/arm,coresight-tmc.yaml       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
(quoted diff) +0 -0

tmc.yaml b/Documentation/devicetree/bindings/arm/arm,coresight- tmc.yaml

Quoted 16 lines

index cb8dceaca70e..45ca4d02d73e 100644

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +9 -0
@@ -101,6 +101,22 @@ properties:
           and ETF configurations.
         $ref: /schemas/graph.yaml#/properties/port
 
+  memory-region:
+    items:
+      - description: Reserved trace buffer memory for ETR and ETF sinks.
+          For ETR, this reserved memory region is used for trace data capture.
+          Same region is used for trace data retention as well after a panic
+          or watchdog reset.
+          For ETF, this reserved memory region is used for retention of trace
+          data synced from internal SRAM after a panic or watchdog reset.
+
Quoted 9 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 118

Quoted 6 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +6 -0
+      - description: Reserved meta data memory. Used for ETR and ETF sinks.
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem

Drop the 'mem' suffixes.

Ack. Will remove it in next version.

#4 lore raw

Re: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Quoted 38 lines · Linu Cherian

Hi Krzysztof,

Quoted 36 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Saturday, September 30, 2023 8:59 PM
To: Linu Cherian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

External Email

----------------------------------------------------------------------

Quoted 18 lines · Linu Cherian

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

---

Quoted 7 lines
Quoted 2 lines

Where is the changelog? This is supposed to be v4 or something later. Please, keep proper versioning and changelog.

Sure, will add the changelog from next version onwards.

Yeah, the last version was RFC v3 and the RFC tag has been dropped from this version onwards. Hence started this version with V1.

v1 says it is the first version, but you already had three others. Please keep continuous version log, regardless whether you call it RFC or RFT or RFsomething.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

 .../bindings/arm/arm,coresight-tmc.yaml       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Best regards,
Krzysztof

#5 lore raw

RE: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Hi Krzysztof,

Quoted 57 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Tuesday, October 3, 2023 12:02 PM
To: Linu Cherian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: Re: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Quoted 43 lines · Linu Cherian

Hi Krzysztof,

Quoted 33 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Saturday, September 30, 2023 8:59 PM
To: Linu Cherian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

External Email

---------------------------------------------------------------------

Quoted 16 lines · Linu Cherian

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

Quoted 5 lines
Quoted 2 lines

---

Where is the changelog? This is supposed to be v4 or something later. Please, keep proper versioning and changelog.

Sure, will add the changelog from next version onwards.

Quoted 7 lines
Quoted 1 line

Yeah, the last version was RFC v3 and the RFC tag has been dropped from

this version onwards.

Quoted 1 line

Hence started this version with V1.

v1 says it is the first version, but you already had three others. Please keep continuous version log, regardless whether you call it RFC or RFT or RFsomething.

Okay. Will continue with Patch V5 from next series and add necessary notes in cover letter.

Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines


 .../bindings/arm/arm,coresight-tmc.yaml       | 19

+++++++++++++++++++

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
 1 file changed, 19 insertions(+)

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

In reply to Linu Cherian

Hi Linu

Quoted 29 lines · Linu Cherian

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

---
 .../bindings/arm/arm,coresight-tmc.yaml       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +0 -0
index cb8dceaca70e..45ca4d02d73e 100644
@@ -101,6 +101,22 @@ properties:
           and ETF configurations.
         $ref: /schemas/graph.yaml#/properties/port

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 112

Quoted 10 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +9 -0
 
+  memory-region:
+    items:
+      - description: Reserved trace buffer memory for ETR and ETF sinks.
+          For ETR, this reserved memory region is used for trace data capture.
+          Same region is used for trace data retention as well after a panic
+          or watchdog reset.
+          For ETF, this reserved memory region is used for retention of trace
+          data synced from internal SRAM after a panic or watchdog reset.
+

Is there a valid use case for ETR where we use these areas when there is not a panic/reset situation?

Either way - the description should perhaps mention that these areas are only used if specifically selected by the driver - the default memory usage models for ETR / perf are otherwise unaltered.

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 119

Quoted 7 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +7 -0
+      - description: Reserved meta data memory. Used for ETR and ETF sinks.
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem
+

Is there a constraint required here? If we are using the memory area for trace in a panic situation, then we must have the meta data memory area defined?
Perhaps a set of names such as "etr-trace-mem", "panic-trace-mem" , "panic-metadata-mem", were the first is for general ETR trace in non-panic situation and then constrain the "panic-" areas to appear together.
The "etr-trace-mem", "panic-trace-mem" could easily point to the same area.

Quoted 16 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +3 -1
 required:
   - compatible
   - reg
@@ -115,6 +131,9 @@ examples:
     etr@20070000 {
         compatible = "arm,coresight-tmc", "arm,primecell";
         reg = <0x20070000 0x1000>;
+        memory-region = <&etr_trace_mem_reserved>,
+                       <&etr_mdata_mem_reserved>;
+        memory-region-names = "trace-mem", "metadata-mem";
 
         clocks = <&oscclk6a>;
         clock-names = "apb_pclk";
--

2.34.1

Signature · 3 lines
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK
#7 lore raw

RE: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Hi Mike,

Quoted 51 lines

-----Original Message-----
From: Mike Leach <[email protected]>
Sent: Friday, October 6, 2023 4:33 PM
To: Linu Cherian <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

External Email

----------------------------------------------------------------------
Hi Linu

Quoted 32 lines · Linu Cherian

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

---
 .../bindings/arm/arm,coresight-tmc.yaml       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml b/Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml index cb8dceaca70e..45ca4d02d73e 100644

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +0 -0
@@ -101,6 +101,22 @@ properties:
           and ETF configurations.
         $ref: /schemas/graph.yaml#/properties/port
 
Quoted 13 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 112

Quoted 9 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +9 -0
+  memory-region:
+    items:
+      - description: Reserved trace buffer memory for ETR and ETF sinks.
+          For ETR, this reserved memory region is used for trace data capture.
+          Same region is used for trace data retention as well after a panic
+          or watchdog reset.
+          For ETF, this reserved memory region is used for retention of trace
+          data synced from internal SRAM after a panic or watchdog reset.
+

Is there a valid use case for ETR where we use these areas when there is not a panic/reset situation?

Currently its meant to be used only for the panic/reset situations and gets enabled only with a special buffer mode.

Quoted 3 lines

Either way - the description should perhaps mention that these areas are only used if specifically selected by the driver - the default memory usage models for ETR / perf are otherwise unaltered.

Ack.

Quoted 18 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 119

Quoted 8 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +7 -0
+      - description: Reserved meta data memory. Used for ETR and ETF sinks.
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem
+

Is there a constraint required here? If we are using the memory area for trace in a panic situation, then we must have the meta data memory area defined?
Perhaps a set of names such as "etr-trace-mem", "panic-trace-mem" , "panic-metadata-mem", were the first is for general ETR trace in non-panic situation and then constrain the "panic-" areas to appear together. The "etr-trace-mem", "panic-trace-mem" could easily point to the same area.

As noted above, we do not have other generic use case for these reserved regions now. Hence two regions/names, panic-trace-mem and panic-metadata-mem with constraints kept as
minItems: 2 and maxItems: 2 would suffice ?

Quoted 22 lines
Quoted 14 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +3 -1
 required:
   - compatible
   - reg
@@ -115,6 +131,9 @@ examples:
     etr@20070000 {
         compatible = "arm,coresight-tmc", "arm,primecell";
         reg = <0x20070000 0x1000>;
+        memory-region = <&etr_trace_mem_reserved>,
+                       <&etr_mdata_mem_reserved>;
+        memory-region-names = "trace-mem", "metadata-mem";
 
         clocks = <&oscclk6a>;
         clock-names = "apb_pclk";
--
Quoted 2 lines

2.34.1

--
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

#8 lore raw

Re: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Quoted 17 lines · Linu Cherian
Quoted 8 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 119

Quoted 7 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +7 -0
+      - description: Reserved meta data memory. Used for ETR and ETF sinks.
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem
+
Quoted 9 lines

Is there a constraint required here? If we are using the memory area for trace in a panic situation, then we must have the meta data memory area defined?
Perhaps a set of names such as "etr-trace-mem", "panic-trace-mem" , "panic-metadata-mem", were the first is for general ETR trace in non-panic situation and then constrain the "panic-" areas to appear together. The "etr-trace-mem", "panic-trace-mem" could easily point to the same area.

Quoted 3 lines

As noted above, we do not have other generic use case for these reserved regions now. Hence two regions/names, panic-trace-mem and panic-metadata-mem with constraints kept as
minItems: 2 and maxItems: 2 would suffice ?

Whatever you do, please delete the -mem suffix.

#9 lore raw

RE: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Hi Conor,

Quoted 34 lines

-----Original Message-----
From: Conor Dooley <[email protected]>
Sent: Saturday, October 14, 2023 6:56 PM
To: Linu Cherian <[email protected]>
Cc: Mike Leach <[email protected]>; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: Re: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Quoted 1 line · Linu Cherian
Quoted 1 line
Quoted 1 line

+ - description: Reserved meta data memory. Used for ETR and ETF

sinks.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +5 -0
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

+

Is there a constraint required here? If we are using the memory area for trace in a panic situation, then we must have the meta data memory area defined?
Perhaps a set of names such as "etr-trace-mem", "panic-trace-mem" , "panic-metadata-mem", were the first is for general ETR trace in non-panic situation and then constrain the "panic-" areas to appear

together.

Quoted 3 lines
Quoted 3 lines

The "etr-trace-mem", "panic-trace-mem" could easily point to the same area.

Quoted 8 lines
Quoted 1 line

As noted above, we do not have other generic use case for these reserved

regions now.

Quoted 1 line

Hence two regions/names, panic-trace-mem and panic-metadata-mem

with

Quoted 2 lines

constraints kept as
minItems: 2 and maxItems: 2 would suffice ?

Whatever you do, please delete the -mem suffix.

Ack.

#10 lore raw

RE: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

In reply to Linu Cherian

Hi Mike,

Quoted 108 lines

-----Original Message-----
From: Linu Cherian
Sent: Saturday, October 14, 2023 5:07 PM
To: Mike Leach <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: RE: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Hi Mike,

Quoted 13 lines

-----Original Message-----
From: Mike Leach <[email protected]>
Sent: Friday, October 6, 2023 4:33 PM
To: Linu Cherian <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>
Subject: [EXT] Re: [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property

Quoted 26 lines

External Email

----------------------------------------------------------------------
Hi Linu

Quoted 20 lines · Linu Cherian

memory-region 0: Reserved trace buffer memory

TMC ETR: When available, use this reserved memory region for trace data capture. Same region is used for trace data retention after a panic or watchdog reset.

TMC ETF: When available, use this reserved memory region for trace data retention synced from internal SRAM after a panic or watchdog reset.

memory-region 1: Reserved meta data memory

TMC ETR, ETF: When available, use this memory for register snapshot retention synced from hardware registers after a panic or watchdog reset.

---
 .../bindings/arm/arm,coresight-tmc.yaml       | 19

+++++++++++++++++++

Quoted 12 lines
Quoted 12 lines
 1 file changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml b/Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml index cb8dceaca70e..45ca4d02d73e 100644

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +0 -0
@@ -101,6 +101,22 @@ properties:
           and ETF configurations.
         $ref: /schemas/graph.yaml#/properties/port
 
Quoted 4 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 107

Quoted 4 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +4 -0
+  memory-region:
+    items:
+      - description: Reserved trace buffer memory for ETR and ETF sinks.
+          For ETR, this reserved memory region is used for trace data

capture.

Quoted 9 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 112

Quoted 5 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +5 -0
+          Same region is used for trace data retention as well after a panic
+          or watchdog reset.
+          For ETF, this reserved memory region is used for retention of trace
+          data synced from internal SRAM after a panic or watchdog reset.
+

Is there a valid use case for ETR where we use these areas when there is not a panic/reset situation?

Currently its meant to be used only for the panic/reset situations and gets enabled only with a special buffer mode.

Quoted 3 lines

Either way - the description should perhaps mention that these areas are only used if specifically selected by the driver - the default memory usage models for ETR / perf are otherwise unaltered.

Ack.

Quoted 2 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 113

Quoted 2 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +1 -0
+      - description: Reserved meta data memory. Used for ETR and ETF

sinks.

Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +5 -0
+
+  memory-region-names:
+    items:
+      - const: trace-mem
+      - const: metadata-mem
Quoted 8 lines

Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml properties: · line 119

Quoted 1 line
Documentation/devicetree/bindings/arm/arm,coresight-tmc.yaml +1 -0
+

Is there a constraint required here? If we are using the memory area for trace in a panic situation, then we must have the meta data memory area defined?
Perhaps a set of names such as "etr-trace-mem", "panic-trace-mem" , "panic-metadata-mem", were the first is for general ETR trace in non-panic situation and then constrain the "panic-" areas to appear

together.

Quoted 8 lines
Quoted 3 lines

The "etr-trace-mem", "panic-trace-mem" could easily point to the same area.

As noted above, we do not have other generic use case for these reserved regions now.
Hence two regions/names, panic-trace-mem and panic-metadata-mem with constraints kept as
minItems: 2 and maxItems: 2 would suffice ?

Looking this further, realized that by default minItems and maxItems are 2 in this case. IIUC, nothing additional required to enforce this constraint.

Also tested this, with the below dts change with just one memory-region,

arch/arm64/boot/dts/arm/juno-cs-r1r2.dtsi +3 -0
index 09d2b692e9e1..03ff6b2f7269 100644
@@ -30,6 +30,9 @@ etf_sys1: etf@20140000 { /* etf1 */
                clocks = <&soc_smc50mhz>;
                clock-names = "apb_pclk";
                power-domains = <&scpi_devpd 0>;
+               memory-region = <&etf1_trace>;
+               memory-region-names = "tracedata";
+
                in-ports {
 
 

Validation of DTS files using below command identified this.

# make CHECK_DTBS=y ARCH=arm64  arm/juno-r2-scmi.dtb 

from schema $id: http://devicetree.org/schemas/thermal/thermal-zones.yaml#
/home/lcherian/scode/mainline/linux/arch/arm64/boot/dts/arm/juno-r2-scmi.dtb: etf@20140000: memory-region: [[72]] is too short
from schema $id: http://devicetree.org/schemas/arm/arm,coresight-tmc.yaml#
/home/lcherian/scode/mainline/linux/arch/arm64/boot/dts/arm/juno-r2-scmi.dtb: etf@20140000: memory-region-names: ['tracedata'] is too short
from schema $id: http://devicetree.org/schemas/arm/arm,coresight-tmc.yaml#
/home/lcherian/scode/mainline/linux/arch/arm64/boot/dts/arm/juno-r2-scmi.dtb: etf@20140000: Unevaluated properties are not allowed ('memory-region', 'memory-region-names' were unexp ected)

#11 lore raw

PATCH 2/7 coresight: tmc-etr: Add support to use reserved trace memory

In reply to Linu Cherian

Add support to use reserved memory for coresight ETR trace buffer.

Introduce a new ETR buffer mode called ETR_MODE_RESRV, which becomes available when ETR device tree node is supplied with a valid reserved memory region.

ETR_MODE_RESRV can be selected only by explicit user request.

$ echo resrv >/sys/bus/coresight/devices/tmc_etr<N>/buf_mode_preferred
---
 .../hwtracing/coresight/coresight-tmc-core.c  | 51 +++++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 87 ++++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   | 24 +++++
 3 files changed, 161 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +51 -0
index 7ec5365e2b64..1e94215ac148 100644
@@ -22,6 +22,7 @@
 #include <linux/spinlock.h>
 #include <linux/pm_runtime.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/coresight.h>
 #include <linux/amba/bus.h>
 
@@ -370,6 +371,54 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata)
 	return (auth & TMC_AUTH_NSID_MASK) == 0x3;
 }
 
+static struct device_node *tmc_get_region_byname(struct device_node *node,
+						 char *name)
+{
+	int index;
+
+	index = of_property_match_string(node, "memory-region-names", name);
+	if (index < 0)
+		return ERR_PTR(-ENODEV);
+
+	return of_parse_phandle(node, "memory-region", index);
+}
+
+static void tmc_get_reserved_region(struct device *parent)
+{
+	struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
+	struct device_node *node;
+	struct resource res;
+	int rc;
+
+	node = tmc_get_region_byname(parent->of_node, "tracedata-mem");
+	if (IS_ERR_OR_NULL(node)) {
+		dev_dbg(parent, "No reserved trace buffer specified\n");
+		goto out;
+	}
+
+	rc = of_address_to_resource(node, 0, &res);
+	of_node_put(node);
+	if (rc || res.start == 0 || resource_size(&res) == 0) {
+		dev_err(parent, "Reserved trace buffer memory is invalid\n");
+		goto out;
+	}
+
+	drvdata->resrv_buf.vaddr = memremap(res.start,
+						resource_size(&res),
+						MEMREMAP_WC);
+	if (IS_ERR_OR_NULL(drvdata->resrv_buf.vaddr)) {
+		dev_err(parent, "Reserved trace buffer mapping failed\n");
+		rc = PTR_ERR(drvdata->resrv_buf.vaddr);
+		goto out;
+	}
+
+	drvdata->resrv_buf.paddr = res.start;
+	drvdata->resrv_buf.size  = resource_size(&res);
+
+out:
+	return;
+}
+
 /* Detect and initialise the capabilities of a TMC ETR */
 static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps)
 {
@@ -482,6 +531,8 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
 		drvdata->size = readl_relaxed(drvdata->base + TMC_RSZ) * 4;
 	}
 
+	tmc_get_reserved_region(dev);
+
 	desc.dev = dev;
 
 	switch (drvdata->config_type) {
drivers/hwtracing/coresight/coresight-tmc-etr.c +86 -1

153 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-tmc.h +24 -0
index 8dcb426ac3e7..5400e1ef1f1b 100644
@@ -135,6 +135,7 @@ enum etr_mode {
 	ETR_MODE_FLAT,		/* Uses contiguous flat buffer */
 	ETR_MODE_ETR_SG,	/* Uses in-built TMC ETR SG mechanism */
 	ETR_MODE_CATU,		/* Use SG mechanism in CATU */
+	ETR_MODE_RESRV,		/* Use reserved region contiguous buffer */
 	ETR_MODE_AUTO,		/* Use the default mechanism */
 };
 
@@ -164,6 +165,17 @@ struct etr_buf {
 	void				*private;
 };
 
+/**
+ * @paddr	: Start address of reserved memory region.
+ * @vaddr	: Corresponding CPU virtual address.
+ * @size	: Size of reserved memory region.
+ */
+struct tmc_resrv_buf {
+	phys_addr_t     paddr;
+	void		*vaddr;
+	size_t		size;
+};
+
 /**
  * struct tmc_drvdata - specifics associated to an TMC component
  * @base:	memory mapped base address for this component.
@@ -188,6 +200,7 @@ struct etr_buf {
  * @idr_mutex:	Access serialisation for idr.
  * @sysfs_buf:	SYSFS buffer for ETR.
  * @perf_buf:	PERF buffer for ETR.
+ * @resrv_buf: Reserved Memory for trace data buffer. Used by ETR/ETF.
  */
 struct tmc_drvdata {
 	void __iomem		*base;
@@ -213,6 +226,7 @@ struct tmc_drvdata {
 	struct mutex		idr_mutex;
 	struct etr_buf		*sysfs_buf;
 	struct etr_buf		*perf_buf;
+	struct tmc_resrv_buf	resrv_buf;
 };
 
 struct etr_buf_operations {
@@ -330,6 +344,16 @@ tmc_sg_table_buf_size(struct tmc_sg_table *sg_table)
 	return (unsigned long)sg_table->data_pages.nr_pages << PAGE_SHIFT;
 }
 
+static inline bool is_tmc_reserved_region_valid(struct device *dev)
+{
+	struct tmc_drvdata *drvdata = dev_get_drvdata(dev);
+
+	if (drvdata->resrv_buf.paddr &&
+		drvdata->resrv_buf.size)
+		return true;
+	return false;
+}
+
 struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
 
 void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu);
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH 2/7] coresight: tmc-etr: Add support to use reserved trace memory

Quoted 22 lines · Linu Cherian

Add support to use reserved memory for coresight ETR trace buffer.

Introduce a new ETR buffer mode called ETR_MODE_RESRV, which becomes available when ETR device tree node is supplied with a valid reserved memory region.

ETR_MODE_RESRV can be selected only by explicit user request.

$ echo resrv >/sys/bus/coresight/devices/tmc_etr<N>/buf_mode_preferred
---
 .../hwtracing/coresight/coresight-tmc-core.c  | 51 +++++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 87 ++++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   | 24 +++++
 3 files changed, 161 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
index 7ec5365e2b64..1e94215ac148 100644

[...]

drivers/hwtracing/coresight/coresight-tmc-etr.c

Quoted 2 lines
drivers/hwtracing/coresight/coresight-tmc-etr.c +0 -0
index 834674feb6b4..fca82eaf073f 100644

Hi Linu,

I think this version of coresight-tmc-etr.c isn't in the tree and it makes it hard to apply the set. Do you have local changes? Or if it requires other patches it might be best to host the full set on your own repo and link to it:

  $ git show 834674feb6b4
  fatal: ambiguous argument '834674feb6b4': unknown revision or path not
  in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

Thanks
James

#13 lore raw

Re: [PATCH 2/7] coresight: tmc-etr: Add support to use reserved trace memory

Quoted 38 lines · James Clark
Quoted 22 lines · Linu Cherian

Add support to use reserved memory for coresight ETR trace buffer.

Introduce a new ETR buffer mode called ETR_MODE_RESRV, which becomes available when ETR device tree node is supplied with a valid reserved memory region.

ETR_MODE_RESRV can be selected only by explicit user request.

$ echo resrv >/sys/bus/coresight/devices/tmc_etr<N>/buf_mode_preferred
---
 .../hwtracing/coresight/coresight-tmc-core.c  | 51 +++++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 87 ++++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   | 24 +++++
 3 files changed, 161 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
index 7ec5365e2b64..1e94215ac148 100644

[...]

drivers/hwtracing/coresight/coresight-tmc-etr.c

Quoted 2 lines
drivers/hwtracing/coresight/coresight-tmc-etr.c +0 -0
index 834674feb6b4..fca82eaf073f 100644

Hi Linu,

I think this version of coresight-tmc-etr.c isn't in the tree and it makes it hard to apply the set. Do you have local changes? Or if it requires other patches it might be best to host the full set on your own repo and link to it:

Quoted 8 lines
  $ git show 834674feb6b4
  fatal: ambiguous argument '834674feb6b4': unknown revision or path not
  in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

Thanks
James

Sorry just saw the note at the top of the cover letter about the other patches.

Quoted 3 lines

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

#14 lore raw

Re: [PATCH 2/7] coresight: tmc-etr: Add support to use reserved trace memory

In reply to Linu Cherian
Quoted 17 lines · Linu Cherian

Add support to use reserved memory for coresight ETR trace buffer.

Introduce a new ETR buffer mode called ETR_MODE_RESRV, which becomes available when ETR device tree node is supplied with a valid reserved memory region.

ETR_MODE_RESRV can be selected only by explicit user request.

$ echo resrv >/sys/bus/coresight/devices/tmc_etr<N>/buf_mode_preferred
---
 .../hwtracing/coresight/coresight-tmc-core.c  | 51 +++++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 87 ++++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   | 24 +++++
 3 files changed, 161 insertions(+), 1 deletion(-)

[...]

drivers/hwtracing/coresight/coresight-tmc-core.c static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata) · line 393

Quoted 9 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +8 -0
+static void tmc_get_reserved_region(struct device *parent)
+{
+	struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
+	struct device_node *node;
+	struct resource res;
+	int rc;
+
+	node = tmc_get_region_byname(parent->of_node, "tracedata-mem");

Is this a typo? The DT commit says the region is called "trace-mem". And "metadata-mem" for the other region, but that one matches the other call to tmc_get_region_byname() added in the later commit.

Quoted 5 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +5 -0
+	if (IS_ERR_OR_NULL(node)) {
+		dev_dbg(parent, "No reserved trace buffer specified\n");
+		goto out;
+	}
+
#15 lore raw

RE: [EXT] Re: [PATCH 2/7] coresight: tmc-etr: Add support to use reserved trace memory

Hi James,

Quoted 52 lines

-----Original Message-----
From: James Clark <[email protected]>
Sent: Monday, October 2, 2023 8:34 PM
To: Linu Cherian <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>; Anil Kumar Reddy H <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [PATCH 2/7] coresight: tmc-etr: Add support to use reserved trace memory

External Email

----------------------------------------------------------------------

Quoted 3 lines · Linu Cherian

Add support to use reserved memory for coresight ETR trace buffer.

Introduce a new ETR buffer mode called ETR_MODE_RESRV, which

becomes

Quoted 15 lines

available when ETR device tree node is supplied with a valid reserved memory region.

ETR_MODE_RESRV can be selected only by explicit user request.

$ echo resrv
/sys/bus/coresight/devices/tmc_etr<N>/buf_mode_preferred
---
 .../hwtracing/coresight/coresight-tmc-core.c  | 51 +++++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 87 ++++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   | 24 +++++
 3 files changed, 161 insertions(+), 1 deletion(-)

[...]

drivers/hwtracing/coresight/coresight-tmc-core.c static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata)

Quoted 8 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +7 -0
+static void tmc_get_reserved_region(struct device *parent) {
+	struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
+	struct device_node *node;
+	struct resource res;
+	int rc;
+
+	node = tmc_get_region_byname(parent->of_node, "tracedata-

mem");

Quoted 3 lines

Is this a typo? The DT commit says the region is called "trace-mem". And "metadata-mem" for the other region, but that one matches the other call to tmc_get_region_byname() added in the later commit.

Ack. Will fix in the next version.

Quoted 6 lines
Quoted 6 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +5 -0
+	if (IS_ERR_OR_NULL(node)) {
+		dev_dbg(parent, "No reserved trace buffer specified\n");
+		goto out;
+	}
+
#16 lore raw

PATCH 3/7 coresight: core: Add provision for panic callbacks

In reply to Linu Cherian

Panic callback handlers allows coresight device drivers to sync relevant trace data and trace metadata to reserved memory regions so that they can be retrieved later in the subsequent boot or in the crashdump kernel.

---
 drivers/hwtracing/coresight/coresight-core.c | 32 ++++++++++++++++++++
 include/linux/coresight.h                    | 12 ++++++++
 2 files changed, 44 insertions(+)
drivers/hwtracing/coresight/coresight-core.c +32 -0
index 9fabe00a40d6..dfa695c103de 100644
@@ -20,6 +20,7 @@
 #include <linux/property.h>
 #include <linux/delay.h>
 #include <linux/pm_runtime.h>
+#include <linux/panic_notifier.h>
 
 #include "coresight-etm-perf.h"
 #include "coresight-priv.h"
@@ -1800,6 +1801,31 @@ struct bus_type coresight_bustype = {
 	.name	= "coresight",
 };
 
+static int coresight_panic_sync(struct device *dev, void *data)
+{
+
+	struct coresight_device *csdev = container_of(dev, struct coresight_device, dev);
+
+	/* Run through panic sync handlers for all enabled devices */
+	if (csdev->enable && panic_ops(csdev))
+		panic_ops(csdev)->sync(csdev);
+
+	return 0;
+}
+
+static int coresight_panic_cb(struct notifier_block *self,
+			       unsigned long v, void *p)
+{
+	bus_for_each_dev(&coresight_bustype, NULL, NULL,
+				 coresight_panic_sync);
+
+	return 0;
+}
+
+static struct notifier_block coresight_notifier = {
+	.notifier_call = coresight_panic_cb,
+};
+
 static int __init coresight_init(void)
 {
 	int ret;
@@ -1812,6 +1838,10 @@ static int __init coresight_init(void)
 	if (ret)
 		goto exit_bus_unregister;
 
+	/* Register function to be called for panic */
+	ret = atomic_notifier_chain_register(&panic_notifier_list,
+					     &coresight_notifier);
+
 	/* initialise the coresight syscfg API */
 	ret = cscfg_init();
 	if (!ret)
@@ -1826,6 +1856,8 @@ static int __init coresight_init(void)
 static void __exit coresight_exit(void)
 {
 	cscfg_exit();
+	atomic_notifier_chain_unregister(&panic_notifier_list,
+					     &coresight_notifier);
 	etm_perf_exit();
 	bus_unregister(&coresight_bustype);
 }
include/linux/coresight.h +12 -0
index a269fffaf991..4fd518738958 100644
@@ -301,6 +301,7 @@ enum cs_mode {
 #define link_ops(csdev)		csdev->ops->link_ops
 #define helper_ops(csdev)	csdev->ops->helper_ops
 #define ect_ops(csdev)		csdev->ops->ect_ops
+#define panic_ops(csdev)	csdev->ops->panic_ops
 
 /**
  * struct coresight_ops_sink - basic operations for a sink
@@ -370,11 +371,22 @@ struct coresight_ops_helper {
 	int (*disable)(struct coresight_device *csdev, void *data);
 };
 
+
+/**
+ * struct coresight_ops_panic - Generic device ops for panic handing
+ *
+ * @sync	: Sync the device register state/trace data
+ */
+struct coresight_ops_panic {
+	int (*sync)(struct coresight_device *csdev);
+};
+
 struct coresight_ops {
 	const struct coresight_ops_sink *sink_ops;
 	const struct coresight_ops_link *link_ops;
 	const struct coresight_ops_source *source_ops;
 	const struct coresight_ops_helper *helper_ops;
+	const struct coresight_ops_panic *panic_ops;
 };
 
 #if IS_ENABLED(CONFIG_CORESIGHT)
Signature · 1 line
2.34.1
#17 lore raw

PATCH 4/7 coresight: tmc: Enable panic sync handling

In reply to Linu Cherian

- Get reserved region from device tree node for metadata
- Define metadata format for TMC
- Add TMC ETR panic sync handler that syncs register snapshot to metadata region
- Add TMC ETF panic sync handler that syncs register snapshot to metadata region and internal SRAM to reserved trace buffer region.

---
 .../hwtracing/coresight/coresight-tmc-core.c  | 26 +++++++++
 .../hwtracing/coresight/coresight-tmc-etf.c   | 56 +++++++++++++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 52 +++++++++++++++++
 drivers/hwtracing/coresight/coresight-tmc.h   | 19 ++++++-
 4 files changed, 152 insertions(+), 1 deletion(-)
drivers/hwtracing/coresight/coresight-tmc-core.c +26 -0
index 1e94215ac148..6658ce76777b 100644
@@ -415,6 +415,32 @@ static void tmc_get_reserved_region(struct device *parent)
 	drvdata->resrv_buf.paddr = res.start;
 	drvdata->resrv_buf.size  = resource_size(&res);
 
+	/* Metadata region */
+	node = tmc_get_region_byname(parent->of_node, "metadata-mem");
+	if (IS_ERR_OR_NULL(node)) {
+		dev_dbg(parent, "No metadata memory-region specified\n");
+		goto out;
+	}
+
+	rc = of_address_to_resource(node, 0, &res);
+	of_node_put(node);
+	if (rc || res.start == 0 || resource_size(&res) == 0) {
+		dev_err(parent, "Metadata memory is invalid\n");
+		goto out;
+	}
+
+	drvdata->metadata.vaddr = memremap(res.start,
+					       resource_size(&res),
+					       MEMREMAP_WC);
+	if (IS_ERR_OR_NULL(drvdata->metadata.vaddr)) {
+		dev_err(parent, "Metadata memory mapping failed\n");
+		rc = PTR_ERR(drvdata->metadata.vaddr);
+		goto out;
+	}
+
+	drvdata->metadata.paddr = res.start;
+	drvdata->metadata.size  = resource_size(&res);
+
 out:
 	return;
 }
drivers/hwtracing/coresight/coresight-tmc-etf.c +56 -0

74 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-tmc-etr.c +52 -0

66 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-tmc.h +18 -1
index 5400e1ef1f1b..24ef7bbb0611 100644
@@ -131,6 +131,19 @@ enum tmc_mem_intf_width {
 #define CORESIGHT_SOC_600_ETR_CAPS	\
 	(TMC_ETR_SAVE_RESTORE | TMC_ETR_AXI_ARCACHE)
 
+/* TMC metadata region for ETR and ETF configurations */
+struct tmc_register_snapshot {
+	uint32_t valid;         /* Indicate if this ETF/ETR was enabled */
+	uint32_t size;          /* Size of trace data */
+	uint32_t sts;           /* Status register */
+	uint32_t reserved32[3];
+	uint64_t rrp;           /* Read pointer */
+	uint64_t rwp;           /* Write pointer */
+	uint64_t dba;		/* Data buffer address */
+	uint64_t trc_paddr;	/* Phys address of trace buffer */
+	uint64_t reserved64[3];
+};
+
 enum etr_mode {
 	ETR_MODE_FLAT,		/* Uses contiguous flat buffer */
 	ETR_MODE_ETR_SG,	/* Uses in-built TMC ETR SG mechanism */
@@ -201,6 +214,7 @@ struct tmc_resrv_buf {
  * @sysfs_buf:	SYSFS buffer for ETR.
  * @perf_buf:	PERF buffer for ETR.
  * @resrv_buf: Reserved Memory for trace data buffer. Used by ETR/ETF.
+ * @metadata: Reserved memory for metadata. Used by ETR/ETF.
  */
 struct tmc_drvdata {
 	void __iomem		*base;
@@ -227,6 +241,7 @@ struct tmc_drvdata {
 	struct etr_buf		*sysfs_buf;
 	struct etr_buf		*perf_buf;
 	struct tmc_resrv_buf	resrv_buf;
+	struct tmc_resrv_buf	metadata;
 };
 
 struct etr_buf_operations {
@@ -349,7 +364,9 @@ static inline bool is_tmc_reserved_region_valid(struct device *dev)
 	struct tmc_drvdata *drvdata = dev_get_drvdata(dev);
 
 	if (drvdata->resrv_buf.paddr &&
-		drvdata->resrv_buf.size)
+		drvdata->resrv_buf.size &&
+		drvdata->metadata.paddr &&
+		drvdata->metadata.size)
 		return true;
 	return false;
 }
Signature · 1 line
2.34.1
#18 lore raw

PATCH 5/7 coresight: tmc: Add support for reading tracedata from previous boot

In reply to Linu Cherian

* Introduce a new mode CS_MODE_READ_PREVBOOT for reading tracedata captured in previous boot.

* Add special handlers for preparing ETR/ETF for this special mode

* User can read the trace data as below

For example, for reading trace data from tmc_etf sink

1. cd /sys/bus/coresight/devices/tmc_etfXX/

2. Change mode to READ_PREVBOOT

#echo 1 > read_prevboot

3. Dump trace buffer data to a file,

#dd if=/dev/tmc_etrXX of=~/cstrace.bin

4. Reset back to normal mode

#echo 0 > read_prevboot

---
 .../coresight/coresight-etm4x-core.c          |   1 +
 .../hwtracing/coresight/coresight-tmc-core.c  |  81 +++++++++-
 .../hwtracing/coresight/coresight-tmc-etf.c   |  62 ++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 145 +++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   |   6 +
 include/linux/coresight.h                     |  13 ++
 6 files changed, 306 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -0
index 77b0271ce6eb..513baf681280 100644
@@ -1010,6 +1010,7 @@ static void etm4_disable(struct coresight_device *csdev,
 
 	switch (mode) {
 	case CS_MODE_DISABLED:
+	case CS_MODE_READ_PREVBOOT:
 		break;
 	case CS_MODE_SYSFS:
 		etm4_disable_sysfs(csdev);
drivers/hwtracing/coresight/coresight-tmc-core.c +80 -1

108 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-tmc-etf.c +62 -0

100 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-tmc-etr.c +144 -1

190 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-tmc.h +6 -0
index 24ef7bbb0611..f8b79eaac0bd 100644
@@ -213,6 +213,9 @@ struct tmc_resrv_buf {
  * @idr_mutex:	Access serialisation for idr.
  * @sysfs_buf:	SYSFS buffer for ETR.
  * @perf_buf:	PERF buffer for ETR.
+ * @prevboot_buf: Previous boot buffer for ETR. This is a special purpose
+ *		buffer that is used only for mapping the trace buffer from
+ *		previous boot and not for capturing trace.
  * @resrv_buf: Reserved Memory for trace data buffer. Used by ETR/ETF.
  * @metadata: Reserved memory for metadata. Used by ETR/ETF.
  */
@@ -240,6 +243,7 @@ struct tmc_drvdata {
 	struct mutex		idr_mutex;
 	struct etr_buf		*sysfs_buf;
 	struct etr_buf		*perf_buf;
+	struct etr_buf		*prevboot_buf;
 	struct tmc_resrv_buf	resrv_buf;
 	struct tmc_resrv_buf	metadata;
 };
@@ -291,6 +295,8 @@ void tmc_flush_and_stop(struct tmc_drvdata *drvdata);
 void tmc_enable_hw(struct tmc_drvdata *drvdata);
 void tmc_disable_hw(struct tmc_drvdata *drvdata);
 u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata);
+int tmc_read_prepare_prevboot(struct tmc_drvdata *drvdata);
+int tmc_read_unprepare_prevboot(struct tmc_drvdata *drvdata);
 
 /* ETB/ETF functions */
 int tmc_read_prepare_etb(struct tmc_drvdata *drvdata);
include/linux/coresight.h +13 -0
index 4fd518738958..9f84decf1d7a 100644
@@ -294,6 +294,7 @@ enum cs_mode {
 	CS_MODE_DISABLED,
 	CS_MODE_SYSFS,
 	CS_MODE_PERF,
+	CS_MODE_READ_PREVBOOT, /* Trace data from previous boot */
 };
 
 #define source_ops(csdev)	csdev->ops->source_ops
@@ -302,6 +303,7 @@ enum cs_mode {
 #define helper_ops(csdev)	csdev->ops->helper_ops
 #define ect_ops(csdev)		csdev->ops->ect_ops
 #define panic_ops(csdev)	csdev->ops->panic_ops
+#define prevboot_ops(csdev)	csdev->ops->prevboot_ops
 
 /**
  * struct coresight_ops_sink - basic operations for a sink
@@ -381,12 +383,23 @@ struct coresight_ops_panic {
 	int (*sync)(struct coresight_device *csdev);
 };
 
+/**
+ * struct coresight_ops_prevboot - Generic device ops for prevboot mode
+ *
+ * @prepare	: Preparation for prevboot mode
+ */
+struct coresight_ops_prevboot {
+	int (*prepare)(struct coresight_device *csdev);
+	int (*unprepare)(struct coresight_device *csdev);
+};
+
 struct coresight_ops {
 	const struct coresight_ops_sink *sink_ops;
 	const struct coresight_ops_link *link_ops;
 	const struct coresight_ops_source *source_ops;
 	const struct coresight_ops_helper *helper_ops;
 	const struct coresight_ops_panic *panic_ops;
+	const struct coresight_ops_prevboot *prevboot_ops;
 };
 
 #if IS_ENABLED(CONFIG_CORESIGHT)
Signature · 1 line
2.34.1
#19 lore raw

Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

Quoted 63 lines · Linu Cherian

* Introduce a new mode CS_MODE_READ_PREVBOOT for reading tracedata captured in previous boot.

* Add special handlers for preparing ETR/ETF for this special mode

* User can read the trace data as below

For example, for reading trace data from tmc_etf sink

1. cd /sys/bus/coresight/devices/tmc_etfXX/

2. Change mode to READ_PREVBOOT

#echo 1 > read_prevboot

3. Dump trace buffer data to a file,

#dd if=/dev/tmc_etrXX of=~/cstrace.bin

4. Reset back to normal mode

#echo 0 > read_prevboot

---
 .../coresight/coresight-etm4x-core.c          |   1 +
 .../hwtracing/coresight/coresight-tmc-core.c  |  81 +++++++++-
 .../hwtracing/coresight/coresight-tmc-etf.c   |  62 ++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 145 +++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   |   6 +
 include/linux/coresight.h                     |  13 ++
 6 files changed, 306 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -0
index 77b0271ce6eb..513baf681280 100644
@@ -1010,6 +1010,7 @@ static void etm4_disable(struct coresight_device *csdev,
 
 	switch (mode) {
 	case CS_MODE_DISABLED:
+	case CS_MODE_READ_PREVBOOT:
 		break;
 	case CS_MODE_SYSFS:
 		etm4_disable_sysfs(csdev);
drivers/hwtracing/coresight/coresight-tmc-core.c +8 -0
index 6658ce76777b..65c15c9f821b 100644
@@ -103,6 +103,45 @@ u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata)
 	return mask;
 }
 
+int tmc_read_prepare_prevboot(struct tmc_drvdata *drvdata)
+{
+	int ret = 0;
+	struct tmc_register_snapshot *reg_ptr;
+	struct coresight_device *csdev = drvdata->csdev;
+
+	if (!drvdata->metadata.vaddr) {
+		ret = -ENOMEM;

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata) · line 123

Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +10 -0
+		goto out;
+	}
+
+	reg_ptr = drvdata->metadata.vaddr;
+	if (!reg_ptr->valid) {
+		dev_err(&drvdata->csdev->dev,
+			"Invalid metadata captured from previous boot\n");
+		ret = -EINVAL;
+		goto out;
+	}

I'm wondering if a more robust check is needed than the valid flag, like a checksum or something. I didn't debug it yet but I ended up with an invalid set of metadata after a panic reboot, see below. I'm not sure if it's just a logic bug or something got lost during the reboot, I didn't debug it yet. But I suppose unless you assume the panic didn't affect writing the metadata, then it could be partially written and shouldn't be trusted?

[...]

Quoted 18 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +18 -0
+
+static int tmc_etr_sync_prevboot_buf(struct tmc_drvdata *drvdata)
+{
+	u32 status;
+	u64 rrp, rwp, dba;
+	struct tmc_register_snapshot *reg_ptr;
+	struct etr_buf *etr_buf = drvdata->prevboot_buf;
+
+	reg_ptr = drvdata->metadata.vaddr;
+
+	rrp = reg_ptr->rrp;
+	rwp = reg_ptr->rwp;
+	dba = reg_ptr->dba;
+	status = reg_ptr->sts;
+
+	etr_buf->full = !!(status & TMC_STS_FULL);
+
+	/* Sync the buffer pointers */

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata)

Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +10 -0
+	etr_buf->offset = rrp - dba;
+	if (etr_buf->full)
+		etr_buf->len = etr_buf->size;
+	else
+		etr_buf->len = rwp - rrp;
+
+	/* Sanity checks for validating metadata */
+	if ((etr_buf->offset > etr_buf->size) ||
+	    (etr_buf->len > etr_buf->size))
+		return -EINVAL;

The values I got here are 0x781b67182aa346f9 0x8000000 0x8000000 for offset, size and len respectively. This fails the first check. It would also be nice to have a dev_dbg here as well, it's basically the same as the valid check above which does have one.

#20 lore raw

Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

Quoted 111 lines · James Clark
Quoted 63 lines · Linu Cherian

* Introduce a new mode CS_MODE_READ_PREVBOOT for reading tracedata captured in previous boot.

* Add special handlers for preparing ETR/ETF for this special mode

* User can read the trace data as below

For example, for reading trace data from tmc_etf sink

1. cd /sys/bus/coresight/devices/tmc_etfXX/

2. Change mode to READ_PREVBOOT

#echo 1 > read_prevboot

3. Dump trace buffer data to a file,

#dd if=/dev/tmc_etrXX of=~/cstrace.bin

4. Reset back to normal mode

#echo 0 > read_prevboot

---
 .../coresight/coresight-etm4x-core.c          |   1 +
 .../hwtracing/coresight/coresight-tmc-core.c  |  81 +++++++++-
 .../hwtracing/coresight/coresight-tmc-etf.c   |  62 ++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 145 +++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   |   6 +
 include/linux/coresight.h                     |  13 ++
 6 files changed, 306 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -0
index 77b0271ce6eb..513baf681280 100644
@@ -1010,6 +1010,7 @@ static void etm4_disable(struct coresight_device *csdev,
 
 	switch (mode) {
 	case CS_MODE_DISABLED:
+	case CS_MODE_READ_PREVBOOT:
 		break;
 	case CS_MODE_SYSFS:
 		etm4_disable_sysfs(csdev);
drivers/hwtracing/coresight/coresight-tmc-core.c +8 -0
index 6658ce76777b..65c15c9f821b 100644
@@ -103,6 +103,45 @@ u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata)
 	return mask;
 }
 
+int tmc_read_prepare_prevboot(struct tmc_drvdata *drvdata)
+{
+	int ret = 0;
+	struct tmc_register_snapshot *reg_ptr;
+	struct coresight_device *csdev = drvdata->csdev;
+
+	if (!drvdata->metadata.vaddr) {
+		ret = -ENOMEM;

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata) · line 123

Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +10 -0
+		goto out;
+	}
+
+	reg_ptr = drvdata->metadata.vaddr;
+	if (!reg_ptr->valid) {
+		dev_err(&drvdata->csdev->dev,
+			"Invalid metadata captured from previous boot\n");
+		ret = -EINVAL;
+		goto out;
+	}

I'm wondering if a more robust check is needed than the valid flag, like a checksum or something. I didn't debug it yet but I ended up with an invalid set of metadata after a panic reboot, see below. I'm not sure if it's just a logic bug or something got lost during the reboot, I didn't debug it yet. But I suppose unless you assume the panic didn't affect writing the metadata, then it could be partially written and shouldn't be trusted?

[...]

Quoted 25 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +25 -0
+
+static int tmc_etr_sync_prevboot_buf(struct tmc_drvdata *drvdata)
+{
+	u32 status;
+	u64 rrp, rwp, dba;
+	struct tmc_register_snapshot *reg_ptr;
+	struct etr_buf *etr_buf = drvdata->prevboot_buf;
+
+	reg_ptr = drvdata->metadata.vaddr;
+
+	rrp = reg_ptr->rrp;
+	rwp = reg_ptr->rwp;
+	dba = reg_ptr->dba;
+	status = reg_ptr->sts;
+
+	etr_buf->full = !!(status & TMC_STS_FULL);
+
+	/* Sync the buffer pointers */
+	etr_buf->offset = rrp - dba;
+	if (etr_buf->full)
+		etr_buf->len = etr_buf->size;
+	else
+		etr_buf->len = rwp - rrp;
+
+	/* Sanity checks for validating metadata */
Quoted 9 lines

drivers/hwtracing/coresight/coresight-tmc-core.c

Quoted 3 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +3 -0
+	if ((etr_buf->offset > etr_buf->size) ||
+	    (etr_buf->len > etr_buf->size))
+		return -EINVAL;

The values I got here are 0x781b67182aa346f9 0x8000000 0x8000000 for offset, size and len respectively. This fails the first check. It would also be nice to have a dev_dbg here as well, it's basically the same as the valid check above which does have one.

So I debugged it and the issue is that after the panic I was doing a cold boot rather than a warm boot and the memory was being randomised.

The reason that 0x8000000 seemed to be initialised is because they are based on the reserved region size, rather than anything from the metadata. When I examined the metadata it was all randomised.

That leads me to think that the single bit for 'valid' is insufficient. There is a simple hashing function in include/linux/stringhash.h that we could use on the whole metadata struct, but that specifically says:

* These hash functions are NOT GUARANTEED STABLE between kernel
* versions, architectures, or even repeated boots of the same kernel.
* (E.g. they may depend on boot-time hardware detection or be
* deliberately randomized.)

Although I'm not sure how true the repeated boots of the same kernel part is.

Maybe something in include/crypto/hash.h could be used instead, or make our own simple hash.

#21 lore raw

RE: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

Hi James,

Quoted 161 lines

-----Original Message-----
From: James Clark <[email protected]>
Sent: Wednesday, October 4, 2023 7:18 PM
To: Linu Cherian <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>; Anil Kumar Reddy H <[email protected]>; Tanmay Jagdale <[email protected]>
Subject: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

External Email

----------------------------------------------------------------------

Quoted 4 lines · James Clark
Quoted 1 line · Linu Cherian

* Introduce a new mode CS_MODE_READ_PREVBOOT for reading

tracedata

Quoted 42 lines
Quoted 42 lines

captured in previous boot.

* Add special handlers for preparing ETR/ETF for this special mode

* User can read the trace data as below

For example, for reading trace data from tmc_etf sink

1. cd /sys/bus/coresight/devices/tmc_etfXX/

2. Change mode to READ_PREVBOOT

#echo 1 > read_prevboot

3. Dump trace buffer data to a file,

#dd if=/dev/tmc_etrXX of=~/cstrace.bin

4. Reset back to normal mode

#echo 0 > read_prevboot

---
 .../coresight/coresight-etm4x-core.c          |   1 +
 .../hwtracing/coresight/coresight-tmc-core.c  |  81 +++++++++-
 .../hwtracing/coresight/coresight-tmc-etf.c   |  62 ++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 145 +++++++++++++++++-
 drivers/hwtracing/coresight/coresight-tmc.h   |   6 +
 include/linux/coresight.h                     |  13 ++
 6 files changed, 306 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
index 77b0271ce6eb..513baf681280 100644
@@ -1010,6 +1010,7 @@ static void etm4_disable(struct
 coresight_device *csdev,
 
Quoted 12 lines

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct

Quoted 12 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -0
 	switch (mode) {
 	case CS_MODE_DISABLED:
+	case CS_MODE_READ_PREVBOOT:
 		break;
 	case CS_MODE_SYSFS:
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
 		etm4_disable_sysfs(csdev);
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
index 6658ce76777b..65c15c9f821b 100644
@@ -103,6 +103,45 @@ u32 tmc_get_memwidth_mask(struct

tmc_drvdata *drvdata)

Quoted 54 lines
Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +7 -0
 	return mask;
 }
 
+int tmc_read_prepare_prevboot(struct tmc_drvdata *drvdata) {
+	int ret = 0;
+	struct tmc_register_snapshot *reg_ptr;
+	struct coresight_device *csdev = drvdata->csdev;
+
+	if (!drvdata->metadata.vaddr) {
+		ret = -ENOMEM;

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata) · line 123

Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +10 -0
+		goto out;
+	}
+
+	reg_ptr = drvdata->metadata.vaddr;
+	if (!reg_ptr->valid) {
+		dev_err(&drvdata->csdev->dev,
+			"Invalid metadata captured from previous boot\n");
+		ret = -EINVAL;
+		goto out;
+	}

I'm wondering if a more robust check is needed than the valid flag, like a checksum or something. I didn't debug it yet but I ended up with an invalid set of metadata after a panic reboot, see below. I'm not sure if it's just a logic bug or something got lost during the reboot, I didn't debug it yet. But I suppose unless you assume the panic didn't affect writing the metadata, then it could be partially written and shouldn't be trusted?

[...]

Quoted 24 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +24 -0
+
+static int tmc_etr_sync_prevboot_buf(struct tmc_drvdata *drvdata) {
+	u32 status;
+	u64 rrp, rwp, dba;
+	struct tmc_register_snapshot *reg_ptr;
+	struct etr_buf *etr_buf = drvdata->prevboot_buf;
+
+	reg_ptr = drvdata->metadata.vaddr;
+
+	rrp = reg_ptr->rrp;
+	rwp = reg_ptr->rwp;
+	dba = reg_ptr->dba;
+	status = reg_ptr->sts;
+
+	etr_buf->full = !!(status & TMC_STS_FULL);
+
+	/* Sync the buffer pointers */
+	etr_buf->offset = rrp - dba;
+	if (etr_buf->full)
+		etr_buf->len = etr_buf->size;
+	else
+		etr_buf->len = rwp - rrp;
+
+	/* Sanity checks for validating metadata */
Quoted 9 lines

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct

Quoted 3 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +3 -0
+	if ((etr_buf->offset > etr_buf->size) ||
+	    (etr_buf->len > etr_buf->size))
+		return -EINVAL;

The values I got here are 0x781b67182aa346f9 0x8000000 0x8000000 for offset, size and len respectively. This fails the first check. It would also be nice to have a dev_dbg here as well, it's basically the same as the valid check above which does have one.

So I debugged it and the issue is that after the panic I was doing a cold boot rather than a warm boot and the memory was being randomised.

The reason that 0x8000000 seemed to be initialised is because they are based on the reserved region size, rather than anything from the metadata. When I examined the metadata it was all randomised.

That leads me to think that the single bit for 'valid' is insufficient. There is a simple hashing function in include/linux/stringhash.h that we could use on the whole metadata struct, but that specifically says:

* These hash functions are NOT GUARANTEED STABLE between kernel
* versions, architectures, or even repeated boots of the same kernel.
* (E.g. they may depend on boot-time hardware detection or be
* deliberately randomized.)

Quoted 5 lines

Although I'm not sure how true the repeated boots of the same kernel part is.

Maybe something in include/crypto/hash.h could be used instead, or make our own simple hash.

Thanks for the pointers. Will take a look at it.

#22 lore raw

RE: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

Hi James,

Quoted 178 lines

-----Original Message-----
From: Linu Cherian <[email protected]>
Sent: Tuesday, October 10, 2023 6:53 PM
To: James Clark <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>; Anil Kumar Reddy H <[email protected]>
Subject: RE: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

Hi James,

Quoted 20 lines

-----Original Message-----
From: James Clark <[email protected]>
Sent: Wednesday, October 4, 2023 7:18 PM
To: Linu Cherian <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>; Anil Kumar Reddy H <[email protected]>; Tanmay Jagdale <[email protected]>
Subject: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

External Email

----------------------------------------------------------------------

Quoted 36 lines
Quoted 4 lines · James Clark
Quoted 1 line · Linu Cherian

* Introduce a new mode CS_MODE_READ_PREVBOOT for reading

tracedata

Quoted 30 lines
Quoted 30 lines

captured in previous boot.

* Add special handlers for preparing ETR/ETF for this special mode

* User can read the trace data as below

For example, for reading trace data from tmc_etf sink

1. cd /sys/bus/coresight/devices/tmc_etfXX/

2. Change mode to READ_PREVBOOT

#echo 1 > read_prevboot

3. Dump trace buffer data to a file,

#dd if=/dev/tmc_etrXX of=~/cstrace.bin

4. Reset back to normal mode

#echo 0 > read_prevboot

---
 .../coresight/coresight-etm4x-core.c          |   1 +
 .../hwtracing/coresight/coresight-tmc-core.c  |  81 +++++++++-
 .../hwtracing/coresight/coresight-tmc-etf.c   |  62 ++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 145

+++++++++++++++++-

Quoted 105 lines
Quoted 12 lines
Quoted 12 lines
 drivers/hwtracing/coresight/coresight-tmc.h   |   6 +
 include/linux/coresight.h                     |  13 ++
 6 files changed, 306 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
index 77b0271ce6eb..513baf681280 100644
@@ -1010,6 +1010,7 @@ static void etm4_disable(struct
 coresight_device *csdev,
 
Quoted 12 lines

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct

Quoted 12 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -0
 	switch (mode) {
 	case CS_MODE_DISABLED:
+	case CS_MODE_READ_PREVBOOT:
 		break;
 	case CS_MODE_SYSFS:
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
 		etm4_disable_sysfs(csdev);
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
index 6658ce76777b..65c15c9f821b 100644
@@ -103,6 +103,45 @@ u32 tmc_get_memwidth_mask(struct

tmc_drvdata *drvdata)

Quoted 54 lines
Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +7 -0
 	return mask;
 }
 
+int tmc_read_prepare_prevboot(struct tmc_drvdata *drvdata) {
+	int ret = 0;
+	struct tmc_register_snapshot *reg_ptr;
+	struct coresight_device *csdev = drvdata->csdev;
+
+	if (!drvdata->metadata.vaddr) {
+		ret = -ENOMEM;

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata) · line 123

Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +10 -0
+		goto out;
+	}
+
+	reg_ptr = drvdata->metadata.vaddr;
+	if (!reg_ptr->valid) {
+		dev_err(&drvdata->csdev->dev,
+			"Invalid metadata captured from previous boot\n");
+		ret = -EINVAL;
+		goto out;
+	}

I'm wondering if a more robust check is needed than the valid flag, like a checksum or something. I didn't debug it yet but I ended up with an invalid set of metadata after a panic reboot, see below. I'm not sure if it's just a logic bug or something got lost during the reboot, I didn't debug it yet. But I suppose unless you assume the panic didn't affect writing the metadata, then it could be partially written and shouldn't be trusted?

[...]

Quoted 24 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +24 -0
+
+static int tmc_etr_sync_prevboot_buf(struct tmc_drvdata *drvdata) {
+	u32 status;
+	u64 rrp, rwp, dba;
+	struct tmc_register_snapshot *reg_ptr;
+	struct etr_buf *etr_buf = drvdata->prevboot_buf;
+
+	reg_ptr = drvdata->metadata.vaddr;
+
+	rrp = reg_ptr->rrp;
+	rwp = reg_ptr->rwp;
+	dba = reg_ptr->dba;
+	status = reg_ptr->sts;
+
+	etr_buf->full = !!(status & TMC_STS_FULL);
+
+	/* Sync the buffer pointers */
+	etr_buf->offset = rrp - dba;
+	if (etr_buf->full)
+		etr_buf->len = etr_buf->size;
+	else
+		etr_buf->len = rwp - rrp;
+
+	/* Sanity checks for validating metadata */
Quoted 9 lines

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct

Quoted 3 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +3 -0
+	if ((etr_buf->offset > etr_buf->size) ||
+	    (etr_buf->len > etr_buf->size))
+		return -EINVAL;

The values I got here are 0x781b67182aa346f9 0x8000000 0x8000000 for offset, size and len respectively. This fails the first check. It would also be nice to have a dev_dbg here as well, it's basically the same as the valid check above which does have one.

So I debugged it and the issue is that after the panic I was doing a cold boot rather than a warm boot and the memory was being randomised.

The reason that 0x8000000 seemed to be initialised is because they are based on the reserved region size, rather than anything from the metadata. When I examined the metadata it was all randomised.

That leads me to think that the single bit for 'valid' is insufficient. There is a simple hashing function in include/linux/stringhash.h that we could use on the whole metadata struct, but that specifically says:

* These hash functions are NOT GUARANTEED STABLE between kernel
* versions, architectures, or even repeated boots of the same kernel.
* (E.g. they may depend on boot-time hardware detection or be
* deliberately randomized.)

Quoted 7 lines
Quoted 5 lines

Although I'm not sure how true the repeated boots of the same kernel part is.

Maybe something in include/crypto/hash.h could be used instead, or make our own simple hash.

Thanks for the pointers. Will take a look at it.

Since the purpose is to identify any data corruption, crc32(using crc32_le API) looks okay to me. Any thoughts on this ? May be we could add crc32 checks for trace data as well ?

Thanks.

Quoted 10 lines

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

#23 lore raw

Re: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

Quoted 186 lines · Linu Cherian

Hi James,

Quoted 184 lines

-----Original Message-----
From: Linu Cherian <[email protected]>
Sent: Tuesday, October 10, 2023 6:53 PM
To: James Clark <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>; Anil Kumar Reddy H <[email protected]>
Subject: RE: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

Hi James,

Quoted 20 lines

-----Original Message-----
From: James Clark <[email protected]>
Sent: Wednesday, October 4, 2023 7:18 PM
To: Linu Cherian <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Sunil Kovvuri Goutham <[email protected]>; George Cherian <[email protected]>; Anil Kumar Reddy H <[email protected]>; Tanmay Jagdale <[email protected]>
Subject: [EXT] Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot

External Email

----------------------------------------------------------------------

Quoted 36 lines
Quoted 4 lines · James Clark
Quoted 1 line · Linu Cherian

* Introduce a new mode CS_MODE_READ_PREVBOOT for reading

tracedata

Quoted 30 lines
Quoted 30 lines

captured in previous boot.

* Add special handlers for preparing ETR/ETF for this special mode

* User can read the trace data as below

For example, for reading trace data from tmc_etf sink

1. cd /sys/bus/coresight/devices/tmc_etfXX/

2. Change mode to READ_PREVBOOT

#echo 1 > read_prevboot

3. Dump trace buffer data to a file,

#dd if=/dev/tmc_etrXX of=~/cstrace.bin

4. Reset back to normal mode

#echo 0 > read_prevboot

---
 .../coresight/coresight-etm4x-core.c          |   1 +
 .../hwtracing/coresight/coresight-tmc-core.c  |  81 +++++++++-
 .../hwtracing/coresight/coresight-tmc-etf.c   |  62 ++++++++
 .../hwtracing/coresight/coresight-tmc-etr.c   | 145

+++++++++++++++++-

Quoted 110 lines
Quoted 12 lines
Quoted 12 lines
 drivers/hwtracing/coresight/coresight-tmc.h   |   6 +
 include/linux/coresight.h                     |  13 ++
 6 files changed, 306 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
index 77b0271ce6eb..513baf681280 100644
@@ -1010,6 +1010,7 @@ static void etm4_disable(struct
 coresight_device *csdev,
 
Quoted 12 lines

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct

Quoted 12 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -0
 	switch (mode) {
 	case CS_MODE_DISABLED:
+	case CS_MODE_READ_PREVBOOT:
 		break;
 	case CS_MODE_SYSFS:
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
 		etm4_disable_sysfs(csdev);
drivers/hwtracing/coresight/coresight-tmc-core.c +0 -0
index 6658ce76777b..65c15c9f821b 100644
@@ -103,6 +103,45 @@ u32 tmc_get_memwidth_mask(struct

tmc_drvdata *drvdata)

Quoted 54 lines
Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +7 -0
 	return mask;
 }
 
+int tmc_read_prepare_prevboot(struct tmc_drvdata *drvdata) {
+	int ret = 0;
+	struct tmc_register_snapshot *reg_ptr;
+	struct coresight_device *csdev = drvdata->csdev;
+
+	if (!drvdata->metadata.vaddr) {
+		ret = -ENOMEM;

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata) · line 123

Quoted 10 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +10 -0
+		goto out;
+	}
+
+	reg_ptr = drvdata->metadata.vaddr;
+	if (!reg_ptr->valid) {
+		dev_err(&drvdata->csdev->dev,
+			"Invalid metadata captured from previous boot\n");
+		ret = -EINVAL;
+		goto out;
+	}

I'm wondering if a more robust check is needed than the valid flag, like a checksum or something. I didn't debug it yet but I ended up with an invalid set of metadata after a panic reboot, see below. I'm not sure if it's just a logic bug or something got lost during the reboot, I didn't debug it yet. But I suppose unless you assume the panic didn't affect writing the metadata, then it could be partially written and shouldn't be trusted?

[...]

Quoted 24 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +24 -0
+
+static int tmc_etr_sync_prevboot_buf(struct tmc_drvdata *drvdata) {
+	u32 status;
+	u64 rrp, rwp, dba;
+	struct tmc_register_snapshot *reg_ptr;
+	struct etr_buf *etr_buf = drvdata->prevboot_buf;
+
+	reg_ptr = drvdata->metadata.vaddr;
+
+	rrp = reg_ptr->rrp;
+	rwp = reg_ptr->rwp;
+	dba = reg_ptr->dba;
+	status = reg_ptr->sts;
+
+	etr_buf->full = !!(status & TMC_STS_FULL);
+
+	/* Sync the buffer pointers */
+	etr_buf->offset = rrp - dba;
+	if (etr_buf->full)
+		etr_buf->len = etr_buf->size;
+	else
+		etr_buf->len = rwp - rrp;
+
+	/* Sanity checks for validating metadata */
Quoted 9 lines

drivers/hwtracing/coresight/coresight-tmc-core.c u32 tmc_get_memwidth_mask(struct

Quoted 3 lines
drivers/hwtracing/coresight/coresight-tmc-core.c +3 -0
+	if ((etr_buf->offset > etr_buf->size) ||
+	    (etr_buf->len > etr_buf->size))
+		return -EINVAL;

The values I got here are 0x781b67182aa346f9 0x8000000 0x8000000 for offset, size and len respectively. This fails the first check. It would also be nice to have a dev_dbg here as well, it's basically the same as the valid check above which does have one.

So I debugged it and the issue is that after the panic I was doing a cold boot rather than a warm boot and the memory was being randomised.

The reason that 0x8000000 seemed to be initialised is because they are based on the reserved region size, rather than anything from the metadata. When I examined the metadata it was all randomised.

That leads me to think that the single bit for 'valid' is insufficient. There is a simple hashing function in include/linux/stringhash.h that we could use on the whole metadata struct, but that specifically says:

* These hash functions are NOT GUARANTEED STABLE between kernel
* versions, architectures, or even repeated boots of the same kernel.
* (E.g. they may depend on boot-time hardware detection or be
* deliberately randomized.)

Although I'm not sure how true the repeated boots of the same kernel part is.

Maybe something in include/crypto/hash.h could be used instead, or make our own simple hash.

Quoted 7 lines
Quoted 1 line

Thanks for the pointers. Will take a look at it.

Since the purpose is to identify any data corruption, crc32(using crc32_le API) looks okay to me. Any thoughts on this ? May be we could add crc32 checks for trace data as well ?

Thanks.

Seems fine to me. Maybe doing it on the trace data is overkill if you already know the metadata is fine, but at the same time it might not do any harm either. It might catch some edge case where the firmware or device is doing something strange.

Quoted 13 lines
Quoted 13 lines

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

#24 lore raw

PATCH 6/7 coresight: tmc: Stop trace capture on FlIn

In reply to Linu Cherian

Configure TMC ETR and ETF to flush and stop trace capture on FlIn event. As a side effect, do manual flush only if auto flush fails.

---
 drivers/hwtracing/coresight/coresight-tmc-etf.c | 10 ++++++++--
 drivers/hwtracing/coresight/coresight-tmc-etr.c | 10 ++++++++--
 drivers/hwtracing/coresight/coresight-tmc.h     |  3 +++
 3 files changed, 19 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-etf.c +8 -2
index 496b44aad56d..cc73cd1f4d11 100644
@@ -34,7 +34,7 @@ static int __tmc_etb_enable_hw(struct tmc_drvdata *drvdata)
 	writel_relaxed(TMC_MODE_CIRCULAR_BUFFER, drvdata->base + TMC_MODE);
 	writel_relaxed(TMC_FFCR_EN_FMT | TMC_FFCR_EN_TI |
 		       TMC_FFCR_FON_FLIN | TMC_FFCR_FON_TRIG_EVT |
-		       TMC_FFCR_TRIGON_TRIGIN,
+		       TMC_FFCR_TRIGON_TRIGIN | TMC_FFCR_STOP_ON_FLUSH,
 		       drvdata->base + TMC_FFCR);
 
 	writel_relaxed(drvdata->trigger_cntr, drvdata->base + TMC_TRG);
@@ -613,7 +613,13 @@ static int tmc_panic_sync_etf(struct coresight_device *csdev)
 	if (val != TMC_MODE_CIRCULAR_BUFFER)
 		goto out;
 
-	tmc_flush_and_stop(drvdata);
+	val = readl(drvdata->base + TMC_FFSR);
+	/* Do manual flush and stop only if its not auto-stopped */
+	if (!(val & TMC_FFSR_FT_STOPPED)) {
+		dev_info(&csdev->dev,
+			 "%s: Triggering manual flush\n", __func__);
+		tmc_flush_and_stop(drvdata);
+	}
 
 	/* Sync registers from hardware to metadata region */
 	tmc->sts = csdev_access_relaxed_read32(csa, TMC_STS);
drivers/hwtracing/coresight/coresight-tmc-etr.c +8 -2
index c31c71e02833..c84f24333ebc 100644
@@ -1112,7 +1112,7 @@ static int __tmc_etr_enable_hw(struct tmc_drvdata *drvdata)
 
 	writel_relaxed(TMC_FFCR_EN_FMT | TMC_FFCR_EN_TI |
 		       TMC_FFCR_FON_FLIN | TMC_FFCR_FON_TRIG_EVT |
-		       TMC_FFCR_TRIGON_TRIGIN,
+		       TMC_FFCR_TRIGON_TRIGIN | TMC_FFCR_STOP_ON_FLUSH,
 		       drvdata->base + TMC_FFCR);
 	writel_relaxed(drvdata->trigger_cntr, drvdata->base + TMC_TRG);
 	tmc_enable_hw(drvdata);
@@ -1843,7 +1843,13 @@ static int tmc_panic_sync_etr(struct coresight_device *csdev)
 	if (!(val & TMC_CTL_CAPT_EN))
 		goto out;
 
-	tmc_flush_and_stop(drvdata);
+	val = readl(drvdata->base + TMC_FFSR);
+	/* Do manual flush and stop only if its not auto-stopped */
+	if (!(val & TMC_FFSR_FT_STOPPED)) {
+		dev_info(&csdev->dev,
+			 "%s: Triggering manual flush\n", __func__);
+		tmc_flush_and_stop(drvdata);
+	}
 
 	/* Sync registers from hardware to metadata region */
 	tmc->size = csdev_access_relaxed_read32(csa, TMC_RSZ);
drivers/hwtracing/coresight/coresight-tmc.h +3 -0
index f8b79eaac0bd..0975afca1f95 100644
@@ -76,6 +76,9 @@
 #define TMC_AXICTL_AXCACHE_OS	(0xf << 2)
 #define TMC_AXICTL_ARCACHE_OS	(0xf << 16)
 
+/* TMC_FFSR - 0x300 */
+#define TMC_FFSR_FT_STOPPED	BIT(1)
+
 /* TMC_FFCR - 0x304 */
 #define TMC_FFCR_FLUSHMAN_BIT	6
 #define TMC_FFCR_EN_FMT		BIT(0)
Signature · 1 line
2.34.1
#25 lore raw

PATCH 7/7 coresight: config: Add preloaded configuration

In reply to Linu Cherian

Add a preloaded configuration for generating
external trigger on address match. This can be
used by CTI and ETR blocks to stop trace capture
on kernel panic.

Kernel address for panic function to be
programmed as below.

$cd /config/cs-syscfg/features/gen_etrig/params
$echo <panic_address> > address/value

---
 drivers/hwtracing/coresight/Makefile          |  2 +-
 .../coresight/coresight-cfg-preload.c         |  2 +
 .../coresight/coresight-cfg-preload.h         |  2 +
 .../hwtracing/coresight/coresight-cfg-pstop.c | 83 +++++++++++++++++++
 4 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 drivers/hwtracing/coresight/coresight-cfg-pstop.c
drivers/hwtracing/coresight/Makefile +1 -1
index 995d3b2c76df..68b15c8d9462 100644
@@ -5,7 +5,7 @@
 obj-$(CONFIG_CORESIGHT) += coresight.o
 coresight-y := coresight-core.o  coresight-etm-perf.o coresight-platform.o \
 		coresight-sysfs.o coresight-syscfg.o coresight-config.o \
-		coresight-cfg-preload.o coresight-cfg-afdo.o \
+		coresight-cfg-preload.o coresight-cfg-afdo.o coresight-cfg-pstop.o \
 		coresight-syscfg-configfs.o coresight-trace-id.o
 obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
 coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
drivers/hwtracing/coresight/coresight-cfg-preload.c +2 -0
index e237a4edfa09..4980e68483c5 100644
@@ -13,6 +13,7 @@
 static struct cscfg_feature_desc *preload_feats[] = {
 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM4X)
 	&strobe_etm4x,
+	&gen_etrig_etm4x,
 #endif
 	NULL
 };
@@ -20,6 +21,7 @@ static struct cscfg_feature_desc *preload_feats[] = {
 static struct cscfg_config_desc *preload_cfgs[] = {
 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM4X)
 	&afdo_etm4x,
+	&pstop_etm4x,
 #endif
 	NULL
 };
drivers/hwtracing/coresight/coresight-cfg-preload.h +2 -0
index 21299e175477..291ba530a6a5 100644
@@ -10,4 +10,6 @@
 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM4X)
 extern struct cscfg_feature_desc strobe_etm4x;
 extern struct cscfg_config_desc afdo_etm4x;
+extern struct cscfg_feature_desc gen_etrig_etm4x;
+extern struct cscfg_config_desc pstop_etm4x;
 #endif
drivers/hwtracing/coresight/coresight-cfg-pstop.c new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
2.34.1