3
votes

In Linux Kernel Development book (Robert Love), It is mentioned that :

we must disable local interrupts before obtaining spinlock in interrupt handler. Otherwise it is possible for an interrupt handler to interrupt kernel code while the lock is held and attempt to re-acquire the lock. Which finally can lead to double-acquire deadlock.

Now my doubt is:

  1. In general, doesn't do_IRQ() disables local interrupt ?
  2. And if lock is acquire, it means thatpreempt_count variable is not zero, which makes that no other handler should get chance, as kernel is not preempt_safe. So how other interrupt handler can work in this situation ?
1

1 Answers

2
votes

First, the do_IRQ() function dosn't disable the local interrupt, but some function written in assembly language does, which is the interrupt entrance. And later, before executing the interrupt function registering by request_irq(), in function handle_IRQ_event() a flag which also pass by request_irq() is compare with IRQF_DISABLED to determine whether we should enable the local interrupt when executing the interrupt function. So the answer to your question one is depending on the flags that you pass to the request_irq() function.

Second, preempt_count just means for kernel preemption in process context, but not for interrupt. To avoid interrupt handlers be executed in UP, the only way is involving the irqs_disable(). When the preempt_count is zero, it's said that the kernel can safely does the process switch, otherwise not.