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