Skip to content

Commit 64e6fa7

Browse files
Pingfan LiuPeter Zijlstra
authored andcommitted
sched/deadline: Fix potential race in dl_add_task_root_domain()
The access rule for local_cpu_mask_dl requires it to be called on the local CPU with preemption disabled. However, dl_add_task_root_domain() currently violates this rule. Without preemption disabled, the following race can occur: 1. ThreadA calls dl_add_task_root_domain() on CPU 0 2. Gets pointer to CPU 0's local_cpu_mask_dl 3. ThreadA is preempted and migrated to CPU 1 4. ThreadA continues using CPU 0's local_cpu_mask_dl 5. Meanwhile, the scheduler on CPU 0 calls find_later_rq() which also uses local_cpu_mask_dl (with preemption properly disabled) 6. Both contexts now corrupt the same per-CPU buffer concurrently Fix this by moving the local_cpu_mask_dl access to the preemption disabled section. Closes: https://lore.kernel.org/lkml/aSBjm3mN_uIy64nz@jlelli-thinkpadt14gen4.remote.csb Fixes: 318e18e ("sched/deadline: Walk up cpuset hierarchy to decide root domain when hot-unplug") Reported-by: Juri Lelli <juri.lelli@redhat.com> Signed-off-by: Pingfan Liu <piliu@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Juri Lelli <juri.lelli@redhat.com> Acked-by: Waiman Long <longman@redhat.com> Link: https://patch.msgid.link/20251125032630.8746-3-piliu@redhat.com
1 parent 479972e commit 64e6fa7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

kernel/sched/deadline.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3154,14 +3154,15 @@ void dl_add_task_root_domain(struct task_struct *p)
31543154
struct rq *rq;
31553155
struct dl_bw *dl_b;
31563156
unsigned int cpu;
3157-
struct cpumask *msk = this_cpu_cpumask_var_ptr(local_cpu_mask_dl);
3157+
struct cpumask *msk;
31583158

31593159
raw_spin_lock_irqsave(&p->pi_lock, rf.flags);
31603160
if (!dl_task(p) || dl_entity_is_special(&p->dl)) {
31613161
raw_spin_unlock_irqrestore(&p->pi_lock, rf.flags);
31623162
return;
31633163
}
31643164

3165+
msk = this_cpu_cpumask_var_ptr(local_cpu_mask_dl);
31653166
dl_get_task_effective_cpus(p, msk);
31663167
cpu = cpumask_first_and(cpu_active_mask, msk);
31673168
BUG_ON(cpu >= nr_cpu_ids);

0 commit comments

Comments
 (0)