From 21e8e38e5231c9104ae8b0ca225844553c8f8178 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 24 Nov 2021 20:23:02 +0000 Subject: [PATCH 1/4] meson: remove libdw dependency from pstore systemd-pstore does not use any symbol from libdw, and never did, but the dependency was listed since the beginning (cherry picked from commit 5361f62d6d5b25c6545059f7d2513324be8d7a49) Related: #2211416 --- meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/meson.build b/meson.build index d986dd24ac..d00d250444 100644 --- a/meson.build +++ b/meson.build @@ -2161,7 +2161,6 @@ if conf.get('ENABLE_PSTORE') == 1 link_with : [libshared], dependencies : [threads, libacl, - libdw, libxz, liblz4], install_rpath : rootlibexecdir, From ba48981223c92456207421adf93f59b8657d51b0 Mon Sep 17 00:00:00 2001 From: Eric DeVolder Date: Mon, 13 Apr 2020 16:22:04 -0500 Subject: [PATCH 2/4] pstore: introduce tmpfiles.d/systemd-pstore.conf The systemd pstore service archives the contents of /sys/fs/pstore upon boot so that there is room for a subsequent dump. The issue is that while the service is present, the kernel still needs to be configured to write data into the pstore. The kernel has two parameters, crash_kexec_post_notifiers and printk.always_kmsg_dump, that control writes into pstore. The crash_kexec_post_notifiers parameter enables the kernel to write dmesg (including stack trace) into pstore upon a panic, and printk.always_kmsg_dump parameter enables the kernel to write dmesg upon a shutdown (shutdown, reboot, halt). As it stands today, these parameters are not managed/manipulated by the systemd pstore service, and are solely reliant upon the user [to have the foresight] to set them on the kernel command line at boot, or post boot via sysfs. Furthermore, the user would need to set these parameters in a persistent fashion so that that they are enabled on subsequent reboots. This patch introduces the setting of these two kernel parameters via the systemd tmpfiles technique. (cherry picked from commit f00c36641a253f4ea659ec3def5d87ba1336eb3b) Resolves: #2211416 --- man/systemd-pstore.service.xml | 18 ++++++++++++++++++ tmpfiles.d/meson.build | 1 + tmpfiles.d/systemd-pstore.conf | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tmpfiles.d/systemd-pstore.conf diff --git a/man/systemd-pstore.service.xml b/man/systemd-pstore.service.xml index 47916da521..335a3b3d18 100644 --- a/man/systemd-pstore.service.xml +++ b/man/systemd-pstore.service.xml @@ -81,6 +81,24 @@ pstore.conf5. + + + Controlling kernel parameters + + The kernel has two parameters, + /sys/module/kernel/parameters/crash_kexec_post_notifiers and + /sys/module/printk/parameters/always_kmsg_dump, + that control writes into pstore. + The crash_kexec_post_notifiers parameter enables the kernel to write + dmesg (including stack trace) into pstore upon a panic or crash, and + printk.always_kmsg_dump parameter enables the kernel to write dmesg + upon a normal shutdown (shutdown, reboot, halt). These kernel + parameters are managed via the + tmpfiles.d5 + mechanism, specifically the file /usr/lib/tmpfiles/systemd-pstore.conf. + + + diff --git a/tmpfiles.d/meson.build b/tmpfiles.d/meson.build index 35eea2be5c..5ebb8f432a 100644 --- a/tmpfiles.d/meson.build +++ b/tmpfiles.d/meson.build @@ -7,6 +7,7 @@ tmpfiles = [['home.conf', ''], ['systemd-nologin.conf', ''], ['systemd-nspawn.conf', 'ENABLE_MACHINED'], ['portables.conf', 'ENABLE_PORTABLED'], + ['systemd-pstore.conf', 'ENABLE_PSTORE'], ['tmp.conf', ''], ['x11.conf', ''], ['legacy.conf', 'HAVE_SYSV_COMPAT'], diff --git a/tmpfiles.d/systemd-pstore.conf b/tmpfiles.d/systemd-pstore.conf new file mode 100644 index 0000000000..cb600ec1ee --- /dev/null +++ b/tmpfiles.d/systemd-pstore.conf @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# The systemd-pstore.service(1) archives the contents of /sys/fs/pstore +# upon boot so that there is room for a subsequent dump. This service +# is enabled with: +# systemctl enable systemd-pstore +# +# With the service enabled, the kernel still needs to be configured +# to write data into the pstore. The kernel has two parameters, +# crash_kexec_post_notifiers and printk.always_kmsg_dump, that +# control writes into pstore. +# +# The crash_kexec_post_notifiers parameter enables the kernel to write +# dmesg (including stack trace) into pstore upon a panic, and +# printk.always_kmsg_dump parameter enables the kernel to write dmesg +# upon a normal shutdown (shutdown, reboot, halt). +# +# To configure the kernel parameters, uncomment the appropriate +# line(s) below. The value written is either 'Y' to enable the +# kernel parameter, or 'N' to disable the kernel parameter. +# +# After making a change to this file, do: +# systemd-tmpfiles --create path/to/tmpfiles.d/systemd-pstore.conf +# +# These changes are automatically applied on future re-boots. + +d /var/lib/systemd/pstore 0755 root root 14d +#w /sys/module/printk/parameters/always_kmsg_dump - - - - Y +w /sys/module/kernel/parameters/crash_kexec_post_notifiers - - - - Y From 7b80bc54b1085e842fcaa6a48e11808dfc7757ee Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 May 2020 16:11:51 +0200 Subject: [PATCH 3/4] tmpfiles: don't complain if we can't enable pstore in containers (cherry picked from commit 203c07c95b91b4ae3b0c1ae3c92accdb71fd5e13) Related: #2211416 --- tmpfiles.d/systemd-pstore.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmpfiles.d/systemd-pstore.conf b/tmpfiles.d/systemd-pstore.conf index cb600ec1ee..8b6a1dafc3 100644 --- a/tmpfiles.d/systemd-pstore.conf +++ b/tmpfiles.d/systemd-pstore.conf @@ -25,5 +25,5 @@ # These changes are automatically applied on future re-boots. d /var/lib/systemd/pstore 0755 root root 14d -#w /sys/module/printk/parameters/always_kmsg_dump - - - - Y -w /sys/module/kernel/parameters/crash_kexec_post_notifiers - - - - Y +#w- /sys/module/printk/parameters/always_kmsg_dump - - - - Y +w- /sys/module/kernel/parameters/crash_kexec_post_notifiers - - - - Y From 7572e73b83ae19a4ceeed54abf837d5ad1570cbd Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 4 Aug 2020 17:30:51 +0800 Subject: [PATCH 4/4] pstore: don't enable crash_kexec_post_notifiers by default commit f00c36641a253f4ea659ec3def5d87ba1336eb3b enabled crash_kexec_post_notifiers by default regardless of whether pstore is enabled or not. The original intention to enabled this option by default is that it only affects kernel post-panic behavior, so should have no harm. But this is not true if the user wants a reliable kdump. crash_kexec_post_notifiers is known to cause problem with kdump, and it's documented in kernel. It's not easy to fix the problem because of how kdump works. Kdump expects the crashed kernel to jump to an pre-loaded crash kernel, so doing any extra job before the jump will increase the risk. It depends on the user to choose between having a reliable kdump or some other post-panic debug mechanic. So it's better to keep this config untouched by default, or it may put kdump at higher risk of failing silently. User should enable it by uncommenting the config line manually if pstore is always needed. Also add a inline comment inform user about the potential issue. Thanks to Dave Young for finding out this issue. Fixes #16661 Signed-off-by: Kairui Song (cherry picked from commit edb8c98446e7dae54bcda90806bf6c068e1c6385) Related: #2211416 --- tmpfiles.d/systemd-pstore.conf | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tmpfiles.d/systemd-pstore.conf b/tmpfiles.d/systemd-pstore.conf index 8b6a1dafc3..e8e9ed48ae 100644 --- a/tmpfiles.d/systemd-pstore.conf +++ b/tmpfiles.d/systemd-pstore.conf @@ -11,8 +11,13 @@ # control writes into pstore. # # The crash_kexec_post_notifiers parameter enables the kernel to write -# dmesg (including stack trace) into pstore upon a panic, and -# printk.always_kmsg_dump parameter enables the kernel to write dmesg +# dmesg (including stack trace) into pstore upon a panic even if kdump +# is loaded, only needed if you want to use pstore with kdump. Without +# this parameter, kdump could block writing to pstore for stability +# reason. Note this increases the risk of kdump failure even if pstore +# is not available. +# +# The printk.always_kmsg_dump parameter enables the kernel to write dmesg # upon a normal shutdown (shutdown, reboot, halt). # # To configure the kernel parameters, uncomment the appropriate @@ -26,4 +31,4 @@ d /var/lib/systemd/pstore 0755 root root 14d #w- /sys/module/printk/parameters/always_kmsg_dump - - - - Y -w- /sys/module/kernel/parameters/crash_kexec_post_notifiers - - - - Y +#w- /sys/module/kernel/parameters/crash_kexec_post_notifiers - - - - Y