blob: a60a96218ba9032ca11667859d1a9d4d35771e10 [file] [log] [blame]
Sergiu Iordache4126dac2011-08-13 12:34:56 -07001Ramoops oops/panic logger
2=========================
3
4Sergiu Iordache <sergiu@chromium.org>
5
Kees Cook9ba80d92012-05-03 15:45:02 +10006Updated: 17 November 2011
Sergiu Iordache4126dac2011-08-13 12:34:56 -07007
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -03008Introduction
9------------
Sergiu Iordache4126dac2011-08-13 12:34:56 -070010
11Ramoops is an oops/panic logger that writes its logs to RAM before the system
12crashes. It works by logging oopses and panics in a circular buffer. Ramoops
13needs a system with persistent RAM so that the content of that area can
14survive after a restart.
15
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030016Ramoops concepts
17----------------
Sergiu Iordache4126dac2011-08-13 12:34:56 -070018
Tony Lindgren027bc8b2014-09-16 13:50:01 -070019Ramoops uses a predefined memory area to store the dump. The start and size
20and type of the memory area are set using three variables:
Tony Lindgren027bc8b2014-09-16 13:50:01 -070021
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030022 * ``mem_address`` for the start
23 * ``mem_size`` for the size. The memory size will be rounded down to a
24 power of two.
25 * ``mem_type`` to specifiy if the memory type (default is pgprot_writecombine).
26
27Typically the default value of ``mem_type=0`` should be used as that sets the pstore
28mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
29``pgprot_noncached``, which only works on some platforms. This is because pstore
Tony Lindgren027bc8b2014-09-16 13:50:01 -070030depends on atomic operations. At least on ARM, pgprot_noncached causes the
31memory to be mapped strongly ordered, and atomic operations on strongly ordered
32memory are implementation defined, and won't work on many ARMs such as omaps.
Sergiu Iordache4126dac2011-08-13 12:34:56 -070033
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030034The memory area is divided into ``record_size`` chunks (also rounded down to
Kees Cook791205e2020-05-13 14:35:03 -070035power of two) and each kmesg dump writes a ``record_size`` chunk of
Sergiu Iordache4126dac2011-08-13 12:34:56 -070036information.
37
Kees Cook791205e2020-05-13 14:35:03 -070038Limiting which kinds of kmsg dumps are stored can be controlled via
39the ``max_reason`` value, as defined in include/linux/kmsg_dump.h's
40``enum kmsg_dump_reason``. For example, to store both Oopses and Panics,
41``max_reason`` should be set to 2 (KMSG_DUMP_OOPS), to store only Panics
42``max_reason`` should be set to 1 (KMSG_DUMP_PANIC). Setting this to 0
43(KMSG_DUMP_UNDEF), means the reason filtering will be controlled by the
44``printk.always_kmsg_dump`` boot param: if unset, it'll be KMSG_DUMP_OOPS,
45otherwise KMSG_DUMP_MAX.
Sergiu Iordache4126dac2011-08-13 12:34:56 -070046
47The module uses a counter to record multiple dumps but the counter gets reset
48on restart (i.e. new dumps after the restart will overwrite old ones).
49
Anton Vorontsov39eb7e972012-05-17 00:15:34 -070050Ramoops also supports software ECC protection of persistent memory regions.
51This might be useful when a hardware reset was used to bring the machine back
52to life (i.e. a watchdog triggered). In such cases, RAM may be somewhat
53corrupt, but usually it is restorable.
54
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030055Setting the parameters
56----------------------
Sergiu Iordache4126dac2011-08-13 12:34:56 -070057
Kees Cook529182e2016-07-29 18:11:32 -070058Setting the ramoops parameters can be done in several different manners:
59
60 A. Use the module parameters (which have the names of the variables described
61 as before). For quick debugging, you can also reserve parts of memory during
62 boot and then use the reserved memory for ramoops. For example, assuming a
63 machine with > 128 MB of memory, the following kernel command line will tell
64 the kernel to use only the first 128 MB of memory, and place ECC-protected
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030065 ramoops region at 128 MB boundary::
66
67 mem=128M ramoops.mem_address=0x8000000 ramoops.ecc=1
Kees Cook529182e2016-07-29 18:11:32 -070068
69 B. Use Device Tree bindings, as described in
Mauro Carvalho Chehabb971a902018-05-09 10:18:50 -030070 ``Documentation/devicetree/bindings/reserved-memory/ramoops.txt``.
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030071 For example::
Kees Cook529182e2016-07-29 18:11:32 -070072
73 reserved-memory {
74 #address-cells = <2>;
75 #size-cells = <2>;
76 ranges;
77
78 ramoops@8f000000 {
79 compatible = "ramoops";
80 reg = <0 0x8f000000 0 0x100000>;
81 record-size = <0x4000>;
82 console-size = <0x4000>;
83 };
84 };
85
86 C. Use a platform device and set the platform data. The parameters can then
Jani Nikula07a37ba2016-11-03 11:43:29 +020087 be set through that platform data. An example of doing that is:
88
89 .. code-block:: c
Sergiu Iordache4126dac2011-08-13 12:34:56 -070090
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030091 #include <linux/pstore_ram.h>
92 [...]
Sergiu Iordache4126dac2011-08-13 12:34:56 -070093
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -030094 static struct ramoops_platform_data ramoops_data = {
Sergiu Iordache4126dac2011-08-13 12:34:56 -070095 .mem_size = <...>,
96 .mem_address = <...>,
Tony Lindgren027bc8b2014-09-16 13:50:01 -070097 .mem_type = <...>,
Sergiu Iordache4126dac2011-08-13 12:34:56 -070098 .record_size = <...>,
Kees Cook791205e2020-05-13 14:35:03 -070099 .max_reason = <...>,
Anton Vorontsov39eb7e972012-05-17 00:15:34 -0700100 .ecc = <...>,
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300101 };
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700102
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300103 static struct platform_device ramoops_dev = {
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700104 .name = "ramoops",
105 .dev = {
106 .platform_data = &ramoops_data,
107 },
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300108 };
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700109
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300110 [... inside a function ...]
111 int ret;
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700112
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300113 ret = platform_device_register(&ramoops_dev);
114 if (ret) {
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700115 printk(KERN_ERR "unable to register platform device\n");
116 return ret;
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300117 }
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700118
Anton Vorontsov958502d2012-05-26 06:20:25 -0700119You can specify either RAM memory or peripheral devices' memory. However, when
120specifying RAM, be sure to reserve the memory by issuing memblock_reserve()
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300121very early in the architecture code, e.g.::
Anton Vorontsov958502d2012-05-26 06:20:25 -0700122
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300123 #include <linux/memblock.h>
Anton Vorontsov958502d2012-05-26 06:20:25 -0700124
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300125 memblock_reserve(ramoops_data.mem_address, ramoops_data.mem_size);
Anton Vorontsov958502d2012-05-26 06:20:25 -0700126
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300127Dump format
128-----------
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700129
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300130The data dump begins with a header, currently defined as ``====`` followed by a
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700131timestamp and a new line. The dump then continues with the actual data.
132
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300133Reading the data
134----------------
Sergiu Iordache4126dac2011-08-13 12:34:56 -0700135
Kees Cook9ba80d92012-05-03 15:45:02 +1000136The dump data can be read from the pstore filesystem. The format for these
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300137files is ``dmesg-ramoops-N``, where N is the record number in memory. To delete
Kees Cook9ba80d92012-05-03 15:45:02 +1000138a stored record from RAM, simply unlink the respective pstore file.
Anton Vorontsova694d1b2012-07-09 17:10:44 -0700139
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300140Persistent function tracing
141---------------------------
Anton Vorontsova694d1b2012-07-09 17:10:44 -0700142
143Persistent function tracing might be useful for debugging software or hardware
Mauro Carvalho Chehabb2777b62016-09-23 15:24:07 -0300144related hangs. The functions call chain log is stored in a ``ftrace-ramoops``
145file. Here is an example of usage::
Anton Vorontsova694d1b2012-07-09 17:10:44 -0700146
147 # mount -t debugfs debugfs /sys/kernel/debug/
Anton Vorontsov65f8c952012-07-17 14:26:15 -0700148 # echo 1 > /sys/kernel/debug/pstore/record_ftrace
Anton Vorontsova694d1b2012-07-09 17:10:44 -0700149 # reboot -f
150 [...]
151 # mount -t pstore pstore /mnt/
152 # tail /mnt/ftrace-ramoops
153 0 ffffffff8101ea64 ffffffff8101bcda native_apic_mem_read <- disconnect_bsp_APIC+0x6a/0xc0
154 0 ffffffff8101ea44 ffffffff8101bcf6 native_apic_mem_write <- disconnect_bsp_APIC+0x86/0xc0
155 0 ffffffff81020084 ffffffff8101a4b5 hpet_disable <- native_machine_shutdown+0x75/0x90
156 0 ffffffff81005f94 ffffffff8101a4bb iommu_shutdown_noop <- native_machine_shutdown+0x7b/0x90
157 0 ffffffff8101a6a1 ffffffff8101a437 native_machine_emergency_restart <- native_machine_restart+0x37/0x40
158 0 ffffffff811f9876 ffffffff8101a73a acpi_reboot <- native_machine_emergency_restart+0xaa/0x1e0
159 0 ffffffff8101a514 ffffffff8101a772 mach_reboot_fixups <- native_machine_emergency_restart+0xe2/0x1e0
160 0 ffffffff811d9c54 ffffffff8101a7a0 __const_udelay <- native_machine_emergency_restart+0x110/0x1e0
161 0 ffffffff811d9c34 ffffffff811d9c80 __delay <- __const_udelay+0x30/0x40
162 0 ffffffff811d9d14 ffffffff811d9c3f delay_tsc <- __delay+0xf/0x20