Irq_mask_ack
irq_mask_ack: The Optional Optimization at the Heart of Linux IRQ Handling
In struct irq_chip, irq_mask_ack carries a compact description: “ack and mask an interrupt source”. That line is accurate, but it does not explain why the callback exists at all. irq_mask and irq_ack already do the work individually. irq_mask_ack is not a third primitive; it is an optional fusion of the other two, and the Linux interrupt framework is fully prepared to function without it. Understanding why it is optional, and why drivers still implement it, reveals how the IRQ subsystem trades code simplicity against hot-path efficiency.
Mask and ack are not the same operation
The two callbacks that irq_mask_ack combines address different things. irq_mask disables an interrupt source at the controller: once masked, that source can no longer raise a new request. irq_ack acknowledges the interrupt that has already occurred, allowing the controller to retire the current transaction and proceed with delivery in general. Acknowledgment does not unmask the source. Masking closes the door; acking tells the controller that the interruption already inside has been dealt with. They operate on different axes, which is why performing mask and then ack does not “undo” the mask.
The framework falls back automatically
If a driver does not provide irq_mask_ack, the generic helper mask_ack_irq() does not fail or warn. It simply calls irq_mask and irq_ack in sequence. This behavior is stated plainly in a 2014 commit by Maxime Ripard: “If irq_mask_ack is not defined, mask_ack_irq will call irq_mask and then irq_ack.” The design guarantees correctness without requiring every irqchip driver to implement a combined callback.
This fallback was discussed explicitly on the Linux kernel mailing list. In a 2017 thread about the Tango irqchip, Doug Berger confirmed the intent without ambiguity:
“The irq_mask_ack method is entirely optional and I assume that is why this issue went undetected for so long”.
The framework will “do the right thing” either way. A driver author can implement only the two basic primitives and still have a working interrupt controller.
Why implement it anyway: the hot-path argument
If the fallback is correct, the only remaining reason to provide irq_mask_ack is efficiency. Berger framed the trade-off directly in the same thread:
“However, it is slightly more efficient to combine the functions (even if the ack is unnecessary)… How much value the improved efficiency has is certainly debatable, but interrupt handling is one area where people might care about such a small difference”.
A follow-up message in that discussion made the concrete cost explicit: “Using the separate mask and ack functions obviously works, but combining them saves a lock/unlock sequence”. In interrupt context, a lock/unlock sequence is not abstract overhead. It involves atomic operations and lock management on a path where interrupts may be disabled and latency matters. A combined callback allows the controller driver to issue the mask and the ack under one acquisition of whatever internal lock protects its register access, rather than two.
There is a second, subtler efficiency benefit. As explained in a MediaTek pinctrl discussion, mask_ack_irq() when backed by irq_mask_ack bypasses the mask_irq() path that “needs to judge IRQD_IRQ_MASKED”. The generic layer tracks whether an IRQ is already masked; the separate mask_irq() path consults that state before acting. A combined irq_mask_ack callback can skip that check, because the driver is explicitly performing a mask-and-ack operation regardless of the previously recorded software state. This removes a conditional branch and a state inspection from the interrupt hot path—a small but real saving in code that runs for every interrupt.
Mask-then-ack is the safe ordering
The combined callback should not be read as “mask, then later unmask.” It is a single step from the framework’s perspective: prevent the source from generating further requests, and retire the request currently being serviced. The ordering mask first, then ack matters for level-triggered interrupts. If the device is still asserting its line and the controller acks without masking, the still-active level can be re-latched and the same interrupt reported again. Masking first removes that risk before the ack clears the pending state. irq_mask_ack lets the driver express this ordering in one hardware programming sequence rather than two.
For edge-triggered interrupts, the ack clears the latched edge, and the mask prevents a new edge from being delivered until an unmask occurs. The combined callback does not change the semantics; it simply fuses the two register operations into one callback invocation.
A note on the irq_ack comment
The kernel header describes irq_ack as “start of a new interrupt”. That phrase is easily misread as “allow a new interrupt,” which would suggest a contradiction when ack follows mask. What it actually means is narrower: by acknowledging the current interrupt, the controller is allowed to proceed with interrupt delivery in general, not with delivery from the specific source that was just masked. The acknowledgment retires the current transaction; the mask still governs whether that source may initiate another. They remain separate concerns.
Conclusion
irq_mask_ack is best understood as a performance escape hatch, not a semantic requirement. The Linux IRQ framework guarantees correct behavior through the irq_mask + irq_ack fallback when the callback is absent. Drivers that provide it are buying a measurable reduction in hot-path overhead: one lock acquisition instead of two, and in some implementations a bypass of the generic IRQD_IRQ_MASKED check. The kernel mailing list record makes the trade-off explicit: the callback is optional, the fallback works, and the reason to implement it is that interrupt handling is one of the few places where saving a lock/unlock sequence justifies the extra line of driver code.