As HK_TYPE_KERNEL_NOISE is going to be changeable at run time, use
RCU to protect access to the cpumask when needed. Some access of the
HK_TYPE_KERNEL_NOISE cpumask is done inside the tick code that has
interrupt disabled which is a rcu_read_lock() critical section. Anyway,
housekeeping_cpumask() will warn if they are used in invalid context.

Signed-off-by: Waiman Long <[email protected]>
---
 kernel/sched/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8952f5764517..6ae00c23d8a7 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1261,6 +1261,8 @@ int get_nohz_timer_target(void)
        struct sched_domain *sd;
        const struct cpumask *hk_mask;
 
+       guard(rcu)();
+
        if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE)) {
                if (!idle_cpu(cpu))
                        return cpu;
@@ -1269,8 +1271,6 @@ int get_nohz_timer_target(void)
 
        hk_mask = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE);
 
-       guard(rcu)();
-
        for_each_domain(cpu, sd) {
                for_each_cpu_and(i, sched_domain_span(sd), hk_mask) {
                        if (cpu == i)
-- 
2.53.0


Reply via email to