Skip to contentSkip to conversation

net: phy: make phy_stop() synchronous

PATCH In review Heiner Kallweit 4 participants 8 messages Sep 19, 2018 – Sep 20, 2018

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover net: phy: make phy_stop() synchronous

There have been few not that successful attempts in the past to make phy_stop() a synchronous call instead of just changing the state. Patch 1 of this series addresses an issue which prevented this change. At least for me it works fine now. Would appreciate if Geert could re-test as well that suspend doesn't throw an error.

Heiner Kallweit (2):
net: linkwatch: add check for netdevice being present to linkwatch_do_dev
net: phy: call state machine synchronously in phy_stop

 drivers/net/phy/phy.c | 2 ++
 net/core/link_watch.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
2.19.0
author maintainer
#1 lore raw

PATCH 1/2 net: linkwatch: add check for netdevice being present to linkwatch_do_dev

When bringing down the netdevice (incl. detaching it) and calling netif_carrier_off directly or indirectly the latter triggers an asynchronous linkwatch event.
This linkwatch event eventually may fail to access chip registers in the ndo_get_stats/ndo_get_stats64 callback because the device isn't accessible any longer, see call trace in [0].

To prevent this scenario don't check for IFF_UP only, but also make sure that the netdevice is present.

[0] https://lists.openwall.net/netdev/2018/03/15/62

---
 net/core/link_watch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/link_watch.c +1 -1
index e38e641e9..7f51efb2b 100644
@@ -155,7 +155,7 @@ static void linkwatch_do_dev(struct net_device *dev)
 	clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state);
 
 	rfc2863_policy(dev);
-	if (dev->flags & IFF_UP) {
+	if (dev->flags & IFF_UP && netif_device_present(dev)) {
 		if (netif_carrier_ok(dev))
 			dev_activate(dev);
 		else
Signature · 1 line
2.19.0
author maintainer
#4 lore raw

PATCH 2/2 net: phy: call state machine synchronously in phy_stop

In reply to Heiner Kallweit

phy_stop() may be called e.g. when suspending, therefore all needed actions should be performed synchronously. Therefore add a synchronous call to the state machine.

---
 drivers/net/phy/phy.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/phy/phy.c +2 -0
index c78203b25..f5bb6a7a8 100644
@@ -861,6 +861,8 @@ void phy_stop(struct phy_device *phydev)
 out_unlock:
 	mutex_unlock(&phydev->lock);
 
+	phy_state_machine(&phydev->state_queue.work);
+
 	/* Cannot call flush_scheduled_work() here as desired because
 	 * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change()
 	 * will not reenable interrupts.
Signature · 1 line
2.19.0
Tested-by on v1 1/2
#2 lore raw

Re: [PATCH net-next 1/2] net: linkwatch: add check for netdevice being present to linkwatch_do_dev

In reply to Heiner Kallweit
Quoted 7 lines · Heiner Kallweit

When bringing down the netdevice (incl. detaching it) and calling netif_carrier_off directly or indirectly the latter triggers an asynchronous linkwatch event.
This linkwatch event eventually may fail to access chip registers in the ndo_get_stats/ndo_get_stats64 callback because the device isn't accessible any longer, see call trace in [0].

Quoted 6 lines

To prevent this scenario don't check for IFF_UP only, but also make sure that the netdevice is present.

[0] https://lists.openwall.net/netdev/2018/03/15/62

Survived 100 suspend/resume cycles on sh73a0/kzm9g and r8a73a4/ape6evm.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Tested-by on v1 2/2
#5 lore raw

Re: [PATCH net-next 2/2] net: phy: call state machine synchronously in phy_stop

In reply to Heiner Kallweit
Quoted 5 lines · Heiner Kallweit

phy_stop() may be called e.g. when suspending, therefore all needed actions should be performed synchronously. Therefore add a synchronous call to the state machine.

Survived 100 suspend/resume cycles on sh73a0/kzm9g and r8a73a4/ape6evm.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH net-next 1/2] net: linkwatch: add check for netdevice being present to linkwatch_do_dev

In reply to Heiner Kallweit
Quoted 7 lines · Heiner Kallweit

When bringing down the netdevice (incl. detaching it) and calling netif_carrier_off directly or indirectly the latter triggers an asynchronous linkwatch event.
This linkwatch event eventually may fail to access chip registers in the ndo_get_stats/ndo_get_stats64 callback because the device isn't accessible any longer, see call trace in [0].

Quoted 6 lines

To prevent this scenario don't check for IFF_UP only, but also make sure that the netdevice is present.

[0] https://lists.openwall.net/netdev/2018/03/15/62

Thanks Heiner!

Signature · 1 line
Florian
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH net-next 2/2] net: phy: call state machine synchronously in phy_stop

In reply to Heiner Kallweit
Quoted 5 lines · Heiner Kallweit

phy_stop() may be called e.g. when suspending, therefore all needed actions should be performed synchronously. Therefore add a synchronous call to the state machine.

Yes!

Signature · 1 line
Florian
maintainer
#7 lore raw
In reply to Heiner Kallweit

From: Heiner Kallweit <[email protected]>
Date: Tue, 18 Sep 2018 21:54:23 +0200

Quoted 5 lines

There have been few not that successful attempts in the past to make phy_stop() a synchronous call instead of just changing the state. Patch 1 of this series addresses an issue which prevented this change. At least for me it works fine now. Would appreciate if Geert could re-test as well that suspend doesn't throw an error.

Series applied, thank you.