Skip to content

Commit 649304c

Browse files
WeiXiong Liaokees
authored andcommitted
Documentation: Add details for pstore/blk
Add details on using pstore/blk, the new backend of pstore to record dumps to block devices, in Documentation/admin-guide/pstore-blk.rst Signed-off-by: WeiXiong Liao <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Kees Cook <[email protected]>
1 parent 34327e9 commit 649304c

File tree

3 files changed

+232
-0
lines changed

3 files changed

+232
-0
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
pstore block oops/panic logger
4+
==============================
5+
6+
Introduction
7+
------------
8+
9+
pstore block (pstore/blk) is an oops/panic logger that writes its logs to a
10+
block device before the system crashes. You can get these log files by
11+
mounting pstore filesystem like::
12+
13+
mount -t pstore pstore /sys/fs/pstore
14+
15+
16+
pstore block concepts
17+
---------------------
18+
19+
pstore/blk provides efficient configuration method for pstore/blk, which
20+
divides all configurations into two parts, configurations for user and
21+
configurations for driver.
22+
23+
Configurations for user determine how pstore/blk works, such as pmsg_size,
24+
kmsg_size and so on. All of them support both Kconfig and module parameters,
25+
but module parameters have priority over Kconfig.
26+
27+
Configurations for driver are all about block device, such as total_size
28+
of block device and read/write operations.
29+
30+
Configurations for user
31+
-----------------------
32+
33+
All of these configurations support both Kconfig and module parameters, but
34+
module parameters have priority over Kconfig.
35+
36+
Here is an example for module parameters::
37+
38+
pstore_blk.blkdev=179:7 pstore_blk.kmsg_size=64
39+
40+
The detail of each configurations may be of interest to you.
41+
42+
blkdev
43+
~~~~~~
44+
45+
The block device to use. Most of the time, it is a partition of block device.
46+
It's required for pstore/blk.
47+
48+
It accepts the following variants:
49+
50+
1. <hex_major><hex_minor> device number in hexadecimal represents itself; no
51+
leading 0x, for example b302.
52+
#. /dev/<disk_name> represents the device number of disk
53+
#. /dev/<disk_name><decimal> represents the device number of partition - device
54+
number of disk plus the partition number
55+
#. /dev/<disk_name>p<decimal> - same as the above; this form is used when disk
56+
name of partitioned disk ends with a digit.
57+
#. PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF represents the unique id of
58+
a partition if the partition table provides it. The UUID may be either an
59+
EFI/GPT UUID, or refer to an MSDOS partition using the format SSSSSSSS-PP,
60+
where SSSSSSSS is a zero-filled hex representation of the 32-bit
61+
"NT disk signature", and PP is a zero-filled hex representation of the
62+
1-based partition number.
63+
#. PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to a
64+
partition with a known unique id.
65+
#. <major>:<minor> major and minor number of the device separated by a colon.
66+
67+
kmsg_size
68+
~~~~~~~~~
69+
70+
The chunk size in KB for oops/panic front-end. It **MUST** be a multiple of 4.
71+
It's optional if you do not care oops/panic log.
72+
73+
There are multiple chunks for oops/panic front-end depending on the remaining
74+
space except other pstore front-ends.
75+
76+
pstore/blk will log to oops/panic chunks one by one, and always overwrite the
77+
oldest chunk if there is no more free chunk.
78+
79+
pmsg_size
80+
~~~~~~~~~
81+
82+
The chunk size in KB for pmsg front-end. It **MUST** be a multiple of 4.
83+
It's optional if you do not care pmsg log.
84+
85+
Unlike oops/panic front-end, there is only one chunk for pmsg front-end.
86+
87+
Pmsg is a user space accessible pstore object. Writes to */dev/pmsg0* are
88+
appended to the chunk. On reboot the contents are available in
89+
*/sys/fs/pstore/pmsg-pstore-blk-0*.
90+
91+
console_size
92+
~~~~~~~~~~~~
93+
94+
The chunk size in KB for console front-end. It **MUST** be a multiple of 4.
95+
It's optional if you do not care console log.
96+
97+
Similar to pmsg front-end, there is only one chunk for console front-end.
98+
99+
All log of console will be appended to the chunk. On reboot the contents are
100+
available in */sys/fs/pstore/console-pstore-blk-0*.
101+
102+
ftrace_size
103+
~~~~~~~~~~~
104+
105+
The chunk size in KB for ftrace front-end. It **MUST** be a multiple of 4.
106+
It's optional if you do not care console log.
107+
108+
Similar to oops front-end, there are multiple chunks for ftrace front-end
109+
depending on the count of cpu processors. Each chunk size is equal to
110+
ftrace_size / processors_count.
111+
112+
All log of ftrace will be appended to the chunk. On reboot the contents are
113+
combined and available in */sys/fs/pstore/ftrace-pstore-blk-0*.
114+
115+
Persistent function tracing might be useful for debugging software or hardware
116+
related hangs. Here is an example of usage::
117+
118+
# mount -t pstore pstore /sys/fs/pstore
119+
# mount -t debugfs debugfs /sys/kernel/debug/
120+
# echo 1 > /sys/kernel/debug/pstore/record_ftrace
121+
# reboot -f
122+
[...]
123+
# mount -t pstore pstore /sys/fs/pstore
124+
# tail /sys/fs/pstore/ftrace-pstore-blk-0
125+
CPU:0 ts:5914676 c0063828 c0063b94 call_cpuidle <- cpu_startup_entry+0x1b8/0x1e0
126+
CPU:0 ts:5914678 c039ecdc c006385c cpuidle_enter_state <- call_cpuidle+0x44/0x48
127+
CPU:0 ts:5914680 c039e9a0 c039ecf0 cpuidle_enter_freeze <- cpuidle_enter_state+0x304/0x314
128+
CPU:0 ts:5914681 c0063870 c039ea30 sched_idle_set_state <- cpuidle_enter_state+0x44/0x314
129+
CPU:1 ts:5916720 c0160f59 c015ee04 kernfs_unmap_bin_file <- __kernfs_remove+0x140/0x204
130+
CPU:1 ts:5916721 c05ca625 c015ee0c __mutex_lock_slowpath <- __kernfs_remove+0x148/0x204
131+
CPU:1 ts:5916723 c05c813d c05ca630 yield_to <- __mutex_lock_slowpath+0x314/0x358
132+
CPU:1 ts:5916724 c05ca2d1 c05ca638 __ww_mutex_lock <- __mutex_lock_slowpath+0x31c/0x358
133+
134+
max_reason
135+
~~~~~~~~~~
136+
137+
Limiting which kinds of kmsg dumps are stored can be controlled via
138+
the ``max_reason`` value, as defined in include/linux/kmsg_dump.h's
139+
``enum kmsg_dump_reason``. For example, to store both Oopses and Panics,
140+
``max_reason`` should be set to 2 (KMSG_DUMP_OOPS), to store only Panics
141+
``max_reason`` should be set to 1 (KMSG_DUMP_PANIC). Setting this to 0
142+
(KMSG_DUMP_UNDEF), means the reason filtering will be controlled by the
143+
``printk.always_kmsg_dump`` boot param: if unset, it'll be KMSG_DUMP_OOPS,
144+
otherwise KMSG_DUMP_MAX.
145+
146+
Configurations for driver
147+
-------------------------
148+
149+
Only a block device driver cares about these configurations. A block device
150+
driver uses ``register_pstore_blk`` to register to pstore/blk.
151+
152+
.. kernel-doc:: fs/pstore/blk.c
153+
:identifiers: register_pstore_blk
154+
155+
Compression and header
156+
----------------------
157+
158+
Block device is large enough for uncompressed oops data. Actually we do not
159+
recommend data compression because pstore/blk will insert some information into
160+
the first line of oops/panic data. For example::
161+
162+
Panic: Total 16 times
163+
164+
It means that it's OOPS|Panic for the 16th time since the first booting.
165+
Sometimes the number of occurrences of oops|panic since the first booting is
166+
important to judge whether the system is stable.
167+
168+
The following line is inserted by pstore filesystem. For example::
169+
170+
Oops#2 Part1
171+
172+
It means that it's OOPS for the 2nd time on the last boot.
173+
174+
Reading the data
175+
----------------
176+
177+
The dump data can be read from the pstore filesystem. The format for these
178+
files is ``dmesg-pstore-blk-[N]`` for oops/panic front-end,
179+
``pmsg-pstore-blk-0`` for pmsg front-end and so on. The timestamp of the
180+
dump file records the trigger time. To delete a stored record from block
181+
device, simply unlink the respective pstore file.
182+
183+
Attentions in panic read/write APIs
184+
-----------------------------------
185+
186+
If on panic, the kernel is not going to run for much longer, the tasks will not
187+
be scheduled and most kernel resources will be out of service. It
188+
looks like a single-threaded program running on a single-core computer.
189+
190+
The following points require special attention for panic read/write APIs:
191+
192+
1. Can **NOT** allocate any memory.
193+
If you need memory, just allocate while the block driver is initializing
194+
rather than waiting until the panic.
195+
#. Must be polled, **NOT** interrupt driven.
196+
No task schedule any more. The block driver should delay to ensure the write
197+
succeeds, but NOT sleep.
198+
#. Can **NOT** take any lock.
199+
There is no other task, nor any shared resource; you are safe to break all
200+
locks.
201+
#. Just use CPU to transfer.
202+
Do not use DMA to transfer unless you are sure that DMA will not keep lock.
203+
#. Control registers directly.
204+
Please control registers directly rather than use Linux kernel resources.
205+
Do I/O map while initializing rather than wait until a panic occurs.
206+
#. Reset your block device and controller if necessary.
207+
If you are not sure of the state of your block device and controller when
208+
a panic occurs, you are safe to stop and reset them.
209+
210+
pstore/blk supports psblk_blkdev_info(), which is defined in
211+
*linux/pstore_blk.h*, to get information of using block device, such as the
212+
device number, sector count and start sector of the whole disk.
213+
214+
pstore block internals
215+
----------------------
216+
217+
For developer reference, here are all the important structures and APIs:
218+
219+
.. kernel-doc:: fs/pstore/zone.c
220+
:internal:
221+
222+
.. kernel-doc:: include/linux/pstore_zone.h
223+
:internal:
224+
225+
.. kernel-doc:: fs/pstore/blk.c
226+
:export:
227+
228+
.. kernel-doc:: include/linux/pstore_blk.h
229+
:internal:

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13660,6 +13660,7 @@ M: Tony Luck <[email protected]>
1366013660
S: Maintained
1366113661
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore
1366213662
F: Documentation/admin-guide/ramoops.rst
13663+
F: Documentation/admin-guide/pstore-blk.rst
1366313664
F: Documentation/devicetree/bindings/reserved-memory/ramoops.txt
1366413665
F: drivers/acpi/apei/erst.c
1366513666
F: drivers/firmware/efi/efi-pstore.c

fs/pstore/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ config PSTORE_BLK
171171
This enables panic and oops message to be logged to a block dev
172172
where it can be read back at some later point.
173173

174+
For more information, see Documentation/admin-guide/pstore-blk.rst
175+
174176
If unsure, say N.
175177

176178
config PSTORE_BLK_BLKDEV

0 commit comments

Comments
 (0)