cgroup/cpuset: Fix v1 task migration failure from empty cpuset
Subsystems (2)
Waiman Long
maintainerv3 cover cgroup/cpuset: Fix v1 task migration failure from empty cpuset
v3:
- Drop patch 3
- Further simplify patch 2 by dropping the flag and only check for v1 cpuset with no CPU to disable security check.
v2:
- Add a new CS_TASKS_OUT flag to signal that task migration out of empty cpuset is allowed without setsched security check as suggested by Tejun.
- Add 2 more patches with minor changes.
As it is found that the cpuset v1 task migration out of cpuset with no CPU can be blocked by a strict security policy, we need to work around that issue by treating it as an exceptional case that is allowed without security check in cpuset_can_attach().
Waiman Long (2):
cgroup/cpuset: Simplify setsched decision check in task iteration loop
of cpuset_can_attach()
cgroup/cpuset: Skip security check for hotplug induced v1 task
migration
kernel/cgroup/cpuset.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
Signature · 1 line
2.53.0
Waiman Long
maintainerPATCH v3 1/2 cgroup/cpuset: Simplify setsched decision check in task iteration loop of cpuset_can_attach()
Centralize the check required to run security_task_setscheduler() in the task iteration loop of cpuset_can_attach() outside of the loop as it has no dependency on the characteristics of the tasks themselves.
There is no functional change.
--- kernel/cgroup/cpuset.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
kernel/cgroup/cpuset.c +10 -9
@@ -2988,7 +2988,7 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)struct cgroup_subsys_state *css;struct cpuset *cs, *oldcs;struct task_struct *task; -bool cpus_updated, mems_updated; +bool setsched_check;int ret;/* used later by cpuset_attach() */
@@ -3003,20 +3003,21 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)if (ret) goto out_unlock; - cpus_updated = !cpumask_equal (cs->effective_cpus, oldcs->effective_cpus); - mems_updated = !nodes_equal (cs->effective_mems, oldcs->effective_mems); +/* +* Skip rights over task setsched check in v2 when nothing changes, +* migration permission derives from hierarchy ownership in +* cgroup_procs_write_permission()). +*/ + setsched_check = !cpuset_v2 () || + !cpumask_equal (cs->effective_cpus, oldcs->effective_cpus) || + !nodes_equal (cs->effective_mems, oldcs->effective_mems);cgroup_taskset_for_each (task, css, tset) { ret =task_can_attach (task);if (ret) goto out_unlock; -/* -* Skip rights over task check in v2 when nothing changes, -* migration permission derives from hierarchy ownership in -* cgroup_procs_write_permission()). -*/ -if (!cpuset_v2 () || (cpus_updated || mems_updated)) { +if (setsched_check) { ret =security_task_setscheduler (task);if (ret) goto out_unlock;
Signature · 1 line
2.53.0
Waiman Long
maintainerPATCH v3 2/2 cgroup/cpuset: Skip security check for hotplug induced v1 task migration
In reply to Waiman LongWhen a CPU hot removal causes a v1 cpuset to lose all its CPUs, the cpuset hotplug handler will schedule a work function to migrate tasks in that cpuset with no CPU to its ancestor to enable those tasks to continue running.
If a strict security policy is in place, however, the task migration may fail when security_task_setscheduler() call in cpuset_can_attach() returns a -EACCESS error. That will mean that those tasks will have no CPU to run on. The system administrators will have to explicitly intervene to either add CPUs to that cpuset or move the tasks elsewhere if they are aware of it.
This problem was found by a reported test failure in the LTP's cpuset_hotplug_test.sh. Fix this problem by treating this special case as an exception to skip the setsched security check in cpuset_can_attach() when a v1 cpuset with tasks have no CPU left.
With that patch applied, the cpuset_hotplug_test.sh test can be run successfully without failure.
--- kernel/cgroup/cpuset.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/cgroup/cpuset.c +10 -0
@@ -3012,6 +3012,16 @@ static int cpuset_can_attach(struct cgroup_taskset *tset) !cpumask_equal (cs->effective_cpus, oldcs->effective_cpus) || !nodes_equal (cs->effective_mems, oldcs->effective_mems); +/* +* A v1 cpuset with tasks will have no CPU left only when CPU hotplug +* brings the last online CPU offline as users are not allowed to empty +* cpuset.cpus when there are active tasks inside. When that happens, +* we should allow tasks to migrate out without security check to make +* sure they will be able to run after migration. +*/ +if (!is_in_v2_mode () &&cpumask_empty (oldcs->effective_cpus)) + setsched_check = false; +cgroup_taskset_for_each (task, css, tset) { ret =task_can_attach (task);if (ret)
Signature · 1 line
2.53.0
Michal Koutný
maintainerRe: [PATCH v3 2/2] cgroup/cpuset: Skip security check for hotplug induced v1 task migration
Quoted 3 lines · Waiman Long
If a strict security policy is in place, however, the task migration may fail when
security_task_setscheduler()call incpuset_can_attach()returns a-EACCESSerror.
I think this should be generally safe to skip (since v2 doesn't consider the object of cpuset migration at all).
Quoted 3 lines
That will mean that those tasks will have no CPU to run on. The system administrators will have to explicitly intervene to either add CPUs to that cpuset or move the tasks elsewhere if they are aware of it.
That "no CPU to run on" means the affected tasks would remain in schedule() indefinitely?
Thanks,
Michal
Waiman Long
maintainerRe: [PATCH v3 2/2] cgroup/cpuset: Skip security check for hotplug induced v1 task migration
Quoted 4 lines · Michal Koutný
Quoted 3 lines · Waiman Long
If a strict security policy is in place, however, the task migration may fail when
security_task_setscheduler()call incpuset_can_attach()returns a-EACCESSerror.
Quoted 8 lines
I think this should be generally safe to skip (since v2 doesn't consider the object of cpuset migration at all).
Quoted 3 lines
That will mean that those tasks will have no CPU to run on. The system administrators will have to explicitly intervene to either add CPUs to that cpuset or move the tasks elsewhere if they are aware of it.
That "no CPU to run on" means the affected tasks would remain in
schedule()indefinitely?
I believe the scheduler has a fallback mechanism in that particular case, but it can be any CPU. So I don't think we should rely on that.
Cheers,
Longman
Michal Koutný
maintainerRe: [PATCH v3 2/2] cgroup/cpuset: Skip security check for hotplug induced v1 task migration
Quoted 2 lines · Waiman Long
I believe the scheduler has a fallback mechanism in that particular case, but it can be any CPU. So I don't think we should rely on that.
I'd say that if the patch resolved a potential lockup it'd be worth it but if there's a fallback to _run somewhere_, what's the issue? (v1 behavior with hotplug is "path dependent" anyway.)
AFAICS the cpuset_hotplug_test.sh is v1-only and not touched in the last 5 years. BTW I checked some old runs with v5.3-based SLES and there doesn't seem to be the described issue.
Do you have more details why this should be changed?
Thanks,
Michal
Tejun Heo
maintainerHello,
Quoted 5 lines
Waiman Long (2):
cgroup/cpuset: Simplify setsched decision check in task iteration loop
ofcpuset_can_attach()
cgroup/cpuset: Skip security check for hotplug induced v1 task
migration
Applied 1-2 to cgroup/for-7.0-fixes with a s/EACCESS/EACCES/ typo fix in the second patch's commit message.
Thanks.
--
tejun