Re: [tip:sched/urgent] cpuset: Fix cpuset_cpus_allowed_fallback(),don't update tsk->rt.nr_cpus_allowed

From: KOSAKI Motohiro
Date: Tue Jun 21 2011 - 05:55:11 EST


(2011/06/20 19:20), Peter Zijlstra wrote:
> On Sat, 2011-05-28 at 16:35 +0000, tip-bot for KOSAKI Motohiro wrote:
>> +++ b/kernel/kthread.c
>> @@ -202,8 +202,8 @@ void kthread_bind(struct task_struct *p, unsigned int cpu)
>> return;
>> }
>>
>> - p->cpus_allowed = cpumask_of_cpu(cpu);
>> - p->rt.nr_cpus_allowed = 1;
>> + /* It's safe because the task is inactive. */
>> + do_set_cpus_allowed(p, cpumask_of(cpu));
>> p->flags |= PF_THREAD_BOUND;
>> }
>
>
> I just happened to be staring at this stuff again, and I'm wondering
> how and why this is correct. After kthread_create() the thread exists
> and is exposed in the pid-hash, therefore userspace can come and do
> sys_sched_setaffinity() on it, and since we're not holding any locks and
> set PF_THREAD_BOUND _after_ setting cpus_allowed, things can end up
> funny.
>
> Hmm?

Can't we take just either rq lock or pi_lock? Layer violation?