Skip to contentSkip to conversation

net: phy: avoid clearing PHY interrupts twice in irq handler

PATCH In review Heiner Kallweit 3 participants 6 messages Mar 1, 2020 – Mar 4, 2020

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH 1/1 net: phy: avoid clearing PHY interrupts twice in irq handler

On all PHY drivers that implement did_interrupt() reading the interrupt status bits clears them. This means we may loose an interrupt that is triggered between calling did_interrupt() and phy_clear_interrupt(). As part of the fix make it a requirement that did_interrupt() clears the interrupt.

The Fixes tag refers to the first commit where the patch applies cleanly.

Fixes 49644e68f472 ("net: phy: add callback for custom interrupt handler to struct phy_driver")
---
 drivers/net/phy/phy.c | 3 ++-
 include/linux/phy.h   | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phy.c +2 -1
index d76e038cf..16e3fb79e 100644
@@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
 		phy_trigger_machine(phydev);
 	}
 
-	if (phy_clear_interrupt(phydev))
+	/* did_interrupt() may have cleared the interrupt already */
+	if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
 		goto phy_err;
 	return IRQ_HANDLED;
 
include/linux/phy.h +1 -0
index 80f8b2158..8b299476b 100644
@@ -557,6 +557,7 @@ struct phy_driver {
 	/*
 	 * Checks if the PHY generated an interrupt.
 	 * For multi-PHY devices with shared PHY interrupt pin
+	 * Set interrupt bits have to be cleared.
 	 */
 	int (*did_interrupt)(struct phy_device *phydev);
 
Signature · 1 line
2.25.1
#1 lore raw

Am 2020-03-01 21:36, schrieb Heiner Kallweit:

Quoted 5 lines

On all PHY drivers that implement did_interrupt() reading the interrupt status bits clears them. This means we may loose an interrupt that is triggered between calling did_interrupt() and phy_clear_interrupt(). As part of the fix make it a requirement that did_interrupt() clears the interrupt.

Looks good. But how would you use did_interrupt() and handle_interrupt() together? I guess you can't. At least not if handle_interrupt() has to read the pending bits again. So you'd have to handle custom interrupts in did_interrupt(). Any idea how to solve that?

[I know, this is only about fixing the lost interrupts.]

-michael

Quoted 39 lines

The Fixes tag refers to the first commit where the patch applies cleanly.

Fixes 49644e68f472 ("net: phy: add callback for custom interrupt

handler to struct phy_driver")

---
 drivers/net/phy/phy.c | 3 ++-
 include/linux/phy.h   | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phy.c +2 -1
index d76e038cf..16e3fb79e 100644
@@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void 
 *phy_dat)
 		phy_trigger_machine(phydev);
 	}
 
-	if (phy_clear_interrupt(phydev))
+	/* did_interrupt() may have cleared the interrupt already */
+	if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
 		goto phy_err;
 	return IRQ_HANDLED;
