Skip to contentSkip to conversation

spi: bcm2835aux: ensure interrupts are enabled for shared handler

PATCH In review Rob Herring 4 participants 7 messages May 3, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: bcm2835aux: ensure interrupts are enabled for shared handler

The BCM2835 AUX SPI has a shared interrupt line (with AUX UART). Downstream fixes this with an AUX irqchip to demux the IRQ sources and a DT change which breaks compatibility with older kernels. The AUX irqchip was already rejected for upstream[1] and the DT change would break working systems if the DTB is updated to a newer one. The latter issue was brought to my attention by Alex Graf.

The root cause however is a bug in the shared handler. Shared handlers must check that interrupts are actually enabled before servicing the interrupt. Add a check that the TXEMPTY or IDLE interrupts are enabled.

[1] https://patchwork.kernel.org/patch/9781221/

Cc Alexander Graf <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Mark Brown <[email protected]>
Cc Eric Anholt <[email protected]>
Cc Stefan Wahren <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc bcm-kernel-feedback-list at broadcom.com
Cc linux-spi at vger.kernel.org
Cc linux-rpi-kernel at lists.infradead.org
Cc linux-arm-kernel at lists.infradead.org

---
Compile tested only. I'll add something to the related github issue on this and hopefully someone can test and confirm.

I'm assuming the 8250 driver can handle shared irqs correctly.

Rob

 drivers/spi/spi-bcm2835aux.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/spi/spi-bcm2835aux.c +5 -0
index 1431cb98fe40..3094d818cf06 100644
@@ -184,6 +184,11 @@ static irqreturn_t bcm2835aux_spi_interrupt(int irq, void *dev_id)
 	struct bcm2835aux_spi *bs = spi_master_get_devdata(master);
 	irqreturn_t ret = IRQ_NONE;
 
