Skip to content

Commit 292fd84

Browse files
Waiman-Longhtejun
authored andcommitted
cgroup/cpuset: Fix partition root's cpuset.cpus update bug
It was found that commit 7a2127e ("cpuset: Call set_cpus_allowed_ptr() with appropriate mask for task") introduced a bug that corrupted "cpuset.cpus" of a partition root when it was updated. It is because the tmp->new_cpus field of the passed tmp parameter of update_parent_subparts_cpumask() should not be used at all as it contains important cpumask data that should not be overwritten. Fix it by using tmp->addmask instead. Also update update_cpumask() to make sure that trialcs->cpu_allowed will not be corrupted until it is no longer needed. Fixes: 7a2127e ("cpuset: Call set_cpus_allowed_ptr() with appropriate mask for task") Signed-off-by: Waiman Long <longman@redhat.com> Cc: stable@vger.kernel.org # v6.2+ Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent fcdb1ed commit 292fd84

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

kernel/cgroup/cpuset.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ static int update_parent_subparts_cpumask(struct cpuset *cs, int cmd,
15131513
spin_unlock_irq(&callback_lock);
15141514

15151515
if (adding || deleting)
1516-
update_tasks_cpumask(parent, tmp->new_cpus);
1516+
update_tasks_cpumask(parent, tmp->addmask);
15171517

15181518
/*
15191519
* Set or clear CS_SCHED_LOAD_BALANCE when partcmd_update, if necessary.
@@ -1770,10 +1770,13 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
17701770
/*
17711771
* Use the cpumasks in trialcs for tmpmasks when they are pointers
17721772
* to allocated cpumasks.
1773+
*
1774+
* Note that update_parent_subparts_cpumask() uses only addmask &
1775+
* delmask, but not new_cpus.
17731776
*/
17741777
tmp.addmask = trialcs->subparts_cpus;
17751778
tmp.delmask = trialcs->effective_cpus;
1776-
tmp.new_cpus = trialcs->cpus_allowed;
1779+
tmp.new_cpus = NULL;
17771780
#endif
17781781

17791782
retval = validate_change(cs, trialcs);
@@ -1838,6 +1841,11 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
18381841
}
18391842
spin_unlock_irq(&callback_lock);
18401843

1844+
#ifdef CONFIG_CPUMASK_OFFSTACK
1845+
/* Now trialcs->cpus_allowed is available */
1846+
tmp.new_cpus = trialcs->cpus_allowed;
1847+
#endif
1848+
18411849
/* effective_cpus will be updated here */
18421850
update_cpumasks_hier(cs, &tmp, false);
18431851

0 commit comments

Comments
 (0)