Skip to contentSkip to conversation

net: phy: fix interrupt handling in non-started states

PATCH Applied Heiner Kallweit 4 participants 6 messages Feb 12, 2019 – Feb 14, 2019

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH 1/1 net: phy: fix interrupt handling in non-started states

phylib enables interrupts before phy_start() has been called, and if we receive an interrupt in a non-started state, the interrupt handler returns IRQ_NONE. This causes problems with at least one Marvell chip as reported by Andrew.
Fix this by handling interrupts the same as in phy_mac_interrupt(), basically always running the phylib state machine. It knows when it has to do something and when not.
This change allows to handle interrupts gracefully even if they occur in a non-started state.

Fixes 2b3e88ea6528 ("net: phy: improve phy state checking")
---
 drivers/net/phy/phy.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/phy/phy.c +0 -3
index 189cd2048c3a..ca5e0c0f018c 100644
@@ -762,9 +762,6 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
 {
 	struct phy_device *phydev = phy_dat;
 
-	if (!phy_is_started(phydev))
-		return IRQ_NONE;		/* It can't be ours.  */
-
 	if (phydev->drv->did_interrupt && !phydev->drv->did_interrupt(phydev))
 		return IRQ_NONE;
 
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 22 lines · Heiner Kallweit

phylib enables interrupts before phy_start() has been called, and if we receive an interrupt in a non-started state, the interrupt handler returns IRQ_NONE. This causes problems with at least one Marvell chip as reported by Andrew.
Fix this by handling interrupts the same as in phy_mac_interrupt(), basically always running the phylib state machine. It knows when it has to do something and when not.
This change allows to handle interrupts gracefully even if they occur in a non-started state.

Fixes 2b3e88ea6528 ("net: phy: improve phy state checking")
---
 drivers/net/phy/phy.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/phy/phy.c +0 -0
index 189cd2048c3a..ca5e0c0f018c 100644

drivers/net/phy/phy.c static irqreturn_t phy_interrupt(int irq, void *phy_dat) · line 766

Quoted 8 lines
drivers/net/phy/phy.c +0 -3
@@ -762,9 +762,6 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
 {
 	struct phy_device *phydev = phy_dat;
 
-	if (!phy_is_started(phydev))
-		return IRQ_NONE;		/* It can't be ours.  */
-
 	if (phydev->drv->did_interrupt && !phydev->drv->did_interrupt(phydev))
 		return IRQ_NONE;

Hi Heiner

Did you look at

ommit 3c3070d713d798f7f9e7ee3614e49b47655d14d8

Author: Maciej W. Rozycki <[email protected]>
Date:   Tue Oct 3 16:18:35 2006 +0100

[PATCH] 2.6.18: sb1250-mac: Phylib IRQ handling fixes

This patch fixes a couple of problems discovered with interrupt handling
in the phylib core, namely:

1. The driver uses timer and workqueue calls, but does not include <linux/timer.h> nor <linux/workqueue.h>.

2. The driver uses schedule_work() for handling interrupts, but does not make sure any pending work scheduled thus has been completed before driver's structures get freed from memory. This is especially important as interrupts may keep arriving if the line is shared with another PHY.

The solution is to ignore phy_interrupt() calls if the reported device has already been halted and calling flush_scheduled_work() from phy_stop_interrupts() (but guarded with current_is_keventd() in case the function has been called through keventd from the MAC device's close call to avoid a deadlock on the netlink lock).

patch-mips-2.6.18-20060920-phy-irq-16

There has been a lot of change since then, so maybe this is no longer an issue?

Thanks
Andrew

author maintainer
#2 lore raw
Quoted 34 lines · Andrew Lunn
Quoted 22 lines · Heiner Kallweit

phylib enables interrupts before phy_start() has been called, and if we receive an interrupt in a non-started state, the interrupt handler returns IRQ_NONE. This causes problems with at least one Marvell chip as reported by Andrew.
Fix this by handling interrupts the same as in phy_mac_interrupt(), basically always running the phylib state machine. It knows when it has to do something and when not.
This change allows to handle interrupts gracefully even if they occur in a non-started state.

Fixes 2b3e88ea6528 ("net: phy: improve phy state checking")
---
 drivers/net/phy/phy.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/phy/phy.c +0 -0
index 189cd2048c3a..ca5e0c0f018c 100644

drivers/net/phy/phy.c static irqreturn_t phy_interrupt(int irq, void *phy_dat) · line 766

Quoted 8 lines
drivers/net/phy/phy.c +0 -3
@@ -762,9 +762,6 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
 {
 	struct phy_device *phydev = phy_dat;
 
-	if (!phy_is_started(phydev))
-		return IRQ_NONE;		/* It can't be ours.  */
-
 	if (phydev->drv->did_interrupt && !phydev->drv->did_interrupt(phydev))
 		return IRQ_NONE;

Hi Heiner

Quoted 2 lines

Did you look at

Thanks for this interesting old read.

Quoted 9 lines

ommit 3c3070d713d798f7f9e7ee3614e49b47655d14d8

Author: Maciej W. Rozycki <[email protected]>
Date:   Tue Oct 3 16:18:35 2006 +0100

[PATCH] 2.6.18: sb1250-mac: Phylib IRQ handling fixes

This patch fixes a couple of problems discovered with interrupt handling
in the phylib core, namely:

Quoted 9 lines

1. The driver uses timer and workqueue calls, but does not include <linux/timer.h> nor <linux/workqueue.h>.

2. The driver uses schedule_work() for handling interrupts, but does not make sure any pending work scheduled thus has been completed before driver's structures get freed from memory. This is especially important as interrupts may keep arriving if the line is shared with another PHY.

Since that time this have massively changed and I *think* this doesn't apply any longer. cancel_delayed_work_sync() is called always before driver structure is freed.

Quoted 6 lines

The solution is to ignore phy_interrupt() calls if the reported device has already been halted and calling flush_scheduled_work() from phy_stop_interrupts() (but guarded with current_is_keventd() in case the function has been called through keventd from the MAC device's close call to avoid a deadlock on the netlink lock).

Quoted 8 lines

patch-mips-2.6.18-20060920-phy-irq-16

There has been a lot of change since then, so maybe this is no longer an issue?

AFAICS, yes. I'll have a closer look at the scenario described by Russell, this however should be independent of the patch here.

Quoted 3 lines

Thanks
Andrew

Heiner

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Heiner Kallweit
Quoted 10 lines · Heiner Kallweit

phylib enables interrupts before phy_start() has been called, and if we receive an interrupt in a non-started state, the interrupt handler returns IRQ_NONE. This causes problems with at least one Marvell chip as reported by Andrew.
Fix this by handling interrupts the same as in phy_mac_interrupt(), basically always running the phylib state machine. It knows when it has to do something and when not.
This change allows to handle interrupts gracefully even if they occur in a non-started state.

Quoted 3 lines
Fixes 2b3e88ea6528 ("net: phy: improve phy state checking")

Andrew

Reviewed-by on v1 1/1
#4 lore raw
In reply to Heiner Kallweit
Quoted 10 lines · Heiner Kallweit

phylib enables interrupts before phy_start() has been called, and if we receive an interrupt in a non-started state, the interrupt handler returns IRQ_NONE. This causes problems with at least one Marvell chip as reported by Andrew.
Fix this by handling interrupts the same as in phy_mac_interrupt(), basically always running the phylib state machine. It knows when it has to do something and when not.
This change allows to handle interrupts gracefully even if they occur in a non-started state.

Quoted 3 lines
Fixes 2b3e88ea6528 ("net: phy: improve phy state checking")
Signature · 1 line
Florian
maintainer Applied
#5 lore raw
In reply to Heiner Kallweit

From: Heiner Kallweit <[email protected]>
Date: Tue, 12 Feb 2019 19:56:15 +0100

Quoted 10 lines

phylib enables interrupts before phy_start() has been called, and if we receive an interrupt in a non-started state, the interrupt handler returns IRQ_NONE. This causes problems with at least one Marvell chip as reported by Andrew.
Fix this by handling interrupts the same as in phy_mac_interrupt(), basically always running the phylib state machine. It knows when it has to do something and when not.
This change allows to handle interrupts gracefully even if they occur in a non-started state.

Quoted 3 lines
Fixes 2b3e88ea6528 ("net: phy: improve phy state checking")

Applied, thanks Heiner.