Re: [RFC PATCH] introduce sys_membarrier(): process-wide memory barrier (v5)

Peter Zijlstra
2010-01-13T16:40:09Z

On Tue, 2010-01-12 at 20:37 -0500, Mathieu Desnoyers wrote:
> + for_each_cpu(cpu, tmpmask) {
> + spin_lock_irq(&cpu_rq(cpu)->lock);
> + mm = cpu_curr(cpu)->mm;
> + spin_unlock_irq(&cpu_rq(cpu)->lock);
> + if (current->mm != mm)
> + cpumask_clear_cpu(cpu, tmpmask);
> + }

Why not:

rcu_read_lock();
if (current->mm != cpu_curr(cpu)->mm)
cpumask_clear_cpu(cpu, tmpmask);
rcu_read_unlock();

the RCU read lock ensures the task_struct obtained remains valid, and it
avoids taking the rq->lock.