notifier/panic: Introduce panic_notifier_filter
Subsystems (3)
PATCH v3 1/1 notifier/panic: Introduce panic_notifier_filter
The kernel notifier infrastructure allows function callbacks to be added in multiple lists, which are then called in the proper time, like in a reboot or panic event. The panic_notifier_list specifically contains the callbacks that are executed during a panic event. As any other notifier list, the panic one has no filtering and all functions previously registered are executed.
The kdump infrastructure, on the other hand, enables users to set a crash kernel that is kexec'ed in a panic event, and vmcore/logs are collected in such crash kernel. When kdump is set, by default the panic notifiers are ignored - the kexec jumps to the crash kernel before the list is checked and callbacks executed.
There are some cases though in which kdump users might want to allow panic notifier callbacks to execute _before_ the kexec to the crash kernel, for a variety of reasons - for example, users may think kexec is very prone to fail and want to give a chance to kmsg dumpers to run (and save logs using pstore), or maybe some panic notifier is required to properly quiesce some hardware that must be used to the crash kernel. For these cases, we have the kernel parameter "crash_kexec_post_notifiers".
But there's a problem: currently it's an "all-or-nothing" situation, the kdump user choice is either to execute all panic notifiers or none of them. Given that panic notifiers may increase the risk of a kdump failure, this is a tough decision and may affect the debug of hard to reproduce bugs, if for some reason the user choice is to enable panic notifiers, but kdump then fails.
So, this patch aims to ease this decision: we hereby introduce a filter for the panic notifier list, in which users may select specifically which callbacks they wish to run, allowing a safer kdump. The allowlist should be provided using the parameter "panic_notifier_filter=a,b,..." where a, b are valid callback names. Invalid symbols are discarded.
Currently up to 16 symbols may be passed in this list, we consider that this numbers allows enough flexibility (and no matter what architecture is used, at most 30 panic callbacks are registered). In an experiment using a qemu x86 virtual machine, by default only six callbacks are registered in the panic notifier list. Once a valid callback name is provided in the list, such function is allowed to be registered/unregistered in the panic_notifier_list; all other panic callbacks are ignored. Notice that this filter is only for the panic notifiers and has no effect in the other notifiers.
---
V3:
* Implemented Alan's suggestion (thanks!), simplifying the check code in the notifiers register/unregister functions. Notice that the suggestion was missing a negative in the check function, I even renamed it now, to be more clear:
s/is_panic_notifier_filtered/should_register_panic_notifier
The condition is !(A && B && C), and C is the check function, that returns true when a symbol *is found* in the notifier filter; hence we need to invert that here, as you can see in the code.
* Implemented Andy's suggestion (thanks!), to reduce the code in the parameter parsing loop. Notice that strsep() modifies the buffer, so not sure if it was a typo but the correct code here is:
single_param = strsep(&full_param_buffer, ",");
* "Bumped" the log output of the parsing function: users should be warned in the errors (invalid symbol or exceeded entries) and informed (pr_info) in case the parsing succeeded - I think pr_debug was useless there.
Cheers,
Guilherme
.../admin-guide/kernel-parameters.txt | 14 +++++- include/linux/panic_notifier.h | 10 +++++ kernel/notifier.c | 44 +++++++++++++++++-- kernel/panic.c | 43 ++++++++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +13 -1
@@ -3727,13 +3727,25 @@ panic_on_warn panic() instead of WARN(). Useful to cause kdump on a WARN(). + panic_notifier_filter=[function-list] + Limit the functions registered by the panic notifier + infrastructure. This allowlist is composed by function + names, comma separated (invalid symbols are filtered + out). Such functionality is useful for kdump users + that set "crash_kexec_post_notifiers" in order to + execute panic notifiers, but at the same time wish to + have just a subset of notifiers, not all of them. The + list of functions is limited to 16 entries currently. + crash_kexec_post_notifiers Run kdump after running panic-notifiers and dumping kmsg. This only for the users who doubt kdump always succeeds in any situation. Note that this also increases risks of kdump failure, because some panic notifiers can make the crashed - kernel more unstable. + kernel more unstable. See the "panic_notifier_filter" + parameter to have more control of which notifiers to + execute. parkbd.port= [HW] Parallel port number the keyboard adapter is connected to, default is 0.
include/linux/panic_notifier.h +10 -0
@@ -5,6 +5,16 @@#include <linux/notifier.h> #include <linux/types.h> +/* +* The panic notifier filter infrastructure - each array element holds a +* function address, to be checked against panic_notifier register/unregister +* operations; these functions are allowed to be registered in the panic +* notifier list. This setting is useful for kdump, since users may want +* some panic notifiers to execute, but not all of them. +*/ +extern unsigned long panic_nf_functions[]; +extern int panic_nf_count; +extern struct atomic_notifier_head panic_notifier_list;extern bool crash_kexec_post_notifiers;
kernel/notifier.c +40 -4
82 lines not on this page · raw message
kernel/panic.c +43 -0
61 lines not on this page · raw message
Signature · 1 line
2.34.1
A message that is not in the archive (sent off-list or not yet received): CAHp75Vf8SisR16tK=hwiF9ET0PoQRcu1h5LCZHZAGX8M3KysRA@mail.gmail.com
Quoted 12 lines · Andy Shevchenko
[...]
+? ? ? ?if (!buf) +? ? ? ? ? ? ? ?return -EINVAL;I also implied that you don?t need this condition.
+? ? ? ?while ((func = strsep(&buf, ","))) { +? ? ? ? ? ? ? ?addr = kallsyms_lookup_name(func);?
Quoted 7 lines
+Btw, this is redundant blank line.
?+? ? ? ? ? ? ? ?if (!addr) {
Thanks Andy, just submitted a V4 that incorporates your suggestions. Cheers,
Guilherme