include/linux/phy.h +1 -0
index 80f8b2158..8b299476b 100644
@@ -557,6 +557,7 @@ struct phy_driver {
 	/*
 	 * Checks if the PHY generated an interrupt.
 	 * For multi-PHY devices with shared PHY interrupt pin
+	 * Set interrupt bits have to be cleared.
 	 */
 	int (*did_interrupt)(struct phy_device *phydev);
author maintainer
#2 lore raw
Quoted 7 lines · Michael Walle

Am 2020-03-01 21:36, schrieb Heiner Kallweit:

Quoted 5 lines

On all PHY drivers that implement did_interrupt() reading the interrupt status bits clears them. This means we may loose an interrupt that is triggered between calling did_interrupt() and phy_clear_interrupt(). As part of the fix make it a requirement that did_interrupt() clears the interrupt.

Quoted 7 lines

Looks good. But how would you use did_interrupt() and handle_interrupt() together? I guess you can't. At least not if handle_interrupt() has to read the pending bits again. So you'd have to handle custom interrupts in did_interrupt(). Any idea how to solve that?

[I know, this is only about fixing the lost interrupts.]

Right, this one is meant for stable to fix the issue with the potentially lost interrupts. Based on it I will submit a patch for net-next that tackles the issue that did_interrupt() has to read (and therefore clear) irq status bits and therefore makes them unusable for handle_interrupt(). The basic idea is that did_interrupt() is called only if handle_interrupt() isn't implemented. handle_interrupt() has to include the did_interrupt functionality. It can read the irq status once and store it in a variable for later use.

Quoted 40 lines

-michael

Quoted 38 lines

The Fixes tag refers to the first commit where the patch applies cleanly.

Fixes 49644e68f472 ("net: phy: add callback for custom interrupt

handler to struct phy_driver")

---
 drivers/net/phy/phy.c | 3 ++-
 include/linux/phy.h   | 1 +

 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phy.c +2 -1
index d76e038cf..16e3fb79e 100644
@@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
          phy_trigger_machine(phydev);
      }
 
-    if (phy_clear_interrupt(phydev))
+    /* did_interrupt() may have cleared the interrupt already */
+    if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
          goto phy_err;
      return IRQ_HANDLED;
 
include/linux/phy.h +1 -0
index 80f8b2158..8b299476b 100644
@@ -557,6 +557,7 @@ struct phy_driver {
      /*
       * Checks if the PHY generated an interrupt.
       * For multi-PHY devices with shared PHY interrupt pin
+     * Set interrupt bits have to be cleared.
       */
      int (*did_interrupt)(struct phy_device *phydev);
author maintainer
#3 lore raw
Quoted 15 lines · Heiner Kallweit
Quoted 7 lines · Michael Walle

Am 2020-03-01 21:36, schrieb Heiner Kallweit:

Quoted 5 lines

On all PHY drivers that implement did_interrupt() reading the interrupt status bits clears them. This means we may loose an interrupt that is triggered between calling did_interrupt() and phy_clear_interrupt(). As part of the fix make it a requirement that did_interrupt() clears the interrupt.

Quoted 7 lines

Looks good. But how would you use did_interrupt() and handle_interrupt() together? I guess you can't. At least not if handle_interrupt() has to read the pending bits again. So you'd have to handle custom interrupts in did_interrupt(). Any idea how to solve that?

[I know, this is only about fixing the lost interrupts.]

Quoted 9 lines

Right, this one is meant for stable to fix the issue with the potentially lost interrupts. Based on it I will submit a patch for net-next that tackles the issue that did_interrupt() has to read (and therefore clear) irq status bits and therefore makes them unusable for handle_interrupt(). The basic idea is that did_interrupt() is called only if handle_interrupt() isn't implemented. handle_interrupt() has to include the did_interrupt functionality. It can read the irq status once and store it in a variable for later use.

In case you wait for this patch to base further own work on it:
I'm waiting for next merge of net into net-next, because my patch will apply cleanly only after that. This merge should happen in the next days.

Quoted 41 lines
Quoted 40 lines

-michael

Quoted 38 lines

The Fixes tag refers to the first commit where the patch applies cleanly.

Fixes 49644e68f472 ("net: phy: add callback for custom interrupt

handler to struct phy_driver")

---
 drivers/net/phy/phy.c | 3 ++-
 include/linux/phy.h   | 1 +

 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phy.c +2 -1
index d76e038cf..16e3fb79e 100644
@@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
          phy_trigger_machine(phydev);
      }
 
-    if (phy_clear_interrupt(phydev))
+    /* did_interrupt() may have cleared the interrupt already */
+    if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
          goto phy_err;
      return IRQ_HANDLED;
 
include/linux/phy.h +1 -0
index 80f8b2158..8b299476b 100644
@@ -557,6 +557,7 @@ struct phy_driver {
      /*
       * Checks if the PHY generated an interrupt.
       * For multi-PHY devices with shared PHY interrupt pin
+     * Set interrupt bits have to be cleared.
       */
      int (*did_interrupt)(struct phy_device *phydev);
#4 lore raw

Am 2020-03-04 13:13, schrieb Heiner Kallweit:

Quoted 25 lines · Heiner Kallweit
Quoted 15 lines · Michael Walle
Quoted 7 lines

Am 2020-03-01 21:36, schrieb Heiner Kallweit:

Quoted 5 lines

On all PHY drivers that implement did_interrupt() reading the interrupt status bits clears them. This means we may loose an interrupt that is triggered between calling did_interrupt() and phy_clear_interrupt(). As part of the fix make it a requirement that did_interrupt() clears the interrupt.

Quoted 7 lines

Looks good. But how would you use did_interrupt() and handle_interrupt() together? I guess you can't. At least not if handle_interrupt() has to read the pending bits again. So you'd have to handle custom interrupts in did_interrupt(). Any idea how to solve that?

[I know, this is only about fixing the lost interrupts.]

Quoted 9 lines

Right, this one is meant for stable to fix the issue with the potentially lost interrupts. Based on it I will submit a patch for net-next that tackles the issue that did_interrupt() has to read (and therefore clear) irq status bits and therefore makes them unusable for handle_interrupt(). The basic idea is that did_interrupt() is called only if handle_interrupt() isn't implemented. handle_interrupt() has to include the did_interrupt functionality. It can read the irq status once and store it in a variable for later use.

Quoted 3 lines

In case you wait for this patch to base further own work on it:
I'm waiting for next merge of net into net-next, because my patch will apply cleanly only after that. This merge should happen in the next days.

Ok, thanks for the information. I have enough other things to do ;)

-michael

maintainer
#5 lore raw
In reply to Heiner Kallweit

From: Heiner Kallweit <[email protected]>
Date: Sun, 1 Mar 2020 21:36:09 +0100

Quoted 6 lines

On all PHY drivers that implement did_interrupt() reading the interrupt status bits clears them. This means we may loose an interrupt that is triggered between calling did_interrupt() and phy_clear_interrupt(). As part of the fix make it a requirement that did_interrupt() clears the interrupt.

Quoted 6 lines

The Fixes tag refers to the first commit where the patch applies cleanly.

Fixes 49644e68f472 ("net: phy: add callback for custom interrupt handler to struct phy_driver")

Applied and queued up for -stable, thanks.