xref: /openbmc/linux/Documentation/admin-guide/pstore-blk.rst (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1649304c9SWeiXiong Liao.. SPDX-License-Identifier: GPL-2.0
2649304c9SWeiXiong Liao
3649304c9SWeiXiong Liaopstore block oops/panic logger
4649304c9SWeiXiong Liao==============================
5649304c9SWeiXiong Liao
6649304c9SWeiXiong LiaoIntroduction
7649304c9SWeiXiong Liao------------
8649304c9SWeiXiong Liao
9649304c9SWeiXiong Liaopstore block (pstore/blk) is an oops/panic logger that writes its logs to a
107dcb7848SWeiXiong Liaoblock device and non-block device before the system crashes. You can get
117dcb7848SWeiXiong Liaothese log files by mounting pstore filesystem like::
12649304c9SWeiXiong Liao
13649304c9SWeiXiong Liao    mount -t pstore pstore /sys/fs/pstore
14649304c9SWeiXiong Liao
15649304c9SWeiXiong Liao
16649304c9SWeiXiong Liaopstore block concepts
17649304c9SWeiXiong Liao---------------------
18649304c9SWeiXiong Liao
19649304c9SWeiXiong Liaopstore/blk provides efficient configuration method for pstore/blk, which
20649304c9SWeiXiong Liaodivides all configurations into two parts, configurations for user and
21649304c9SWeiXiong Liaoconfigurations for driver.
22649304c9SWeiXiong Liao
23649304c9SWeiXiong LiaoConfigurations for user determine how pstore/blk works, such as pmsg_size,
24649304c9SWeiXiong Liaokmsg_size and so on. All of them support both Kconfig and module parameters,
25649304c9SWeiXiong Liaobut module parameters have priority over Kconfig.
26649304c9SWeiXiong Liao
277dcb7848SWeiXiong LiaoConfigurations for driver are all about block device and non-block device,
287dcb7848SWeiXiong Liaosuch as total_size of block device and read/write operations.
29649304c9SWeiXiong Liao
30649304c9SWeiXiong LiaoConfigurations for user
31649304c9SWeiXiong Liao-----------------------
32649304c9SWeiXiong Liao
33649304c9SWeiXiong LiaoAll of these configurations support both Kconfig and module parameters, but
34649304c9SWeiXiong Liaomodule parameters have priority over Kconfig.
35649304c9SWeiXiong Liao
36649304c9SWeiXiong LiaoHere is an example for module parameters::
37649304c9SWeiXiong Liao
3845a8af44SChristoph Hellwig        pstore_blk.blkdev=/dev/mmcblk0p7 pstore_blk.kmsg_size=64 best_effort=y
39649304c9SWeiXiong Liao
40649304c9SWeiXiong LiaoThe detail of each configurations may be of interest to you.
41649304c9SWeiXiong Liao
42649304c9SWeiXiong Liaoblkdev
43649304c9SWeiXiong Liao~~~~~~
44649304c9SWeiXiong Liao
45649304c9SWeiXiong LiaoThe block device to use. Most of the time, it is a partition of block device.
4678c08247SWeiXiong LiaoIt's required for pstore/blk. It is also used for MTD device.
47649304c9SWeiXiong Liao
48*c811659bSKees CookWhen pstore/blk is built as a module, "blkdev" accepts the following variants:
49649304c9SWeiXiong Liao
50*c811659bSKees Cook1. /dev/<disk_name> represents the device number of disk
51649304c9SWeiXiong Liao#. /dev/<disk_name><decimal> represents the device number of partition - device
52649304c9SWeiXiong Liao   number of disk plus the partition number
53649304c9SWeiXiong Liao#. /dev/<disk_name>p<decimal> - same as the above; this form is used when disk
54649304c9SWeiXiong Liao   name of partitioned disk ends with a digit.
55*c811659bSKees Cook
56*c811659bSKees CookWhen pstore/blk is built into the kernel, "blkdev" accepts the following variants:
57*c811659bSKees Cook
58*c811659bSKees Cook#. <hex_major><hex_minor> device number in hexadecimal representation,
59*c811659bSKees Cook   with no leading 0x, for example b302.
60649304c9SWeiXiong Liao#. PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF represents the unique id of
61649304c9SWeiXiong Liao   a partition if the partition table provides it. The UUID may be either an
62649304c9SWeiXiong Liao   EFI/GPT UUID, or refer to an MSDOS partition using the format SSSSSSSS-PP,
63649304c9SWeiXiong Liao   where SSSSSSSS is a zero-filled hex representation of the 32-bit
64649304c9SWeiXiong Liao   "NT disk signature", and PP is a zero-filled hex representation of the
65649304c9SWeiXiong Liao   1-based partition number.
66649304c9SWeiXiong Liao#. PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to a
67649304c9SWeiXiong Liao   partition with a known unique id.
68649304c9SWeiXiong Liao#. <major>:<minor> major and minor number of the device separated by a colon.
69649304c9SWeiXiong Liao
7078c08247SWeiXiong LiaoIt accepts the following variants for MTD device:
7178c08247SWeiXiong Liao
7278c08247SWeiXiong Liao1. <device name> MTD device name. "pstore" is recommended.
7378c08247SWeiXiong Liao#. <device number> MTD device number.
7478c08247SWeiXiong Liao
75649304c9SWeiXiong Liaokmsg_size
76649304c9SWeiXiong Liao~~~~~~~~~
77649304c9SWeiXiong Liao
78649304c9SWeiXiong LiaoThe chunk size in KB for oops/panic front-end. It **MUST** be a multiple of 4.
79649304c9SWeiXiong LiaoIt's optional if you do not care oops/panic log.
80649304c9SWeiXiong Liao
81649304c9SWeiXiong LiaoThere are multiple chunks for oops/panic front-end depending on the remaining
82649304c9SWeiXiong Liaospace except other pstore front-ends.
83649304c9SWeiXiong Liao
84649304c9SWeiXiong Liaopstore/blk will log to oops/panic chunks one by one, and always overwrite the
85649304c9SWeiXiong Liaooldest chunk if there is no more free chunk.
86649304c9SWeiXiong Liao
87649304c9SWeiXiong Liaopmsg_size
88649304c9SWeiXiong Liao~~~~~~~~~
89649304c9SWeiXiong Liao
90649304c9SWeiXiong LiaoThe chunk size in KB for pmsg front-end. It **MUST** be a multiple of 4.
91649304c9SWeiXiong LiaoIt's optional if you do not care pmsg log.
92649304c9SWeiXiong Liao
93649304c9SWeiXiong LiaoUnlike oops/panic front-end, there is only one chunk for pmsg front-end.
94649304c9SWeiXiong Liao
95649304c9SWeiXiong LiaoPmsg is a user space accessible pstore object. Writes to */dev/pmsg0* are
96649304c9SWeiXiong Liaoappended to the chunk. On reboot the contents are available in
97649304c9SWeiXiong Liao*/sys/fs/pstore/pmsg-pstore-blk-0*.
98649304c9SWeiXiong Liao
99649304c9SWeiXiong Liaoconsole_size
100649304c9SWeiXiong Liao~~~~~~~~~~~~
101649304c9SWeiXiong Liao
102649304c9SWeiXiong LiaoThe chunk size in KB for console front-end.  It **MUST** be a multiple of 4.
103649304c9SWeiXiong LiaoIt's optional if you do not care console log.
104649304c9SWeiXiong Liao
105649304c9SWeiXiong LiaoSimilar to pmsg front-end, there is only one chunk for console front-end.
106649304c9SWeiXiong Liao
107649304c9SWeiXiong LiaoAll log of console will be appended to the chunk. On reboot the contents are
108649304c9SWeiXiong Liaoavailable in */sys/fs/pstore/console-pstore-blk-0*.
109649304c9SWeiXiong Liao
110649304c9SWeiXiong Liaoftrace_size
111649304c9SWeiXiong Liao~~~~~~~~~~~
112649304c9SWeiXiong Liao
113649304c9SWeiXiong LiaoThe chunk size in KB for ftrace front-end. It **MUST** be a multiple of 4.
114649304c9SWeiXiong LiaoIt's optional if you do not care console log.
115649304c9SWeiXiong Liao
116649304c9SWeiXiong LiaoSimilar to oops front-end, there are multiple chunks for ftrace front-end
117649304c9SWeiXiong Liaodepending on the count of cpu processors. Each chunk size is equal to
118649304c9SWeiXiong Liaoftrace_size / processors_count.
119649304c9SWeiXiong Liao
120649304c9SWeiXiong LiaoAll log of ftrace will be appended to the chunk. On reboot the contents are
121649304c9SWeiXiong Liaocombined and available in */sys/fs/pstore/ftrace-pstore-blk-0*.
122649304c9SWeiXiong Liao
123649304c9SWeiXiong LiaoPersistent function tracing might be useful for debugging software or hardware
124649304c9SWeiXiong Liaorelated hangs. Here is an example of usage::
125649304c9SWeiXiong Liao
126649304c9SWeiXiong Liao # mount -t pstore pstore /sys/fs/pstore
127649304c9SWeiXiong Liao # mount -t debugfs debugfs /sys/kernel/debug/
128649304c9SWeiXiong Liao # echo 1 > /sys/kernel/debug/pstore/record_ftrace
129649304c9SWeiXiong Liao # reboot -f
130649304c9SWeiXiong Liao [...]
131649304c9SWeiXiong Liao # mount -t pstore pstore /sys/fs/pstore
132649304c9SWeiXiong Liao # tail /sys/fs/pstore/ftrace-pstore-blk-0
133649304c9SWeiXiong Liao CPU:0 ts:5914676 c0063828  c0063b94  call_cpuidle <- cpu_startup_entry+0x1b8/0x1e0
134649304c9SWeiXiong Liao CPU:0 ts:5914678 c039ecdc  c006385c  cpuidle_enter_state <- call_cpuidle+0x44/0x48
135649304c9SWeiXiong Liao CPU:0 ts:5914680 c039e9a0  c039ecf0  cpuidle_enter_freeze <- cpuidle_enter_state+0x304/0x314
136649304c9SWeiXiong Liao CPU:0 ts:5914681 c0063870  c039ea30  sched_idle_set_state <- cpuidle_enter_state+0x44/0x314
137649304c9SWeiXiong Liao CPU:1 ts:5916720 c0160f59  c015ee04  kernfs_unmap_bin_file <- __kernfs_remove+0x140/0x204
138649304c9SWeiXiong Liao CPU:1 ts:5916721 c05ca625  c015ee0c  __mutex_lock_slowpath <- __kernfs_remove+0x148/0x204
139649304c9SWeiXiong Liao CPU:1 ts:5916723 c05c813d  c05ca630  yield_to <- __mutex_lock_slowpath+0x314/0x358
140649304c9SWeiXiong Liao CPU:1 ts:5916724 c05ca2d1  c05ca638  __ww_mutex_lock <- __mutex_lock_slowpath+0x31c/0x358
141649304c9SWeiXiong Liao
142649304c9SWeiXiong Liaomax_reason
143649304c9SWeiXiong Liao~~~~~~~~~~
144649304c9SWeiXiong Liao
145649304c9SWeiXiong LiaoLimiting which kinds of kmsg dumps are stored can be controlled via
146649304c9SWeiXiong Liaothe ``max_reason`` value, as defined in include/linux/kmsg_dump.h's
147649304c9SWeiXiong Liao``enum kmsg_dump_reason``. For example, to store both Oopses and Panics,
148649304c9SWeiXiong Liao``max_reason`` should be set to 2 (KMSG_DUMP_OOPS), to store only Panics
149649304c9SWeiXiong Liao``max_reason`` should be set to 1 (KMSG_DUMP_PANIC). Setting this to 0
150649304c9SWeiXiong Liao(KMSG_DUMP_UNDEF), means the reason filtering will be controlled by the
151649304c9SWeiXiong Liao``printk.always_kmsg_dump`` boot param: if unset, it'll be KMSG_DUMP_OOPS,
152649304c9SWeiXiong Liaootherwise KMSG_DUMP_MAX.
153649304c9SWeiXiong Liao
154649304c9SWeiXiong LiaoConfigurations for driver
155649304c9SWeiXiong Liao-------------------------
156649304c9SWeiXiong Liao
157b6f8ed33SChristoph HellwigA device driver uses ``register_pstore_device`` with
1587dcb7848SWeiXiong Liao``struct pstore_device_info`` to register to pstore/blk.
1597dcb7848SWeiXiong Liao
1607dcb7848SWeiXiong Liao.. kernel-doc:: fs/pstore/blk.c
161b30fd8e9SMauro Carvalho Chehab   :export:
1627dcb7848SWeiXiong Liao
163649304c9SWeiXiong LiaoCompression and header
164649304c9SWeiXiong Liao----------------------
165649304c9SWeiXiong Liao
166649304c9SWeiXiong LiaoBlock device is large enough for uncompressed oops data. Actually we do not
167649304c9SWeiXiong Liaorecommend data compression because pstore/blk will insert some information into
168649304c9SWeiXiong Liaothe first line of oops/panic data. For example::
169649304c9SWeiXiong Liao
170649304c9SWeiXiong Liao        Panic: Total 16 times
171649304c9SWeiXiong Liao
172649304c9SWeiXiong LiaoIt means that it's OOPS|Panic for the 16th time since the first booting.
173649304c9SWeiXiong LiaoSometimes the number of occurrences of oops|panic since the first booting is
174649304c9SWeiXiong Liaoimportant to judge whether the system is stable.
175649304c9SWeiXiong Liao
176649304c9SWeiXiong LiaoThe following line is inserted by pstore filesystem. For example::
177649304c9SWeiXiong Liao
178649304c9SWeiXiong Liao        Oops#2 Part1
179649304c9SWeiXiong Liao
180649304c9SWeiXiong LiaoIt means that it's OOPS for the 2nd time on the last boot.
181649304c9SWeiXiong Liao
182649304c9SWeiXiong LiaoReading the data
183649304c9SWeiXiong Liao----------------
184649304c9SWeiXiong Liao
185649304c9SWeiXiong LiaoThe dump data can be read from the pstore filesystem. The format for these
186649304c9SWeiXiong Liaofiles is ``dmesg-pstore-blk-[N]`` for oops/panic front-end,
187649304c9SWeiXiong Liao``pmsg-pstore-blk-0`` for pmsg front-end and so on.  The timestamp of the
188649304c9SWeiXiong Liaodump file records the trigger time. To delete a stored record from block
189649304c9SWeiXiong Liaodevice, simply unlink the respective pstore file.
190649304c9SWeiXiong Liao
191649304c9SWeiXiong LiaoAttentions in panic read/write APIs
192649304c9SWeiXiong Liao-----------------------------------
193649304c9SWeiXiong Liao
194649304c9SWeiXiong LiaoIf on panic, the kernel is not going to run for much longer, the tasks will not
195649304c9SWeiXiong Liaobe scheduled and most kernel resources will be out of service. It
196649304c9SWeiXiong Liaolooks like a single-threaded program running on a single-core computer.
197649304c9SWeiXiong Liao
198649304c9SWeiXiong LiaoThe following points require special attention for panic read/write APIs:
199649304c9SWeiXiong Liao
200649304c9SWeiXiong Liao1. Can **NOT** allocate any memory.
201649304c9SWeiXiong Liao   If you need memory, just allocate while the block driver is initializing
202649304c9SWeiXiong Liao   rather than waiting until the panic.
203649304c9SWeiXiong Liao#. Must be polled, **NOT** interrupt driven.
204649304c9SWeiXiong Liao   No task schedule any more. The block driver should delay to ensure the write
205649304c9SWeiXiong Liao   succeeds, but NOT sleep.
206649304c9SWeiXiong Liao#. Can **NOT** take any lock.
207649304c9SWeiXiong Liao   There is no other task, nor any shared resource; you are safe to break all
208649304c9SWeiXiong Liao   locks.
209649304c9SWeiXiong Liao#. Just use CPU to transfer.
210649304c9SWeiXiong Liao   Do not use DMA to transfer unless you are sure that DMA will not keep lock.
211649304c9SWeiXiong Liao#. Control registers directly.
212649304c9SWeiXiong Liao   Please control registers directly rather than use Linux kernel resources.
213649304c9SWeiXiong Liao   Do I/O map while initializing rather than wait until a panic occurs.
214649304c9SWeiXiong Liao#. Reset your block device and controller if necessary.
215649304c9SWeiXiong Liao   If you are not sure of the state of your block device and controller when
216649304c9SWeiXiong Liao   a panic occurs, you are safe to stop and reset them.
217649304c9SWeiXiong Liao
218649304c9SWeiXiong Liaopstore/blk supports psblk_blkdev_info(), which is defined in
219649304c9SWeiXiong Liao*linux/pstore_blk.h*, to get information of using block device, such as the
220649304c9SWeiXiong Liaodevice number, sector count and start sector of the whole disk.
221649304c9SWeiXiong Liao
222649304c9SWeiXiong Liaopstore block internals
223649304c9SWeiXiong Liao----------------------
224649304c9SWeiXiong Liao
225649304c9SWeiXiong LiaoFor developer reference, here are all the important structures and APIs:
226649304c9SWeiXiong Liao
227649304c9SWeiXiong Liao.. kernel-doc:: fs/pstore/zone.c
228649304c9SWeiXiong Liao   :internal:
229649304c9SWeiXiong Liao
230649304c9SWeiXiong Liao.. kernel-doc:: include/linux/pstore_zone.h
231649304c9SWeiXiong Liao   :internal:
232649304c9SWeiXiong Liao
233649304c9SWeiXiong Liao.. kernel-doc:: include/linux/pstore_blk.h
234649304c9SWeiXiong Liao   :internal:
235