According to what I've read so far, "when the kernel receives an interrupt, all the registered handlers are invoked."
I understand that the registered handlers for each IRQ can be viewed via
/proc/interrupts, and I also understand that the registered handlers come from the drivers that have invoked request_irq passing in a callback roughly of the form:
irqreturn_t (*handler)(int, void *)
Based on what I know, each of these interrupt handler callbacks associated with the particular IRQ should be invoked, and it is up to the handler to determine whether the interrupt should be handled by it. If the handler should not handle the particular interrupt it must return the kernel macro
What I am having trouble understanding is how each driver is expected to determine whether it should handle the interrupt or not. I suppose they can keep track internally if they're supposed to be expecting an interrupt. If so, I don't know how they'd be able to deal with the situation in which multiple drivers behind the same IRQ are expecting an interrupt.
The reason I'm trying to understand these details is because I'm messing with the kexec mechanism to re-execute the kernel in the middle of system operation while playing with the reset pins and various registers on a PCIe bridge as well as a downstream PCI device. And in doing so, after a reboot I'm either getting kernel panics, or other drivers complaining that they're receiving interrupts even though no operation was taking place.
How the handler decided that the interrupt should be handled by it is the mystery.
Edit: In case it's relevant, the CPU architecture in question is x86.