netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] SFP polling fixes
@ 2019-06-07 16:42 Robert Hancock
  2019-06-07 16:42 ` [PATCH net-next 1/2 v2] net: sfp: Stop SFP polling and interrupt handling during shutdown Robert Hancock
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Robert Hancock @ 2019-06-07 16:42 UTC (permalink / raw)
  To: netdev; +Cc: linux, andrew, f.fainelli, hkallweit1, Robert Hancock

This has an updated version of an earlier patch to ensure that SFP
operations are stopped during shutdown, and another patch suggested by
Russell King to address a potential concurrency issue with SFP state
checks.

Robert Hancock (2):
  net: sfp: Stop SFP polling and interrupt handling during shutdown
  net: sfp: add mutex to prevent concurrent state checks

 drivers/net/phy/sfp.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2 v2] net: sfp: Stop SFP polling and interrupt handling during shutdown
  2019-06-07 16:42 [PATCH net-next 0/2] SFP polling fixes Robert Hancock
@ 2019-06-07 16:42 ` Robert Hancock
  2019-06-07 16:42 ` [PATCH net-next 2/2] net: sfp: add mutex to prevent concurrent state checks Robert Hancock
  2019-06-10  2:26 ` [PATCH net-next 0/2] SFP polling fixes David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Hancock @ 2019-06-07 16:42 UTC (permalink / raw)
  To: netdev; +Cc: linux, andrew, f.fainelli, hkallweit1, Robert Hancock

SFP device polling can cause problems during the shutdown process if the
parent devices of the network controller have been shut down already.
This problem was seen on the iMX6 platform with PCIe devices, where
accessing the device after the bus is shut down causes a hang.

Free any acquired GPIO interrupts and stop all delayed work in the SFP
driver during the shutdown process, so that we ensure that no pending
operations are still occurring after the SFP shutdown completes.

Signed-off-by: Robert Hancock <hancock@sedsystems.ca>
---

Changed since v1: Free interrupts during shutdown to avoid need for shutdown
state flag.

 drivers/net/phy/sfp.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 554acc8..01af080 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -185,6 +185,7 @@ struct sfp {
 	int (*write)(struct sfp *, bool, u8, void *, size_t);
 
 	struct gpio_desc *gpio[GPIO_MAX];
+	int gpio_irq[GPIO_MAX];
 
 	bool attached;
 	unsigned int state;
@@ -1786,7 +1787,7 @@ static int sfp_probe(struct platform_device *pdev)
 	struct i2c_adapter *i2c;
 	struct sfp *sfp;
 	bool poll = false;
-	int irq, err, i;
+	int err, i;
 
 	sfp = sfp_alloc(&pdev->dev);
 	if (IS_ERR(sfp))
@@ -1885,19 +1886,22 @@ static int sfp_probe(struct platform_device *pdev)
 		if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i])
 			continue;
 
