panic.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. ===================================================
  2. Using Coresight for Kernel panic and Watchdog reset
  3. ===================================================
  4. Introduction
  5. ------------
  6. This documentation is about using Linux coresight trace support to
  7. debug kernel panic and watchdog reset scenarios.
  8. Coresight trace during Kernel panic
  9. -----------------------------------
  10. From the coresight driver point of view, addressing the kernel panic
  11. situation has four main requirements.
  12. a. Support for allocation of trace buffer pages from reserved memory area.
  13. Platform can advertise this using a new device tree property added to
  14. relevant coresight nodes.
  15. b. Support for stopping coresight blocks at the time of panic
  16. c. Saving required metadata in the specified format
  17. d. Support for reading trace data captured at the time of panic
  18. Allocation of trace buffer pages from reserved RAM
  19. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. A new optional device tree property "memory-region" is added to the
  21. Coresight TMC device nodes, that would give the base address and size of trace
  22. buffer.
  23. Static allocation of trace buffers would ensure that both IOMMU enabled
  24. and disabled cases are handled. Also, platforms that support persistent
  25. RAM will allow users to read trace data in the subsequent boot without
  26. booting the crashdump kernel.
  27. Note:
  28. For ETR sink devices, this reserved region will be used for both trace
  29. capture and trace data retrieval.
  30. For ETF sink devices, internal SRAM would be used for trace capture,
  31. and they would be synced to reserved region for retrieval.
  32. Disabling coresight blocks at the time of panic
  33. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. In order to avoid the situation of losing relevant trace data after a
  35. kernel panic, it would be desirable to stop the coresight blocks at the
  36. time of panic.
  37. This can be achieved by configuring the comparator, CTI and sink
  38. devices as below::
  39. Trigger on panic
  40. Comparator --->External out --->CTI -->External In---->ETR/ETF stop
  41. Saving metadata at the time of kernel panic
  42. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. Coresight metadata involves all additional data that are required for a
  44. successful trace decode in addition to the trace data. This involves
  45. ETR/ETF/ETB register snapshot etc.
  46. A new optional device property "memory-region" is added to
  47. the ETR/ETF/ETB device nodes for this.
  48. Reading trace data captured at the time of panic
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. Trace data captured at the time of panic, can be read from rebooted kernel
  51. or from crashdump kernel using a special device file /dev/crash_tmc_xxx.
  52. This device file is created only when there is a valid crashdata available.
  53. General flow of trace capture and decode in case of kernel panic
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. 1. Enable source and sink on all the cores using the sysfs interface.
  56. ETR sinks should have trace buffers allocated from reserved memory,
  57. by selecting "resrv" buffer mode from sysfs.
  58. 2. Run relevant tests.
  59. 3. On a kernel panic, all coresight blocks are disabled, necessary
  60. metadata is synced by kernel panic handler.
  61. System would eventually reboot or boot a crashdump kernel.
  62. 4. For platforms that supports crashdump kernel, raw trace data can be
  63. dumped using the coresight sysfs interface from the crashdump kernel
  64. itself. Persistent RAM is not a requirement in this case.
  65. 5. For platforms that supports persistent RAM, trace data can be dumped
  66. using the coresight sysfs interface in the subsequent Linux boot.
  67. Crashdump kernel is not a requirement in this case. Persistent RAM
  68. ensures that trace data is intact across reboot.
  69. Coresight trace during Watchdog reset
  70. -------------------------------------
  71. The main difference between addressing the watchdog reset and kernel panic
  72. case are below,
  73. a. Saving coresight metadata need to be taken care by the
  74. SCP(system control processor) firmware in the specified format,
  75. instead of kernel.
  76. b. Reserved memory region given by firmware for trace buffer and metadata
  77. has to be in persistent RAM.
  78. Note: This is a requirement for watchdog reset case but optional
  79. in kernel panic case.
  80. Watchdog reset can be supported only on platforms that meet the above
  81. two requirements.
  82. Sample commands for testing a Kernel panic case with ETR sink
  83. -------------------------------------------------------------
  84. 1. Boot Linux kernel with "crash_kexec_post_notifiers" added to the kernel
  85. bootargs. This is mandatory if the user would like to read the tracedata
  86. from the crashdump kernel.
  87. 2. Enable the preloaded ETM configuration::
  88. #echo 1 > /sys/kernel/config/cs-syscfg/configurations/panicstop/enable
  89. 3. Configure CTI using sysfs interface::
  90. #./cti_setup.sh
  91. #cat cti_setup.sh
  92. cd /sys/bus/coresight/devices/
  93. ap_cti_config () {
  94. #ETM trig out[0] trigger to Channel 0
  95. echo 0 4 > channels/trigin_attach
  96. }
  97. etf_cti_config () {
  98. #ETF Flush in trigger from Channel 0
  99. echo 0 1 > channels/trigout_attach
  100. echo 1 > channels/trig_filter_enable
  101. }
  102. etr_cti_config () {
  103. #ETR Flush in from Channel 0
  104. echo 0 1 > channels/trigout_attach
  105. echo 1 > channels/trig_filter_enable
  106. }
  107. ctidevs=`find . -name "cti*"`
  108. for i in $ctidevs
  109. do
  110. cd $i
  111. connection=`find . -name "ete*"`
  112. if [ ! -z "$connection" ]
  113. then
  114. echo "AP CTI config for $i"
  115. ap_cti_config
  116. fi
  117. connection=`find . -name "tmc_etf*"`
  118. if [ ! -z "$connection" ]
  119. then
  120. echo "ETF CTI config for $i"
  121. etf_cti_config
  122. fi
  123. connection=`find . -name "tmc_etr*"`
  124. if [ ! -z "$connection" ]
  125. then
  126. echo "ETR CTI config for $i"
  127. etr_cti_config
  128. fi
  129. cd ..
  130. done
  131. Note: CTI connections are SOC specific and hence the above script is
  132. added just for reference.
  133. 4. Choose reserved buffer mode for ETR buffer::
  134. #echo "resrv" > /sys/bus/coresight/devices/tmc_etr0/buf_mode_preferred
  135. 5. Enable stop on flush trigger configuration::
  136. #echo 1 > /sys/bus/coresight/devices/tmc_etr0/stop_on_flush
  137. 6. Start Coresight tracing on cores 1 and 2 using sysfs interface
  138. 7. Run some application on core 1::
  139. #taskset -c 1 dd if=/dev/urandom of=/dev/null &
  140. 8. Invoke kernel panic on core 2::
  141. #echo 1 > /proc/sys/kernel/panic
  142. #taskset -c 2 echo c > /proc/sysrq-trigger
  143. 9. From rebooted kernel or crashdump kernel, read crashdata::
  144. #dd if=/dev/crash_tmc_etr0 of=/trace/cstrace.bin
  145. 10. Run opencsd decoder tools/scripts to generate the instruction trace.
  146. Sample instruction trace dump
  147. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148. Core1 dump::
  149. A etm4_enable_hw: ffff800008ae1dd4
  150. CONTEXT EL2 etm4_enable_hw: ffff800008ae1dd4
  151. I etm4_enable_hw: ffff800008ae1dd4:
  152. d503201f nop
  153. I etm4_enable_hw: ffff800008ae1dd8:
  154. d503201f nop
  155. I etm4_enable_hw: ffff800008ae1ddc:
  156. d503201f nop
  157. I etm4_enable_hw: ffff800008ae1de0:
  158. d503201f nop
  159. I etm4_enable_hw: ffff800008ae1de4:
  160. d503201f nop
  161. I etm4_enable_hw: ffff800008ae1de8:
  162. d503233f paciasp
  163. I etm4_enable_hw: ffff800008ae1dec:
  164. a9be7bfd stp x29, x30, [sp, #-32]!
  165. I etm4_enable_hw: ffff800008ae1df0:
  166. 910003fd mov x29, sp
  167. I etm4_enable_hw: ffff800008ae1df4:
  168. a90153f3 stp x19, x20, [sp, #16]
  169. I etm4_enable_hw: ffff800008ae1df8:
  170. 2a0003f4 mov w20, w0
  171. I etm4_enable_hw: ffff800008ae1dfc:
  172. 900085b3 adrp x19, ffff800009b95000 <reserved_mem+0xc48>
  173. I etm4_enable_hw: ffff800008ae1e00:
  174. 910f4273 add x19, x19, #0x3d0
  175. I etm4_enable_hw: ffff800008ae1e04:
  176. f8747a60 ldr x0, [x19, x20, lsl #3]
  177. E etm4_enable_hw: ffff800008ae1e08:
  178. b4000140 cbz x0, ffff800008ae1e30 <etm4_starting_cpu+0x50>
  179. I 149.039572921 etm4_enable_hw: ffff800008ae1e30:
  180. a94153f3 ldp x19, x20, [sp, #16]
  181. I 149.039572921 etm4_enable_hw: ffff800008ae1e34:
  182. 52800000 mov w0, #0x0 // #0
  183. I 149.039572921 etm4_enable_hw: ffff800008ae1e38:
  184. a8c27bfd ldp x29, x30, [sp], #32
  185. ..snip
  186. 149.052324811 chacha_block_generic: ffff800008642d80:
  187. 9100a3e0 add x0,
  188. I 149.052324811 chacha_block_generic: ffff800008642d84:
  189. b86178a2 ldr w2, [x5, x1, lsl #2]
  190. I 149.052324811 chacha_block_generic: ffff800008642d88:
  191. 8b010803 add x3, x0, x1, lsl #2
  192. I 149.052324811 chacha_block_generic: ffff800008642d8c:
  193. b85fc063 ldur w3, [x3, #-4]
  194. I 149.052324811 chacha_block_generic: ffff800008642d90:
  195. 0b030042 add w2, w2, w3
  196. I 149.052324811 chacha_block_generic: ffff800008642d94:
  197. b8217882 str w2, [x4, x1, lsl #2]
  198. I 149.052324811 chacha_block_generic: ffff800008642d98:
  199. 91000421 add x1, x1, #0x1
  200. I 149.052324811 chacha_block_generic: ffff800008642d9c:
  201. f100443f cmp x1, #0x11
  202. Core 2 dump::
  203. A etm4_enable_hw: ffff800008ae1dd4
  204. CONTEXT EL2 etm4_enable_hw: ffff800008ae1dd4
  205. I etm4_enable_hw: ffff800008ae1dd4:
  206. d503201f nop
  207. I etm4_enable_hw: ffff800008ae1dd8:
  208. d503201f nop
  209. I etm4_enable_hw: ffff800008ae1ddc:
  210. d503201f nop
  211. I etm4_enable_hw: ffff800008ae1de0:
  212. d503201f nop
  213. I etm4_enable_hw: ffff800008ae1de4:
  214. d503201f nop
  215. I etm4_enable_hw: ffff800008ae1de8:
  216. d503233f paciasp
  217. I etm4_enable_hw: ffff800008ae1dec:
  218. a9be7bfd stp x29, x30, [sp, #-32]!
  219. I etm4_enable_hw: ffff800008ae1df0:
  220. 910003fd mov x29, sp
  221. I etm4_enable_hw: ffff800008ae1df4:
  222. a90153f3 stp x19, x20, [sp, #16]
  223. I etm4_enable_hw: ffff800008ae1df8:
  224. 2a0003f4 mov w20, w0
  225. I etm4_enable_hw: ffff800008ae1dfc:
  226. 900085b3 adrp x19, ffff800009b95000 <reserved_mem+0xc48>
  227. I etm4_enable_hw: ffff800008ae1e00:
  228. 910f4273 add x19, x19, #0x3d0
  229. I etm4_enable_hw: ffff800008ae1e04:
  230. f8747a60 ldr x0, [x19, x20, lsl #3]
  231. E etm4_enable_hw: ffff800008ae1e08:
  232. b4000140 cbz x0, ffff800008ae1e30 <etm4_starting_cpu+0x50>
  233. I 149.046243445 etm4_enable_hw: ffff800008ae1e30:
  234. a94153f3 ldp x19, x20, [sp, #16]
  235. I 149.046243445 etm4_enable_hw: ffff800008ae1e34:
  236. 52800000 mov w0, #0x0 // #0
  237. I 149.046243445 etm4_enable_hw: ffff800008ae1e38:
  238. a8c27bfd ldp x29, x30, [sp], #32
  239. I 149.046243445 etm4_enable_hw: ffff800008ae1e3c:
  240. d50323bf autiasp
  241. E 149.046243445 etm4_enable_hw: ffff800008ae1e40:
  242. d65f03c0 ret
  243. A ete_sysreg_write: ffff800008adfa18
  244. ..snip
  245. I 149.05422547 panic: ffff800008096300:
  246. a90363f7 stp x23, x24, [sp, #48]
  247. I 149.05422547 panic: ffff800008096304:
  248. 6b00003f cmp w1, w0
  249. I 149.05422547 panic: ffff800008096308:
  250. 3a411804 ccmn w0, #0x1, #0x4, ne // ne = any
  251. N 149.05422547 panic: ffff80000809630c:
  252. 540001e0 b.eq ffff800008096348 <panic+0xe0> // b.none
  253. I 149.05422547 panic: ffff800008096310:
  254. f90023f9 str x25, [sp, #64]
  255. E 149.05422547 panic: ffff800008096314:
  256. 97fe44ef bl ffff8000080276d0 <panic_smp_self_stop>
  257. A panic: ffff80000809634c
  258. I 149.05422547 panic: ffff80000809634c:
  259. 910102d5 add x21, x22, #0x40
  260. I 149.05422547 panic: ffff800008096350:
  261. 52800020 mov w0, #0x1 // #1
  262. E 149.05422547 panic: ffff800008096354:
  263. 94166b8b bl ffff800008631180 <bust_spinlocks>
  264. N 149.054225518 bust_spinlocks: ffff800008631180:
  265. 340000c0 cbz w0, ffff800008631198 <bust_spinlocks+0x18>
  266. I 149.054225518 bust_spinlocks: ffff800008631184:
  267. f000a321 adrp x1, ffff800009a98000 <pbufs.0+0xbb8>
  268. I 149.054225518 bust_spinlocks: ffff800008631188:
  269. b9405c20 ldr w0, [x1, #92]
  270. I 149.054225518 bust_spinlocks: ffff80000863118c:
  271. 11000400 add w0, w0, #0x1
  272. I 149.054225518 bust_spinlocks: ffff800008631190:
  273. b9005c20 str w0, [x1, #92]
  274. E 149.054225518 bust_spinlocks: ffff800008631194:
  275. d65f03c0 ret
  276. A panic: ffff800008096358
  277. Perf based testing
  278. ------------------
  279. Starting perf session
  280. ~~~~~~~~~~~~~~~~~~~~~
  281. ETF::
  282. perf record -e cs_etm/panicstop,@tmc_etf1/ -C 1
  283. perf record -e cs_etm/panicstop,@tmc_etf2/ -C 2
  284. ETR::
  285. perf record -e cs_etm/panicstop,@tmc_etr0/ -C 1,2
  286. Reading trace data after panic
  287. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  288. Same sysfs based method explained above can be used to retrieve and
  289. decode the trace data after the reboot on kernel panic.