2011-08-13 23:34:56 +04:00
|
|
|
Ramoops oops/panic logger
|
|
|
|
=========================
|
|
|
|
|
|
|
|
Sergiu Iordache <sergiu@chromium.org>
|
|
|
|
|
2021-03-22 21:42:17 +03:00
|
|
|
Updated: 10 Feb 2021
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
Introduction
|
|
|
|
------------
|
2011-08-13 23:34:56 +04:00
|
|
|
|
|
|
|
Ramoops is an oops/panic logger that writes its logs to RAM before the system
|
|
|
|
crashes. It works by logging oopses and panics in a circular buffer. Ramoops
|
|
|
|
needs a system with persistent RAM so that the content of that area can
|
|
|
|
survive after a restart.
|
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
Ramoops concepts
|
|
|
|
----------------
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2014-09-17 00:50:01 +04:00
|
|
|
Ramoops uses a predefined memory area to store the dump. The start and size
|
|
|
|
and type of the memory area are set using three variables:
|
2016-09-23 21:24:07 +03:00
|
|
|
|
|
|
|
* ``mem_address`` for the start
|
|
|
|
* ``mem_size`` for the size. The memory size will be rounded down to a
|
|
|
|
power of two.
|
Documentation: fix multiple typos found in the admin-guide subdirectory
Fix thirty five typos in dm-integrity.rst, dm-raid.rst, dm-zoned.rst,
verity.rst, writecache.rst, tsx_async_abort.rst, md.rst, bttv.rst,
dvb_references.rst, frontend-cardlist.rst, gspca-cardlist.rst, ipu3.rst,
remote-controller.rst, mm/index.rst, numaperf.rst, userfaultfd.rst,
module-signing.rst, imx-ddr.rst, intel-speed-select.rst,
intel_pstate.rst, ramoops.rst, abi.rst, kernel.rst, vm.rst
Signed-off-by: Andrew Klychkov <andrew.a.klychkov@gmail.com>
Link: https://lore.kernel.org/r/20201204072848.GA49895@spblnx124.lan
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
2020-12-04 10:28:48 +03:00
|
|
|
* ``mem_type`` to specify if the memory type (default is pgprot_writecombine).
|
2016-09-23 21:24:07 +03:00
|
|
|
|
|
|
|
Typically the default value of ``mem_type=0`` should be used as that sets the pstore
|
|
|
|
mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
|
|
|
|
``pgprot_noncached``, which only works on some platforms. This is because pstore
|
2014-09-17 00:50:01 +04:00
|
|
|
depends on atomic operations. At least on ARM, pgprot_noncached causes the
|
|
|
|
memory to be mapped strongly ordered, and atomic operations on strongly ordered
|
|
|
|
memory are implementation defined, and won't work on many ARMs such as omaps.
|
2021-03-22 21:42:17 +03:00
|
|
|
Setting ``mem_type=2`` attempts to treat the memory region as normal memory,
|
|
|
|
which enables full cache on it. This can improve the performance.
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
The memory area is divided into ``record_size`` chunks (also rounded down to
|
2020-05-14 00:35:03 +03:00
|
|
|
power of two) and each kmesg dump writes a ``record_size`` chunk of
|
2011-08-13 23:34:56 +04:00
|
|
|
information.
|
|
|
|
|
2020-05-14 00:35:03 +03:00
|
|
|
Limiting which kinds of kmsg dumps are stored can be controlled via
|
|
|
|
the ``max_reason`` value, as defined in include/linux/kmsg_dump.h's
|
|
|
|
``enum kmsg_dump_reason``. For example, to store both Oopses and Panics,
|
|
|
|
``max_reason`` should be set to 2 (KMSG_DUMP_OOPS), to store only Panics
|
|
|
|
``max_reason`` should be set to 1 (KMSG_DUMP_PANIC). Setting this to 0
|
|
|
|
(KMSG_DUMP_UNDEF), means the reason filtering will be controlled by the
|
|
|
|
``printk.always_kmsg_dump`` boot param: if unset, it'll be KMSG_DUMP_OOPS,
|
|
|
|
otherwise KMSG_DUMP_MAX.
|
2011-08-13 23:34:56 +04:00
|
|
|
|
|
|
|
The module uses a counter to record multiple dumps but the counter gets reset
|
|
|
|
on restart (i.e. new dumps after the restart will overwrite old ones).
|
|
|
|
|
2012-05-17 11:15:34 +04:00
|
|
|
Ramoops also supports software ECC protection of persistent memory regions.
|
|
|
|
This might be useful when a hardware reset was used to bring the machine back
|
|
|
|
to life (i.e. a watchdog triggered). In such cases, RAM may be somewhat
|
|
|
|
corrupt, but usually it is restorable.
|
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
Setting the parameters
|
|
|
|
----------------------
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-07-30 04:11:32 +03:00
|
|
|
Setting the ramoops parameters can be done in several different manners:
|
|
|
|
|
|
|
|
A. Use the module parameters (which have the names of the variables described
|
|
|
|
as before). For quick debugging, you can also reserve parts of memory during
|
|
|
|
boot and then use the reserved memory for ramoops. For example, assuming a
|
|
|
|
machine with > 128 MB of memory, the following kernel command line will tell
|
|
|
|
the kernel to use only the first 128 MB of memory, and place ECC-protected
|
2016-09-23 21:24:07 +03:00
|
|
|
ramoops region at 128 MB boundary::
|
|
|
|
|
|
|
|
mem=128M ramoops.mem_address=0x8000000 ramoops.ecc=1
|
2016-07-30 04:11:32 +03:00
|
|
|
|
|
|
|
B. Use Device Tree bindings, as described in
|
2018-05-09 16:18:50 +03:00
|
|
|
``Documentation/devicetree/bindings/reserved-memory/ramoops.txt``.
|
2016-09-23 21:24:07 +03:00
|
|
|
For example::
|
2016-07-30 04:11:32 +03:00
|
|
|
|
|
|
|
reserved-memory {
|
|
|
|
#address-cells = <2>;
|
|
|
|
#size-cells = <2>;
|
|
|
|
ranges;
|
|
|
|
|
|
|
|
ramoops@8f000000 {
|
|
|
|
compatible = "ramoops";
|
|
|
|
reg = <0 0x8f000000 0 0x100000>;
|
|
|
|
record-size = <0x4000>;
|
|
|
|
console-size = <0x4000>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
C. Use a platform device and set the platform data. The parameters can then
|
2016-11-03 12:43:29 +03:00
|
|
|
be set through that platform data. An example of doing that is:
|
|
|
|
|
|
|
|
.. code-block:: c
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
#include <linux/pstore_ram.h>
|
|
|
|
[...]
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
static struct ramoops_platform_data ramoops_data = {
|
2011-08-13 23:34:56 +04:00
|
|
|
.mem_size = <...>,
|
|
|
|
.mem_address = <...>,
|
2014-09-17 00:50:01 +04:00
|
|
|
.mem_type = <...>,
|
2011-08-13 23:34:56 +04:00
|
|
|
.record_size = <...>,
|
2020-05-14 00:35:03 +03:00
|
|
|
.max_reason = <...>,
|
2012-05-17 11:15:34 +04:00
|
|
|
.ecc = <...>,
|
2016-09-23 21:24:07 +03:00
|
|
|
};
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
static struct platform_device ramoops_dev = {
|
2011-08-13 23:34:56 +04:00
|
|
|
.name = "ramoops",
|
|
|
|
.dev = {
|
|
|
|
.platform_data = &ramoops_data,
|
|
|
|
},
|
2016-09-23 21:24:07 +03:00
|
|
|
};
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
[... inside a function ...]
|
|
|
|
int ret;
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
ret = platform_device_register(&ramoops_dev);
|
|
|
|
if (ret) {
|
2011-08-13 23:34:56 +04:00
|
|
|
printk(KERN_ERR "unable to register platform device\n");
|
|
|
|
return ret;
|
2016-09-23 21:24:07 +03:00
|
|
|
}
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2012-05-26 17:20:25 +04:00
|
|
|
You can specify either RAM memory or peripheral devices' memory. However, when
|
|
|
|
specifying RAM, be sure to reserve the memory by issuing memblock_reserve()
|
2016-09-23 21:24:07 +03:00
|
|
|
very early in the architecture code, e.g.::
|
2012-05-26 17:20:25 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
#include <linux/memblock.h>
|
2012-05-26 17:20:25 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
memblock_reserve(ramoops_data.mem_address, ramoops_data.mem_size);
|
2012-05-26 17:20:25 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
Dump format
|
|
|
|
-----------
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
The data dump begins with a header, currently defined as ``====`` followed by a
|
2011-08-13 23:34:56 +04:00
|
|
|
timestamp and a new line. The dump then continues with the actual data.
|
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
Reading the data
|
|
|
|
----------------
|
2011-08-13 23:34:56 +04:00
|
|
|
|
2012-05-03 09:45:02 +04:00
|
|
|
The dump data can be read from the pstore filesystem. The format for these
|
2016-09-23 21:24:07 +03:00
|
|
|
files is ``dmesg-ramoops-N``, where N is the record number in memory. To delete
|
2012-05-03 09:45:02 +04:00
|
|
|
a stored record from RAM, simply unlink the respective pstore file.
|
2012-07-10 04:10:44 +04:00
|
|
|
|
2016-09-23 21:24:07 +03:00
|
|
|
Persistent function tracing
|
|
|
|
---------------------------
|
2012-07-10 04:10:44 +04:00
|
|
|
|
|
|
|
Persistent function tracing might be useful for debugging software or hardware
|
2016-09-23 21:24:07 +03:00
|
|
|
related hangs. The functions call chain log is stored in a ``ftrace-ramoops``
|
|
|
|
file. Here is an example of usage::
|
2012-07-10 04:10:44 +04:00
|
|
|
|
|
|
|
# mount -t debugfs debugfs /sys/kernel/debug/
|
pstore/ftrace: Convert to its own enable/disable debugfs knob
With this patch we no longer reuse function tracer infrastructure, now
we register our own tracer back-end via a debugfs knob.
It's a bit more code, but that is the only downside. On the bright side we
have:
- Ability to make persistent_ram module removable (when needed, we can
move ftrace_ops struct into a module). Note that persistent_ram is still
not removable for other reasons, but with this patch it's just one
thing less to worry about;
- Pstore part is more isolated from the generic function tracer. We tried
it already by registering our own tracer in available_tracers, but that
way we're loosing ability to see the traces while we record them to
pstore. This solution is somewhere in the middle: we only register
"internal ftracer" back-end, but not the "front-end";
- When there is only pstore tracing enabled, the kernel will only write
to the pstore buffer, omitting function tracer buffer (which, of course,
still can be enabled via 'echo function > current_tracer').
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
2012-07-18 01:26:15 +04:00
|
|
|
# echo 1 > /sys/kernel/debug/pstore/record_ftrace
|
2012-07-10 04:10:44 +04:00
|
|
|
# reboot -f
|
|
|
|
[...]
|
|
|
|
# mount -t pstore pstore /mnt/
|
|
|
|
# tail /mnt/ftrace-ramoops
|
|
|
|
0 ffffffff8101ea64 ffffffff8101bcda native_apic_mem_read <- disconnect_bsp_APIC+0x6a/0xc0
|
|
|
|
0 ffffffff8101ea44 ffffffff8101bcf6 native_apic_mem_write <- disconnect_bsp_APIC+0x86/0xc0
|
|
|
|
0 ffffffff81020084 ffffffff8101a4b5 hpet_disable <- native_machine_shutdown+0x75/0x90
|
|
|
|
0 ffffffff81005f94 ffffffff8101a4bb iommu_shutdown_noop <- native_machine_shutdown+0x7b/0x90
|
|
|
|
0 ffffffff8101a6a1 ffffffff8101a437 native_machine_emergency_restart <- native_machine_restart+0x37/0x40
|
|
|
|
0 ffffffff811f9876 ffffffff8101a73a acpi_reboot <- native_machine_emergency_restart+0xaa/0x1e0
|
|
|
|
0 ffffffff8101a514 ffffffff8101a772 mach_reboot_fixups <- native_machine_emergency_restart+0xe2/0x1e0
|
|
|
|
0 ffffffff811d9c54 ffffffff8101a7a0 __const_udelay <- native_machine_emergency_restart+0x110/0x1e0
|
|
|
|
0 ffffffff811d9c34 ffffffff811d9c80 __delay <- __const_udelay+0x30/0x40
|
|
|
|
0 ffffffff811d9d14 ffffffff811d9c3f delay_tsc <- __delay+0xf/0x20
|