When the housekeeping CPU mask for RCU is updated at runtime, RCU
grace-period kthreads and tasks-RCU kthreads should be migrated to the
newly designated housekeeping CPUs.

1. Implement rcu_housekeeping_reconfigure() to handle HK_UPDATE_MASK
   events for HK_TYPE_RCU.
2. Update the affinity of rcu_state.gp_kthread when the mask changes.
3. Register the RCU housekeeping notifier during late initialization.

This ensures RCU kthreads honor dynamic isolation settings without
requiring a system reboot.

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

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 293bbd9ac3f4..ec496e4bd24f 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -48,6 +48,7 @@
 #include <linux/delay.h>
 #include <linux/random.h>
 #include <linux/trace_events.h>
+#include <linux/sched/isolation.h>
 #include <linux/suspend.h>
 #include <linux/ftrace.h>
 #include <linux/tick.h>
@@ -4913,7 +4914,49 @@ void __init rcu_init(void)
        tasks_cblist_init_generic();
 }
 
+#ifdef CONFIG_SMP
+static int rcu_housekeeping_reconfigure(struct notifier_block *nb,
+                                       unsigned long action, void *data)
+{
+       struct housekeeping_update *upd = data;
+       struct task_struct *t;
+
+       if (action != HK_UPDATE_MASK || upd->type != HK_TYPE_RCU)
+               return NOTIFY_OK;
+
+       t = READ_ONCE(rcu_state.gp_kthread);
+       if (t)
+               housekeeping_affine(t, HK_TYPE_RCU);
+
+#ifdef CONFIG_TASKS_RCU
+       t = get_rcu_tasks_gp_kthread();
+       if (t)
+               housekeeping_affine(t, HK_TYPE_RCU);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+       t = get_rcu_tasks_rude_gp_kthread();
+       if (t)
+               housekeeping_affine(t, HK_TYPE_RCU);
+#endif
+
+       return NOTIFY_OK;
+}
+
+static struct notifier_block rcu_housekeeping_nb = {
+       .notifier_call = rcu_housekeeping_reconfigure,
+};
+
+static int __init rcu_init_housekeeping_notifier(void)
+{
+       housekeeping_register_notifier(&rcu_housekeeping_nb);
+       return 0;
+}
+late_initcall(rcu_init_housekeeping_notifier);
+#endif
+
 #include "tree_stall.h"
 #include "tree_exp.h"
 #include "tree_nocb.h"
 #include "tree_plugin.h"
+

-- 
2.51.0


Reply via email to