The hardlockup detector threads are affined to CPUs based on the
HK_TYPE_TIMER housekeeping mask at boot. If this mask is updated at
runtime, these threads remain on their original CPUs, potentially
running on isolated cores.

Synchronize watchdog thread affinity with HK_TYPE_TIMER updates.

This ensures that hardlockup detector threads correctly follow the
dynamic housekeeping boundaries for timers.

Signed-off-by: Qiliang Yuan <[email protected]>
---
 kernel/watchdog.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 366122f4a0f87..ef93795729697 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -26,6 +26,7 @@
 #include <linux/sysctl.h>
 #include <linux/tick.h>
 #include <linux/sys_info.h>
+#include <linux/sched/isolation.h>
 
 #include <linux/sched/clock.h>
 #include <linux/sched/debug.h>
@@ -1359,6 +1360,29 @@ static int __init lockup_detector_check(void)
 }
 late_initcall_sync(lockup_detector_check);
 
+static int watchdog_housekeeping_reconfigure(struct notifier_block *nb,
+                                           unsigned long action, void *data)
+{
+       if (action == HK_UPDATE_MASK) {
+               struct housekeeping_update *upd = data;
+               unsigned int type = upd->type;
+
+               if (type == HK_TYPE_TIMER) {
+                       mutex_lock(&watchdog_mutex);
+                       cpumask_copy(&watchdog_cpumask,
+                                    housekeeping_cpumask(HK_TYPE_TIMER));
+                       proc_watchdog_update(false);
+                       mutex_unlock(&watchdog_mutex);
+               }
+       }
+
+       return NOTIFY_OK;
+}
+
+static struct notifier_block watchdog_housekeeping_nb = {
+       .notifier_call = watchdog_housekeeping_reconfigure,
+};
+
 void __init lockup_detector_init(void)
 {
        if (tick_nohz_full_enabled())
@@ -1373,4 +1397,5 @@ void __init lockup_detector_init(void)
                allow_lockup_detector_init_retry = true;
 
        lockup_detector_setup();
+       housekeeping_register_notifier(&watchdog_housekeeping_nb);
 }

-- 
2.43.0


Reply via email to