Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9fbf75b authored by Olav Haugan's avatar Olav Haugan Committed by Satya Durga Srinivasu Prabhala
Browse files

sched/core: Prevent (user) space tasks from affining to isolated cpus



We don't want user space tasks to run on isolated cpus. If the affinity
mask that the user space task is trying to set only includes online
cpus that are isolated return error.

Also ensure that tasks do not get stuck on isolated cores. We are not
properly updating the mask that we check against the current CPU so we
might end up thinking we can run on the current CPU. Fix this.

Change-Id: I078d01e63860d1fc60fc96eb0c739c0f680ae983
Signed-off-by: default avatarOlav Haugan <ohaugan@codeaurora.org>
[satyap@codeaurora.org: trivial merge conflicts resolution]
Signed-off-by: default avatarSatya Durga Srinivasu Prabhala <satyap@codeaurora.org>
parent 87812db2
Loading
Loading
Loading
Loading
+24 −14
Original line number Diff line number Diff line
@@ -1092,14 +1092,16 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
		goto out;

	cpumask_andnot(&allowed_mask, new_mask, cpu_isolated_mask);
	cpumask_and(&allowed_mask, &allowed_mask, cpu_valid_mask);

	dest_cpu = cpumask_any_and(cpu_valid_mask, &allowed_mask);
	dest_cpu = cpumask_any(&allowed_mask);
	if (dest_cpu >= nr_cpu_ids) {
		cpumask_and(&allowed_mask, cpu_valid_mask, new_mask);
		dest_cpu = cpumask_any(&allowed_mask);
		if (!cpumask_intersects(new_mask, cpu_valid_mask)) {
			ret = -EINVAL;
			goto out;
		}
		cpumask_copy(&allowed_mask, new_mask);
	}

	do_set_cpus_allowed(p, new_mask);
@@ -4878,6 +4880,8 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
	cpumask_var_t cpus_allowed, new_mask;
	struct task_struct *p;
	int retval;
	int dest_cpu;
	cpumask_t allowed_mask;

	rcu_read_lock();

@@ -4939,8 +4943,10 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
	}
#endif
again:
	cpumask_andnot(&allowed_mask, new_mask, cpu_isolated_mask);
	dest_cpu = cpumask_any_and(cpu_active_mask, &allowed_mask);
	if (dest_cpu < nr_cpu_ids) {
		retval = __set_cpus_allowed_ptr(p, new_mask, true);

		if (!retval) {
			cpuset_cpus_allowed(p, cpus_allowed);
			if (!cpumask_subset(new_mask, cpus_allowed)) {
@@ -4953,6 +4959,10 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
				goto again;
			}
		}
	} else {
		retval = -EINVAL;
	}

out_free_new_mask:
	free_cpumask_var(new_mask);
out_free_cpus_allowed: