Help with semaphores/locks, anyone?

Roman Mitnitski (roman@checkpoint.com)
Thu, 9 Sep 1999 12:33:36 +0200


I am having a huge trouble getting semaphores to work in my code.

The code looks like this:

struct semaphore my_sem=MUTEX;

ioctl_handler()
{
down(&my_sem);
...
up(&my_sem);
}

in_the_interrupt()
{
down(&my_sem);
...
up(&my_sem);
}

My indended purpose of the semaphore is to avoid the situation when the
code in the "in_the_interrupt" changes stuff while ioctl_handler
was changing it.

The driver using this code crashes very soon after loading, in the

with the following fault:
Scheduling in the interrupt
Unable to handle kernel NULL dereference at virtual address 00000000
current->tss.cr3=022e1000 , %cr3=022e1000
*pde=00000000
entering kdb due to panic at 0xc0110b2e
....
stack:
schedule(0xC48ABFF0,0xC0F42D80)
__down(0x48EB02C,0x1,0xC0095B60)
__down_failed(...)

kdbg shows that the count field of the semaphore == -1.

When I disable interrupts in the ioctl_handler()
the crash goes away, but I would rather avoid disabling all
interrupts (for performance reasons), I only need to protect the
access to my variables.

I suspect that I don't understand something very fundamental
here, please help :)

(uh, the kernel is 2.2.10)

Thanks.
Roman

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