Grab cpu lock around sched_migrate_task() and sys_sched_setaffinity().
This is a noop without CONFIG_HOTPLUG_CPU.
The sched_migrate_task may have a performance penalty on NUMA if lots
of exec rebalancing is happening, however this only applies to
CONFIG_NUMA and CONFIG_HOTPLUG_CPU, which noone does at the moment
anyway.
Also, the scheduler in -mm solves the race another way, so this will
vanish then.
unsigned long flags;
cpumask_t old_mask, new_mask = cpumask_of_cpu(dest_cpu);
+ lock_cpu_hotplug();
rq = task_rq_lock(p, &flags);
old_mask = p->cpus_allowed;
if (!cpu_isset(dest_cpu, old_mask) || !cpu_online(dest_cpu))
}
out:
task_rq_unlock(rq, &flags);
+ unlock_cpu_hotplug();
}
/*
if (copy_from_user(&new_mask, user_mask_ptr, sizeof(new_mask)))
return -EFAULT;
+ lock_cpu_hotplug();
read_lock(&tasklist_lock);
p = find_process_by_pid(pid);
if (!p) {
read_unlock(&tasklist_lock);
+ unlock_cpu_hotplug();
return -ESRCH;
}
out_unlock:
put_task_struct(p);
+ unlock_cpu_hotplug();
return retval;
}