xref: /OK3568_Linux_fs/kernel/Documentation/admin-guide/ramoops.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunRamoops oops/panic logger
2*4882a593Smuzhiyun=========================
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunSergiu Iordache <sergiu@chromium.org>
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunUpdated: 10 Feb 2021
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunIntroduction
9*4882a593Smuzhiyun------------
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunRamoops is an oops/panic logger that writes its logs to RAM before the system
12*4882a593Smuzhiyuncrashes. It works by logging oopses and panics in a circular buffer. Ramoops
13*4882a593Smuzhiyunneeds a system with persistent RAM so that the content of that area can
14*4882a593Smuzhiyunsurvive after a restart.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunRamoops concepts
17*4882a593Smuzhiyun----------------
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunRamoops uses a predefined memory area to store the dump. The start and size
20*4882a593Smuzhiyunand type of the memory area are set using three variables:
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun  * ``mem_address`` for the start
23*4882a593Smuzhiyun  * ``mem_size`` for the size. The memory size will be rounded down to a
24*4882a593Smuzhiyun    power of two.
25*4882a593Smuzhiyun  * ``mem_type`` to specifiy if the memory type (default is pgprot_writecombine).
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunTypically the default value of ``mem_type=0`` should be used as that sets the pstore
28*4882a593Smuzhiyunmapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
29*4882a593Smuzhiyun``pgprot_noncached``, which only works on some platforms. This is because pstore
30*4882a593Smuzhiyundepends on atomic operations. At least on ARM, pgprot_noncached causes the
31*4882a593Smuzhiyunmemory to be mapped strongly ordered, and atomic operations on strongly ordered
32*4882a593Smuzhiyunmemory are implementation defined, and won't work on many ARMs such as omaps.
33*4882a593SmuzhiyunSetting ``mem_type=2`` attempts to treat the memory region as normal memory,
34*4882a593Smuzhiyunwhich enables full cache on it. This can improve the performance.
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunThe memory area is divided into ``record_size`` chunks (also rounded down to
37*4882a593Smuzhiyunpower of two) and each kmesg dump writes a ``record_size`` chunk of
38*4882a593Smuzhiyuninformation.
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunLimiting which kinds of kmsg dumps are stored can be controlled via
41*4882a593Smuzhiyunthe ``max_reason`` value, as defined in include/linux/kmsg_dump.h's
42*4882a593Smuzhiyun``enum kmsg_dump_reason``. For example, to store both Oopses and Panics,
43*4882a593Smuzhiyun``max_reason`` should be set to 2 (KMSG_DUMP_OOPS), to store only Panics
44*4882a593Smuzhiyun``max_reason`` should be set to 1 (KMSG_DUMP_PANIC). Setting this to 0
45*4882a593Smuzhiyun(KMSG_DUMP_UNDEF), means the reason filtering will be controlled by the
46*4882a593Smuzhiyun``printk.always_kmsg_dump`` boot param: if unset, it'll be KMSG_DUMP_OOPS,
47*4882a593Smuzhiyunotherwise KMSG_DUMP_MAX.
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunThe module uses a counter to record multiple dumps but the counter gets reset
50*4882a593Smuzhiyunon restart (i.e. new dumps after the restart will overwrite old ones).
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunRamoops also supports software ECC protection of persistent memory regions.
53*4882a593SmuzhiyunThis might be useful when a hardware reset was used to bring the machine back
54*4882a593Smuzhiyunto life (i.e. a watchdog triggered). In such cases, RAM may be somewhat
55*4882a593Smuzhiyuncorrupt, but usually it is restorable.
56*4882a593Smuzhiyun
57*4882a593SmuzhiyunSetting the parameters
58*4882a593Smuzhiyun----------------------
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunSetting the ramoops parameters can be done in several different manners:
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun A. Use the module parameters (which have the names of the variables described
63*4882a593Smuzhiyun as before). For quick debugging, you can also reserve parts of memory during
64*4882a593Smuzhiyun boot and then use the reserved memory for ramoops. For example, assuming a
65*4882a593Smuzhiyun machine with > 128 MB of memory, the following kernel command line will tell
66*4882a593Smuzhiyun the kernel to use only the first 128 MB of memory, and place ECC-protected
67*4882a593Smuzhiyun ramoops region at 128 MB boundary::
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun	mem=128M ramoops.mem_address=0x8000000 ramoops.ecc=1
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun B. Use Device Tree bindings, as described in
72*4882a593Smuzhiyun ``Documentation/devicetree/bindings/reserved-memory/ramoops.txt``.
73*4882a593Smuzhiyun For example::
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun	reserved-memory {
76*4882a593Smuzhiyun		#address-cells = <2>;
77*4882a593Smuzhiyun		#size-cells = <2>;
78*4882a593Smuzhiyun		ranges;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun		ramoops@8f000000 {
81*4882a593Smuzhiyun			compatible = "ramoops";
82*4882a593Smuzhiyun			reg = <0 0x8f000000 0 0x100000>;
83*4882a593Smuzhiyun			record-size = <0x4000>;
84*4882a593Smuzhiyun			console-size = <0x4000>;
85*4882a593Smuzhiyun		};
86*4882a593Smuzhiyun	};
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun C. Use a platform device and set the platform data. The parameters can then
89*4882a593Smuzhiyun be set through that platform data. An example of doing that is:
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun .. code-block:: c
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun  #include <linux/pstore_ram.h>
94*4882a593Smuzhiyun  [...]
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun  static struct ramoops_platform_data ramoops_data = {
97*4882a593Smuzhiyun        .mem_size               = <...>,
98*4882a593Smuzhiyun        .mem_address            = <...>,
99*4882a593Smuzhiyun        .mem_type               = <...>,
100*4882a593Smuzhiyun        .record_size            = <...>,
101*4882a593Smuzhiyun        .max_reason             = <...>,
102*4882a593Smuzhiyun        .ecc                    = <...>,
103*4882a593Smuzhiyun  };
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun  static struct platform_device ramoops_dev = {
106*4882a593Smuzhiyun        .name = "ramoops",
107*4882a593Smuzhiyun        .dev = {
108*4882a593Smuzhiyun                .platform_data = &ramoops_data,
109*4882a593Smuzhiyun        },
110*4882a593Smuzhiyun  };
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun  [... inside a function ...]
113*4882a593Smuzhiyun  int ret;
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun  ret = platform_device_register(&ramoops_dev);
116*4882a593Smuzhiyun  if (ret) {
117*4882a593Smuzhiyun	printk(KERN_ERR "unable to register platform device\n");
118*4882a593Smuzhiyun	return ret;
119*4882a593Smuzhiyun  }
120*4882a593Smuzhiyun
121*4882a593SmuzhiyunYou can specify either RAM memory or peripheral devices' memory. However, when
122*4882a593Smuzhiyunspecifying RAM, be sure to reserve the memory by issuing memblock_reserve()
123*4882a593Smuzhiyunvery early in the architecture code, e.g.::
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun	#include <linux/memblock.h>
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun	memblock_reserve(ramoops_data.mem_address, ramoops_data.mem_size);
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunDump format
130*4882a593Smuzhiyun-----------
131*4882a593Smuzhiyun
132*4882a593SmuzhiyunThe data dump begins with a header, currently defined as ``====`` followed by a
133*4882a593Smuzhiyuntimestamp and a new line. The dump then continues with the actual data.
134*4882a593Smuzhiyun
135*4882a593SmuzhiyunReading the data
136*4882a593Smuzhiyun----------------
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunThe dump data can be read from the pstore filesystem. The format for these
139*4882a593Smuzhiyunfiles is ``dmesg-ramoops-N``, where N is the record number in memory. To delete
140*4882a593Smuzhiyuna stored record from RAM, simply unlink the respective pstore file.
141*4882a593Smuzhiyun
142*4882a593SmuzhiyunPersistent function tracing
143*4882a593Smuzhiyun---------------------------
144*4882a593Smuzhiyun
145*4882a593SmuzhiyunPersistent function tracing might be useful for debugging software or hardware
146*4882a593Smuzhiyunrelated hangs. The functions call chain log is stored in a ``ftrace-ramoops``
147*4882a593Smuzhiyunfile. Here is an example of usage::
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun # mount -t debugfs debugfs /sys/kernel/debug/
150*4882a593Smuzhiyun # echo 1 > /sys/kernel/debug/pstore/record_ftrace
151*4882a593Smuzhiyun # reboot -f
152*4882a593Smuzhiyun [...]
153*4882a593Smuzhiyun # mount -t pstore pstore /mnt/
154*4882a593Smuzhiyun # tail /mnt/ftrace-ramoops
155*4882a593Smuzhiyun 0 ffffffff8101ea64  ffffffff8101bcda  native_apic_mem_read <- disconnect_bsp_APIC+0x6a/0xc0
156*4882a593Smuzhiyun 0 ffffffff8101ea44  ffffffff8101bcf6  native_apic_mem_write <- disconnect_bsp_APIC+0x86/0xc0
157*4882a593Smuzhiyun 0 ffffffff81020084  ffffffff8101a4b5  hpet_disable <- native_machine_shutdown+0x75/0x90
158*4882a593Smuzhiyun 0 ffffffff81005f94  ffffffff8101a4bb  iommu_shutdown_noop <- native_machine_shutdown+0x7b/0x90
159*4882a593Smuzhiyun 0 ffffffff8101a6a1  ffffffff8101a437  native_machine_emergency_restart <- native_machine_restart+0x37/0x40
160*4882a593Smuzhiyun 0 ffffffff811f9876  ffffffff8101a73a  acpi_reboot <- native_machine_emergency_restart+0xaa/0x1e0
161*4882a593Smuzhiyun 0 ffffffff8101a514  ffffffff8101a772  mach_reboot_fixups <- native_machine_emergency_restart+0xe2/0x1e0
162*4882a593Smuzhiyun 0 ffffffff811d9c54  ffffffff8101a7a0  __const_udelay <- native_machine_emergency_restart+0x110/0x1e0
163*4882a593Smuzhiyun 0 ffffffff811d9c34  ffffffff811d9c80  __delay <- __const_udelay+0x30/0x40
164*4882a593Smuzhiyun 0 ffffffff811d9d14  ffffffff811d9c3f  delay_tsc <- __delay+0xf/0x20
165