Skip to contentSkip to conversation

irqchip/apple-aic: fix irq_disable from within irq handlers

PATCH Applied Sven Peter 4 participants 4 messages Aug 12, 2021 – Aug 20, 2021

Subsystems (2)
lore
Share & tools
lore

Sven Peter

author
#0 lore raw

PATCH 1/1 irqchip/apple-aic: fix irq_disable from within irq handlers

When disable_irq_nosync for an interrupt is called from within its interrupt handler, this interrupt is only marked as disabled with the intention to mask it when it triggers again.
The AIC hardware however automatically masks the interrupt when it is read. aic_irq_eoi then unmasks it again if it's not disabled *and* not masked. This results in a state mismatch between the hardware state and the state kept in irq_data: The hardware interrupt is masked but IRQD_IRQ_MASKED is not set. Any further calls to unmask_irq will directly return and the interrupt can never be enabled again.

Fix this by keeping the hardware and irq_data state in sync by unmasking in aic_irq_eoi if and only if the irq_data state also assumes the interrupt to be unmasked.

Fixes 76cde2639411 ("irqchip/apple-aic: Add support for the Apple Interrupt Controller")
---
 drivers/irqchip/irq-apple-aic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-apple-aic.c +1 -1
index b8c06bd8659e..6fc145aacaf0 100644
@@ -226,7 +226,7 @@ static void aic_irq_eoi(struct irq_data *d)
 	 * Reading the interrupt reason automatically acknowledges and masks
 	 * the IRQ, so we just unmask it here if needed.
 	 */
-	if (!irqd_irq_disabled(d) && !irqd_irq_masked(d))
+	if (!irqd_irq_masked(d))
 		aic_irq_unmask(d);
 }
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

*Puts on kernel maintainer hat again*

Sorry for the delay. I've been spending too much time on hardware RE recently...

Quoted 26 lines · Sven Peter

When disable_irq_nosync for an interrupt is called from within its interrupt handler, this interrupt is only marked as disabled with the intention to mask it when it triggers again.
The AIC hardware however automatically masks the interrupt when it is read. aic_irq_eoi then unmasks it again if it's not disabled *and* not masked. This results in a state mismatch between the hardware state and the state kept in irq_data: The hardware interrupt is masked but IRQD_IRQ_MASKED is not set. Any further calls to unmask_irq will directly return and the interrupt can never be enabled again.

Fix this by keeping the hardware and irq_data state in sync by unmasking in aic_irq_eoi if and only if the irq_data state also assumes the interrupt to be unmasked.

Fixes 76cde2639411 ("irqchip/apple-aic: Add support for the Apple Interrupt Controller")
---
  drivers/irqchip/irq-apple-aic.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-apple-aic.c +0 -0
index b8c06bd8659e..6fc145aacaf0 100644

drivers/irqchip/irq-apple-aic.c static void aic_irq_eoi(struct irq_data *d) · line 232

Quoted 8 lines
drivers/irqchip/irq-apple-aic.c +1 -1
@@ -226,7 +226,7 @@ static void aic_irq_eoi(struct irq_data *d)
  	 * Reading the interrupt reason automatically acknowledges and masks
  	 * the IRQ, so we just unmask it here if needed.
  	 */
-	if (!irqd_irq_disabled(d) && !irqd_irq_masked(d))
+	if (!irqd_irq_masked(d))
  		aic_irq_unmask(d);
  }
 

Looks good to me. I can't remember exactly where this code came from, but looking again at the irqchip code it's clear that the mask state and hardware mask always have to be in sync.

Signature · 7 lines
Hector Martin ([email protected])
Public Key: https://mrcn.st/pub

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Applied
#2 lore raw
In reply to Sven Peter
Quoted 11 lines · Sven Peter

When disable_irq_nosync for an interrupt is called from within its interrupt handler, this interrupt is only marked as disabled with the intention to mask it when it triggers again.
The AIC hardware however automatically masks the interrupt when it is read. aic_irq_eoi then unmasks it again if it's not disabled *and* not masked. This results in a state mismatch between the hardware state and the state kept in irq_data: The hardware interrupt is masked but IRQD_IRQ_MASKED is not set. Any further calls to unmask_irq will directly return and the interrupt can never be enabled again.

[...]

Applied to irq/misc-5.15, thanks!

[1/1] irqchip/apple-aic: fix irq_disable from within irq handlers

      commit: 0fb038ba08dba0a5e937b79a67ed9c21ab5b59c5

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
merge bot Applied
#3 lore raw

[irqchip: irq/irqchip-next] irqchip/apple-aic: Fix irq_disable from within irq handlers

In reply to Sven Peter
The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     60a1cd10b222e004f860d14651e80089c77e8e6b
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/60a1cd10b222e004f860d14651e80089c77e8e6b
Author:        Sven Peter <[email protected]>
AuthorDate:    Thu, 12 Aug 2021 12:09:42 +02:00
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Fri, 20 Aug 2021 14:32:33 +01:00

irqchip/apple-aic: Fix irq_disable from within irq handlers

When disable_irq_nosync for an interrupt is called from within its interrupt handler, this interrupt is only marked as disabled with the intention to mask it when it triggers again.
The AIC hardware however automatically masks the interrupt when it is read. aic_irq_eoi then unmasks it again if it's not disabled *and* not masked. This results in a state mismatch between the hardware state and the state kept in irq_data: The hardware interrupt is masked but IRQD_IRQ_MASKED is not set. Any further calls to unmask_irq will directly return and the interrupt can never be enabled again.

Fix this by keeping the hardware and irq_data state in sync by unmasking in aic_irq_eoi if and only if the irq_data state also assumes the interrupt to be unmasked.

Fixes 76cde2639411 ("irqchip/apple-aic: Add support for the Apple Interrupt Controller")
---
 drivers/irqchip/irq-apple-aic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-apple-aic.c +1 -1
index b8c06bd..6fc145a 100644
@@ -226,7 +226,7 @@ static void aic_irq_eoi(struct irq_data *d)
 	 * Reading the interrupt reason automatically acknowledges and masks
 	 * the IRQ, so we just unmask it here if needed.
 	 */
-	if (!irqd_irq_disabled(d) && !irqd_irq_masked(d))
+	if (!irqd_irq_masked(d))
 		aic_irq_unmask(d);
 }