[RFC] down and down_interruptible on x86

From: BALBIR SINGH (balbir.singh@wipro.com)
Date: Thu Jun 13 2002 - 00:17:00 EST


Hello, All,

I am a little confused about down and down_interruptible.
My mixed mind tells me it might be a bug in __down() and
__down_interruptible()

snippet from semaphore.c

int __down_interruptible(struct semaphore * sem)
{
....

                /*
                 * With signals pending, this turns into
                 * the trylock failure case - we won't be
                 * sleeping, and we* can't get the lock as
                 * it has contention. Just correct the count
                 * and exit.
                 */
                if (signal_pending(current)) {
                        retval = -EINTR;
                        sem->sleepers = 0;
                        atomic_add(sleepers, &sem->count);
                        break;
                }
.....

        spin_unlock_irq(&semaphore_lock);
        tsk->state = TASK_RUNNING;
        remove_wait_queue(&sem->wait, &wait);
        wake_up(&sem->wait); <---------------------
Is this correct?
        return retval;
}

Lets assume that two processes/threads called down_interruptible on a
semaphore.

P1 P2
--- ---

down_interruptible() down_interruptible()
 | |
 V V
Did not get semaphore, so signals pending, so leave (break
in the signal_pending if)
waits in the wait queue
 | |
 V V
schedule() Remove self from
wait_queue
                                                        |
                                                        V
                                                Call wake_up on
&sem->wait

Wont wake_up(&sem->wait), wakeup p1, so then when up() is called for
waking up P1,
the system will panic.

Am I missing something?

Warm Regards,
Balbir



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



This archive was generated by hypermail 2b29 : Sat Jun 15 2002 - 22:00:27 EST