3
votes

Imagine that a device function holds a spinlock to control access to the device. While the lock is held, the device issues an interrupt, which causes an interrupt handler to run. The interrupt handler, before accessing the device, must also obtain the lock.

Suppose that the interrupt handler executes in the same processor as the code that took out the lock originally.

Knowing that to hold spinlock disables preemption on the relevant processor, is it possible that the code that holds the spinlock be executed on another processor (because of preemption on this processor)? (We suppose that this is a SMP machine)

1

1 Answers

1
votes
Is it possible that the code that holds the spinlock be executed on another processor (because of preemption on this processor)?

No, the code just keeps waiting for the interrupt handler to return.

Just use spin_lock_irq*(), or spin_lock_bh() if you also want to protect against softirqs/tasklets.