Re: [PATCH] pi-futex: set PF_EXITING without taking ->pi_lock

From: Oleg Nesterov
Date: Sat Jul 21 2007 - 10:17:21 EST


On 07/21, Ingo Molnar wrote:
>
> * Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> > It is a bit annoying that do_exit() takes ->pi_lock to set PF_EXITING.
> > All we need is to synchronize with lookup_pi_state() which saw this task
> > without PF_EXITING under ->pi_lock.
> >
> > Change do_exit() to use spin_unlock_wait().
> >
> > Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
>
> Acked-by: Ingo Molnar <mingo@xxxxxxx>

Thanks!

> > - spin_lock_irq(&tsk->pi_lock);
> > - tsk->flags |= PF_EXITING;
> > - spin_unlock_irq(&tsk->pi_lock);
> > + smp_mb();
> > + spin_unlock_wait(&tsk->pi_lock);
>
> hm, isnt spin_unlock_wait() an SMP barrier in itself?

no, only barrier() due to cpu_relax()

> (if not then it should be.)

I think you are right, I can't imagine a valid usage of spin_unlock_wait()
without a barrier.

For example, from net/dccp/ccid.c

static void ccids_write_lock(void)
{
spin_lock(&ccids_lock);
while (atomic_read(&ccids_lockct) != 0) {
spin_unlock(&ccids_lock);
yield();
spin_lock(&ccids_lock);
}
}

static inline void ccids_read_lock(void)
{
atomic_inc(&ccids_lockct);
spin_unlock_wait(&ccids_lock);
}

This looks racy, in theory atomic_inc() and spin_unlock_wait() could be
re-ordered. However, in this particular case we have an "optimized"
smp_mb_after_atomic_inc(), perhaps it is good that the caller can choose
the "right" barrier by hand.

Oleg.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/