All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: netdev@vger.kernel.org
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>,
	"David S . Miller" <davem@davemloft.net>,
	kernel@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>,
	Sascha Hauer <s.hauer@pengutronix.de>
Subject: [PATCH] net: fec: ethtool: fix unbalanced IRQ wake disable
Date: Wed, 23 Feb 2022 09:09:18 +0100	[thread overview]
Message-ID: <20220223080918.3751233-1-s.hauer@pengutronix.de> (raw)

From: Ahmad Fatoum <a.fatoum@pengutronix.de>

Userspace can trigger a kernel warning by using the ethtool ioctls to
disable WoL, when it was not enabled before:

  $ ethtool -s eth0 wol d ; ethtool -s eth0 wol d
  Unbalanced IRQ 54 wake disable
  WARNING: CPU: 2 PID: 17532 at kernel/irq/manage.c:900 irq_set_irq_wake+0x108/0x148

This is because fec_enet_set_wol happily calls disable_irq_wake,
even if the wake IRQ is already disabled.

Looking at other drivers, like lpc_eth, suggests the way to go is to
do wake IRQ enabling/disabling in the suspend/resume callbacks.
Doing so avoids the warning at no loss of functionality.

This only affects userspace with older ethtool versions. Newer ones
use netlink and disabling before enabling will be refused before
reaching the driver.

Fixes: de40ed31b3c5 ("net: fec: add Wake-on-LAN support")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/ethernet/freescale/fec_main.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 796133de527e4..44a0c89d76dd6 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -4055,6 +4055,9 @@ static int __maybe_unused fec_suspend(struct device *dev)
 	struct net_device *ndev = dev_get_drvdata(dev);
 	struct fec_enet_private *fep = netdev_priv(ndev);
 
+	if (device_may_wakeup(&ndev->dev) && fep->wake_irq > 0)
+		enable_irq_wake(fep->wake_irq);
+
 	rtnl_lock();
 	if (netif_running(ndev)) {
 		if (fep->wol_flag & FEC_WOL_FLAG_ENABLE)
@@ -4137,6 +4140,9 @@ static int __maybe_unused fec_resume(struct device *dev)
 	}
 	rtnl_unlock();
 
+	if (device_may_wakeup(&ndev->dev) && fep->wake_irq > 0)
+		disable_irq_wake(fep->wake_irq);
+
 	return 0;
 
 failed_clk:
-- 
2.30.2


             reply	other threads:[~2022-02-23  8:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23  8:09 Sascha Hauer [this message]
2022-02-23 10:28 ` [PATCH] net: fec: ethtool: fix unbalanced IRQ wake disable Joakim Zhang
2022-02-23 10:56   ` Sascha Hauer
2022-02-25  3:07     ` Joakim Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220223080918.3751233-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=qiangqing.zhang@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.