]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cgroup/cpuset: Simplify setsched decision check in task iteration loop of cpuset_can_...
authorWaiman Long <longman@redhat.com>
Tue, 31 Mar 2026 15:11:07 +0000 (11:11 -0400)
committerTejun Heo <tj@kernel.org>
Tue, 31 Mar 2026 19:14:13 +0000 (09:14 -1000)
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.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cpuset.c

index d21868455341aa1b897b972b447aef312e48ab78..58c5b7b72ccae6bd2585b3d3d5a395ae7b91a64d 100644 (file)
@@ -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;