+	/* IRQ may be shared, so return if our interrupts are disabled */
+	if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) &
+	      (BCM2835_AUX_SPI_CNTL1_TXEMPTY | BCM2835_AUX_SPI_CNTL1_IDLE)))
+		return ret;
+
 	/* check if we have data to read */
 	while (bs->rx_len &&
 	       (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/1 spi: bcm2835aux: ensure interrupts are enabled for shared handler

Hi,

[added Martin, Noralf and Phil]

Quoted 58 lines

Rob Herring <[email protected]> hat am 3. Mai 2018 um 20:09 geschrieben:

The BCM2835 AUX SPI has a shared interrupt line (with AUX UART). Downstream fixes this with an AUX irqchip to demux the IRQ sources and a DT change which breaks compatibility with older kernels. The AUX irqchip was already rejected for upstream[1] and the DT change would break working systems if the DTB is updated to a newer one. The latter issue was brought to my attention by Alex Graf.

The root cause however is a bug in the shared handler. Shared handlers must check that interrupts are actually enabled before servicing the interrupt. Add a check that the TXEMPTY or IDLE interrupts are enabled.

[1] https://patchwork.kernel.org/patch/9781221/

Cc Alexander Graf <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Mark Brown <[email protected]>
Cc Eric Anholt <[email protected]>
Cc Stefan Wahren <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc bcm-kernel-feedback-list at broadcom.com
Cc linux-spi at vger.kernel.org
Cc linux-rpi-kernel at lists.infradead.org
Cc linux-arm-kernel at lists.infradead.org

---
Compile tested only. I'll add something to the related github issue on this and hopefully someone can test and confirm.

I'm assuming the 8250 driver can handle shared irqs correctly.

Rob

 drivers/spi/spi-bcm2835aux.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/spi/spi-bcm2835aux.c +5 -0
index 1431cb98fe40..3094d818cf06 100644
@@ -184,6 +184,11 @@ static irqreturn_t bcm2835aux_spi_interrupt(int irq, void *dev_id)
 	struct bcm2835aux_spi *bs = spi_master_get_devdata(master);
 	irqreturn_t ret = IRQ_NONE;
 
+	/* IRQ may be shared, so return if our interrupts are disabled */
+	if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) &
+	      (BCM2835_AUX_SPI_CNTL1_TXEMPTY | BCM2835_AUX_SPI_CNTL1_IDLE)))
+		return ret;
+
 	/* check if we have data to read */
 	while (bs->rx_len &&
 	       (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
Signature · 1 line
2.17.0

does anyone have a setup to test this patch (i assume it requires a compute module)?

@Rob: Thank you very much for this patch

#2 lore raw

PATCH 1/1 spi: bcm2835aux: ensure interrupts are enabled for shared handler

In reply to Rob Herring
Quoted 10 lines · Rob Herring

The BCM2835 AUX SPI has a shared interrupt line (with AUX UART). Downstream fixes this with an AUX irqchip to demux the IRQ sources and a DT change which breaks compatibility with older kernels. The AUX irqchip was already rejected for upstream[1] and the DT change would break working systems if the DTB is updated to a newer one. The latter issue was brought to my attention by Alex Graf.

The root cause however is a bug in the shared handler. Shared handlers must check that interrupts are actually enabled before servicing the interrupt. Add a check that the TXEMPTY or IDLE interrupts are enabled.

It looks to me like we'd only return IRQ_HANDLED if we did work that
needed doing. Is this check effectively doing some interlock to make
sure that we've already started bcm2835aux_spi_transfer_one_irq() and
aren't just racing against transaction setup?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180503/566dc920/attachment.sig>

#3 lore raw

PATCH 1/1 spi: bcm2835aux: ensure interrupts are enabled for shared handler

Quoted 9 lines · Eric Anholt
Quoted 7 lines · Rob Herring

The BCM2835 AUX SPI has a shared interrupt line (with AUX UART). Downstream fixes this with an AUX irqchip to demux the IRQ sources and a DT change which breaks compatibility with older kernels. The AUX irqchip was already rejected for upstream[1] and the DT change would break working systems if the DTB is updated to a newer one. The latter issue was brought to my attention by Alex Graf.

Quoted 8 lines
Quoted 3 lines

The root cause however is a bug in the shared handler. Shared handlers must check that interrupts are actually enabled before servicing the interrupt. Add a check that the TXEMPTY or IDLE interrupts are enabled.

It looks to me like we'd only return IRQ_HANDLED if we did work that needed doing. Is this check effectively doing some interlock to make sure that we've already started bcm2835aux_spi_transfer_one_irq() and aren't just racing against transaction setup?

What if you are in polled mode for the SPI and the 8250 irq (or other SPI instance) causes the SPI irq handler to run?

The way I look at it is, this change in the irq handler was also said to fix the problem[1]:

    u32 irq_flags = readl(bcm2835_aux_irq_reg);

    if(!(irq_flags & (1<<master->bus_num)))
    {
        return IRQ_NONE;
    }

Is checking whether the interrupt is pending in the aux reg any different than checking for interrupt being enabled in the device? I could have checked the status bits too, but as you say that is handled farther down.

Rob

[1] https://github.com/raspberrypi/linux/issues/1573

#4 lore raw

PATCH 1/1 spi: bcm2835aux: ensure interrupts are enabled for shared handler

Quoted 19 lines · Rob Herring
Quoted 9 lines · Eric Anholt
Quoted 7 lines · Rob Herring

The BCM2835 AUX SPI has a shared interrupt line (with AUX UART). Downstream fixes this with an AUX irqchip to demux the IRQ sources and a DT change which breaks compatibility with older kernels. The AUX irqchip was already rejected for upstream[1] and the DT change would break working systems if the DTB is updated to a newer one. The latter issue was brought to my attention by Alex Graf.

Quoted 8 lines
Quoted 3 lines

The root cause however is a bug in the shared handler. Shared handlers must check that interrupts are actually enabled before servicing the interrupt. Add a check that the TXEMPTY or IDLE interrupts are enabled.

It looks to me like we'd only return IRQ_HANDLED if we did work that needed doing. Is this check effectively doing some interlock to make sure that we've already started bcm2835aux_spi_transfer_one_irq() and aren't just racing against transaction setup?

Quoted 7 lines

What if you are in polled mode for the SPI and the 8250 irq (or other SPI instance) causes the SPI irq handler to run?

Is checking whether the interrupt is pending in the aux reg any different than checking for interrupt being enabled in the device? I could have checked the status bits too, but as you say that is handled farther down.

It seems clearly different to me, in that one is about allowing the interrupt line to go high and the other is about whether the interrupt line is actually high right now.

However, the polled mode note explains to me what was going wrong, so:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180503/f9180838/attachment.sig>

maintainer
#5 lore raw

PATCH 1/1 spi: bcm2835aux: ensure interrupts are enabled for shared handler

In reply to Rob Herring
Quoted 3 lines · Rob Herring

The root cause however is a bug in the shared handler. Shared handlers must check that interrupts are actually enabled before servicing the interrupt. Add a check that the TXEMPTY or IDLE interrupts are enabled.

The requirement is more that the handler should correctly identify if it
actually handled an interrupt - especially if the driver doesn't enable
and disable the interrupt at runtime it's not going to upset anything to
always run the interrupt handling (and of course some hardware can't
disable things anyway) but if nohing happened then the handler needs to
return IRQ_NONE.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180504/fb07c019/attachment.sig>

maintainer
#6 lore raw

Applied "spi: bcm2835aux: ensure interrupts are enabled for shared handler" to the spi tree

In reply to Rob Herring

The patch

spi: bcm2835aux: ensure interrupts are enabled for shared handler

has been applied to the spi tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From bc519d9574618e47a0c788000fb78da95e18d953 Mon Sep 17 00:00:00 2001

From: Rob Herring <[email protected]>
Date: Thu, 3 May 2018 13:09:44 -0500
Subject: [PATCH] spi: bcm2835aux: ensure interrupts are enabled for shared
handler

The BCM2835 AUX SPI has a shared interrupt line (with AUX UART). Downstream fixes this with an AUX irqchip to demux the IRQ sources and a DT change which breaks compatibility with older kernels. The AUX irqchip was already rejected for upstream[1] and the DT change would break working systems if the DTB is updated to a newer one. The latter issue was brought to my attention by Alex Graf.

The root cause however is a bug in the shared handler. Shared handlers must check that interrupts are actually enabled before servicing the interrupt. Add a check that the TXEMPTY or IDLE interrupts are enabled.

[1] https://patchwork.kernel.org/patch/9781221/

Cc Alexander Graf <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Mark Brown <[email protected]>
Cc Eric Anholt <[email protected]>
Cc Stefan Wahren <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Ray Jui <[email protected]>
Cc Scott Branden <[email protected]>
Cc bcm-kernel-feedback-list at broadcom.com
Cc linux-spi at vger.kernel.org
Cc linux-rpi-kernel at lists.infradead.org
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/spi/spi-bcm2835aux.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/spi/spi-bcm2835aux.c +5 -0
index 1431cb98fe40..3094d818cf06 100644
@@ -184,6 +184,11 @@ static irqreturn_t bcm2835aux_spi_interrupt(int irq, void *dev_id)
 	struct bcm2835aux_spi *bs = spi_master_get_devdata(master);
 	irqreturn_t ret = IRQ_NONE;
 
+	/* IRQ may be shared, so return if our interrupts are disabled */
+	if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) &
+	      (BCM2835_AUX_SPI_CNTL1_TXEMPTY | BCM2835_AUX_SPI_CNTL1_IDLE)))
+		return ret;
+
 	/* check if we have data to read */
 	while (bs->rx_len &&
 	       (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) &
Signature · 1 line
2.17.0