<div dir="ltr">Hi!<br><br>I have a doubt about interrupts and spin locks.<br>I&#39;m not sure if I&#39;m in the good way:<br><br>When an interrupt is raised, the kernel (through do_IRQ and etc) acknowledges the interrupt and locks this IRQ taking a spin lock, so any other cpu can not handle this interrupt, and then the kernel executes the handler, if there is a handler available for that interrupt.<br><br>When we are on the handler interrupt , maybe we need to lock the cpu till we finish( if we are in a network driver, may we need to process some TX/RX packets ), <br>so if we have to lock the code we can do a spin_lock().<br>But with a spin_lock, even other CPU&#39;s can execute part of your code(code that is not part of the handler interrupt). <br>For example:<br><br>(this is an example in a network device driver)<br>The system has to transmit a packet, so network subsystem calls ndo_start_xmit. Inside this function we take a lock disabling the interrupts(spin_lock_irqsave) because we have to do some private things, but suddenly an interrupt is raised and we go to the interrupt handler, we take a spin_lock, we do some work (processing some RX/TX packets), and exites from the interrupt handler, and then we come back to the ndo_start_xmit when we were.<br><br>As far I could understand( I have read <a href="http://www.makelinux.net/ldd3/chp-5-sect-5">http://www.makelinux.net/ldd3/chp-5-sect-5</a> ), spin_lock_irqsave only disables the interrupts for the local cpu(where the code is executed), <br>so I think that another cpu took the handler interrupt.<br>The problem is if I&#39;m working with irq disabled, because I have to handle a private structure and suddenly interrupts is taking place, the interrupt can manipulate the code that I&#39;m trying to keep safe.<br>Is there any advice? Maybe that is happened because the code within my critical section on ndo_start_xmit has to be atomic? Otherwise it can go to sleep and I can lose my lock?<br><br>Thank you very much<br>Oscar Salvador<br></div>