-		irq = gpiod_to_irq(sfp->gpio[i]);
-		if (!irq) {
+		sfp->gpio_irq[i] = gpiod_to_irq(sfp->gpio[i]);
+		if (!sfp->gpio_irq[i]) {
 			poll = true;
 			continue;
 		}
 
-		err = devm_request_threaded_irq(sfp->dev, irq, NULL, sfp_irq,
+		err = devm_request_threaded_irq(sfp->dev, sfp->gpio_irq[i],
+						NULL, sfp_irq,
 						IRQF_ONESHOT |
 						IRQF_TRIGGER_RISING |
 						IRQF_TRIGGER_FALLING,
 						dev_name(sfp->dev), sfp);
-		if (err)
+		if (err) {
+			sfp->gpio_irq[i] = 0;
 			poll = true;
+		}
 	}
 
 	if (poll)
@@ -1928,9 +1932,26 @@ static int sfp_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void sfp_shutdown(struct platform_device *pdev)
+{
+	struct sfp *sfp = platform_get_drvdata(pdev);
+	int i;
+
+	for (i = 0; i < GPIO_MAX; i++) {
+		if (!sfp->gpio_irq[i])
+			continue;
+
+		devm_free_irq(sfp->dev, sfp->gpio_irq[i], sfp);
+	}
+
+	cancel_delayed_work_sync(&sfp->poll);
+	cancel_delayed_work_sync(&sfp->timeout);
+}
+
 static struct platform_driver sfp_driver = {
 	.probe = sfp_probe,
 	.remove = sfp_remove,
+	.shutdown = sfp_shutdown,
 	.driver = {
 		.name = "sfp",
 		.of_match_table = sfp_of_match,
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] net: sfp: add mutex to prevent concurrent state checks
  2019-06-07 16:42 [PATCH net-next 0/2] SFP polling fixes Robert Hancock
  2019-06-07 16:42 ` [PATCH net-next 1/2 v2] net: sfp: Stop SFP polling and interrupt handling during shutdown Robert Hancock
@ 2019-06-07 16:42 ` Robert Hancock
  2019-06-10  2:26 ` [PATCH net-next 0/2] SFP polling fixes David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Hancock @ 2019-06-07 16:42 UTC (permalink / raw)
  To: netdev; +Cc: linux, andrew, f.fainelli, hkallweit1, Robert Hancock

sfp_check_state can potentially be called by both a threaded IRQ handler
and delayed work. If it is concurrently called, it could result in
incorrect state management. Add a st_mutex to protect the state - this
lock gets taken outside of code that checks and handle state changes, and
the existing sm_mutex nests inside of it.

Suggested-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Robert Hancock <hancock@sedsystems.ca>
---
 drivers/net/phy/sfp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 01af080..edd2de5 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -188,10 +188,11 @@ struct sfp {
 	int gpio_irq[GPIO_MAX];
 
 	bool attached;
+	struct mutex st_mutex;			/* Protects state */
 	unsigned int state;
 	struct delayed_work poll;
 	struct delayed_work timeout;
-	struct mutex sm_mutex;
+	struct mutex sm_mutex;			/* Protects state machine */
 	unsigned char sm_mod_state;
 	unsigned char sm_dev_state;
 	unsigned short sm_state;
@@ -1705,6 +1706,7 @@ static void sfp_check_state(struct sfp *sfp)
 {
 	unsigned int state, i, changed;
 
+	mutex_lock(&sfp->st_mutex);
 	state = sfp_get_state(sfp);
 	changed = state ^ sfp->state;
 	changed &= SFP_F_PRESENT | SFP_F_LOS | SFP_F_TX_FAULT;
@@ -1730,6 +1732,7 @@ static void sfp_check_state(struct sfp *sfp)
 		sfp_sm_event(sfp, state & SFP_F_LOS ?
 				SFP_E_LOS_HIGH : SFP_E_LOS_LOW);
 	rtnl_unlock();
+	mutex_unlock(&sfp->st_mutex);
 }
 
 static irqreturn_t sfp_irq(int irq, void *data)
@@ -1760,6 +1763,7 @@ static struct sfp *sfp_alloc(struct device *dev)
 	sfp->dev = dev;
 
 	mutex_init(&sfp->sm_mutex);
+	mutex_init(&sfp->st_mutex);
 	INIT_DELAYED_WORK(&sfp->poll, sfp_poll);
 	INIT_DELAYED_WORK(&sfp->timeout, sfp_timeout);
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] SFP polling fixes
  2019-06-07 16:42 [PATCH net-next 0/2] SFP polling fixes Robert Hancock
  2019-06-07 16:42 ` [PATCH net-next 1/2 v2] net: sfp: Stop SFP polling and interrupt handling during shutdown Robert Hancock
  2019-06-07 16:42 ` [PATCH net-next 2/2] net: sfp: add mutex to prevent concurrent state checks Robert Hancock
@ 2019-06-10  2:26 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-06-10  2:26 UTC (permalink / raw)
  To: hancock; +Cc: netdev, linux, andrew, f.fainelli, hkallweit1

From: Robert Hancock <hancock@sedsystems.ca>
Date: Fri,  7 Jun 2019 10:42:34 -0600

> This has an updated version of an earlier patch to ensure that SFP
> operations are stopped during shutdown, and another patch suggested by
> Russell King to address a potential concurrency issue with SFP state
> checks.

Series applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-06-10  2:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07 16:42 [PATCH net-next 0/2] SFP polling fixes Robert Hancock
2019-06-07 16:42 ` [PATCH net-next 1/2 v2] net: sfp: Stop SFP polling and interrupt handling during shutdown Robert Hancock
2019-06-07 16:42 ` [PATCH net-next 2/2] net: sfp: add mutex to prevent concurrent state checks Robert Hancock
2019-06-10  2:26 ` [PATCH net-next 0/2] SFP polling fixes David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).