Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/kfence: add reboot notifier to disable KFENCE on shutdown

During system shutdown, KFENCE can cause IPI synchronization issues if it
remains active through the reboot process. To prevent this, register a
reboot notifier that disables KFENCE and cancels any pending timer work
early in the shutdown sequence.

This is only necessary when CONFIG_KFENCE_STATIC_KEYS is enabled, as this
configuration sends IPIs that can interfere with shutdown. Without static
keys, no IPIs are generated and KFENCE can safely remain active.

The notifier uses maximum priority (INT_MAX) to ensure KFENCE shuts down
before other subsystems that might still depend on stable memory
allocation behavior.

This fixes a late kexec CSD lockup[1] when kfence is trying to IPI a CPU
that is busy in a IRQ-disabled context printing characters to the console.

Link: https://lkml.kernel.org/r/20251127-kfence-v2-1-daeccb5ef9aa@debian.org
Link: https://lkml.kernel.org/r/20251126-kfence-v1-1-5a6e1d7c681c@debian.org
Link: https://lore.kernel.org/all/sqwajvt7utnt463tzxgwu2yctyn5m6bjwrslsnupfexeml6hkd@v6sqmpbu3vvu/ [1]
Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure")
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Breno Leitao and committed by
Andrew Morton
ce2bba89 f3b566d7

+24
+24
mm/kfence/core.c
··· 26 26 #include <linux/panic_notifier.h> 27 27 #include <linux/random.h> 28 28 #include <linux/rcupdate.h> 29 + #include <linux/reboot.h> 29 30 #include <linux/sched/clock.h> 30 31 #include <linux/seq_file.h> 31 32 #include <linux/slab.h> ··· 821 820 static struct delayed_work kfence_timer; 822 821 823 822 #ifdef CONFIG_KFENCE_STATIC_KEYS 823 + static int kfence_reboot_callback(struct notifier_block *nb, 824 + unsigned long action, void *data) 825 + { 826 + /* 827 + * Disable kfence to avoid static keys IPI synchronization during 828 + * late shutdown/kexec 829 + */ 830 + WRITE_ONCE(kfence_enabled, false); 831 + /* Cancel any pending timer work */ 832 + cancel_delayed_work_sync(&kfence_timer); 833 + 834 + return NOTIFY_OK; 835 + } 836 + 837 + static struct notifier_block kfence_reboot_notifier = { 838 + .notifier_call = kfence_reboot_callback, 839 + .priority = INT_MAX, /* Run early to stop timers ASAP */ 840 + }; 841 + 824 842 /* Wait queue to wake up allocation-gate timer task. */ 825 843 static DECLARE_WAIT_QUEUE_HEAD(allocation_wait); 826 844 ··· 920 900 921 901 if (kfence_check_on_panic) 922 902 atomic_notifier_chain_register(&panic_notifier_list, &kfence_check_canary_notifier); 903 + 904 + #ifdef CONFIG_KFENCE_STATIC_KEYS 905 + register_reboot_notifier(&kfence_reboot_notifier); 906 + #endif 923 907 924 908 WRITE_ONCE(kfence_enabled, true); 925 909 queue_delayed_work(system_unbound_wq, &kfence_timer, 0);