Skip to content

Commit

Permalink
cgroup/cpuset: Fix partition root's cpuset.cpus update bug
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Waiman Long authored and Tejun Heo committed Mar 29, 2023
1 parent fcdb1ed commit 292fd84
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions kernel/cgroup/cpuset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ static int update_parent_subparts_cpumask(struct cpuset *cs, int cmd,
spin_unlock_irq(&callback_lock);

if (adding || deleting)
update_tasks_cpumask(parent, tmp->new_cpus);
update_tasks_cpumask(parent, tmp->addmask);

/*
* Set or clear CS_SCHED_LOAD_BALANCE when partcmd_update, if necessary.
Expand Down Expand Up @@ -1770,10 +1770,13 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
/*
* Use the cpumasks in trialcs for tmpmasks when they are pointers
* to allocated cpumasks.
*
* Note that update_parent_subparts_cpumask() uses only addmask &
* delmask, but not new_cpus.
*/
tmp.addmask = trialcs->subparts_cpus;
tmp.delmask = trialcs->effective_cpus;
tmp.new_cpus = trialcs->cpus_allowed;
tmp.new_cpus = NULL;
#endif

retval = validate_change(cs, trialcs);
Expand Down Expand Up @@ -1838,6 +1841,11 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
}
spin_unlock_irq(&callback_lock);

#ifdef CONFIG_CPUMASK_OFFSTACK
/* Now trialcs->cpus_allowed is available */
tmp.new_cpus = trialcs->cpus_allowed;
#endif

/* effective_cpus will be updated here */
update_cpumasks_hier(cs, &tmp, false);

Expand Down

0 comments on commit 292fd84

Please sign in to comment.