diff mbox series

net: fec: ethtool: fix unbalanced IRQ wake disable

Message ID 20220223080918.3751233-1-s.hauer@pengutronix.de (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series net: fec: ethtool: fix unbalanced IRQ wake disable | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: B38611@freescale.com; 2 maintainers not CCed: B38611@freescale.com kuba@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Sascha Hauer Feb. 23, 2022, 8:09 a.m. UTC
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(+)

Comments

Joakim Zhang Feb. 23, 2022, 10:28 a.m. UTC | #1
Hi Sascha,

> -----Original Message-----
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Sent: 2022年2月23日 16:09
> 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
> 
> 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.

I have not found disable_irq_wake in fec_enet_set_wol.
https://elixir.bootlin.com/linux/v5.17-rc5/source/drivers/net/ethernet/freescale/fec_main.c#L2882

> 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.

FEC done as this way:
https://elixir.bootlin.com/linux/v5.17-rc5/source/drivers/net/ethernet/freescale/fec_main.c#L4075
https://elixir.bootlin.com/linux/v5.17-rc5/source/drivers/net/ethernet/freescale/fec_main.c#L4119

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

Ahh, what I misunderstand? All the description makes me confusion. Please use the latest kernel.

Best Regards,
Joakim Zhang
> 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
Sascha Hauer Feb. 23, 2022, 10:56 a.m. UTC | #2
On Wed, Feb 23, 2022 at 10:28:34AM +0000, Joakim Zhang wrote:
> 
> Hi Sascha,
> 
> > -----Original Message-----
> > From: Sascha Hauer <s.hauer@pengutronix.de>
> > Sent: 2022年2月23日 16:09
> > 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
> > 
> > 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.
> 
> I have not found disable_irq_wake in fec_enet_set_wol.
> https://elixir.bootlin.com/linux/v5.17-rc5/source/drivers/net/ethernet/freescale/fec_main.c#L2882
> 
> > 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.
> 
> FEC done as this way:
> https://elixir.bootlin.com/linux/v5.17-rc5/source/drivers/net/ethernet/freescale/fec_main.c#L4075
> https://elixir.bootlin.com/linux/v5.17-rc5/source/drivers/net/ethernet/freescale/fec_main.c#L4119
> 
> > This only affects userspace with older ethtool versions. Newer ones use
> > netlink and disabling before enabling will be refused before reaching the
> > driver.
> 
> Ahh, what I misunderstand? All the description makes me confusion. Please use the latest kernel.

This patch was forward ported from v5.16. I should have had a closer
look before posting, then I maybe would have realized that 0b6f65c707e5
("net: fec: fix system hang during suspend/resume") already fixes the
issue.

Sorry for the noise.

Sascha
Joakim Zhang Feb. 25, 2022, 3:07 a.m. UTC | #3
Hi Sascha,

> -----Original Message-----
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Sent: 2022年2月23日 18:56
> To: Joakim Zhang <qiangqing.zhang@nxp.com>
> Cc: netdev@vger.kernel.org; David S . Miller <davem@davemloft.net>;
> kernel@pengutronix.de; Ahmad Fatoum <a.fatoum@pengutronix.de>
> Subject: Re: [PATCH] net: fec: ethtool: fix unbalanced IRQ wake disable
> 
> On Wed, Feb 23, 2022 at 10:28:34AM +0000, Joakim Zhang wrote:
> >
> > Hi Sascha,
> >
> > > -----Original Message-----
> > > From: Sascha Hauer <s.hauer@pengutronix.de>
> > > Sent: 2022年2月23日 16:09
> > > 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
> > >
> > > 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.
> >
> > I have not found disable_irq_wake in fec_enet_set_wol.
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
> >
> ir.bootlin.com%2Flinux%2Fv5.17-rc5%2Fsource%2Fdrivers%2Fnet%2Fethern
> et
> > %2Ffreescale%2Ffec_main.c%23L2882&amp;data=04%7C01%7Cqiangqing.z
> hang%4
> >
> 0nxp.com%7C2d4ab9a7efa94043248a08d9f6bb1b04%7C686ea1d3bc2b4c6fa9
> 2cd99c
> >
> 5c301635%7C0%7C0%7C637812105743913684%7CUnknown%7CTWFpbGZsb3
> d8eyJWIjoi
> >
> MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C300
> 0&amp;
> >
> sdata=Po%2F0sml1SjBSXlx8BTELg29hE5qsLIW2xyALy7O87s0%3D&amp;reserv
> ed=0
> >
> > > 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.
> >
> > FEC done as this way:
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
> >
> ir.bootlin.com%2Flinux%2Fv5.17-rc5%2Fsource%2Fdrivers%2Fnet%2Fethern
> et
> > %2Ffreescale%2Ffec_main.c%23L4075&amp;data=04%7C01%7Cqiangqing.z
> hang%4
> >
> 0nxp.com%7C2d4ab9a7efa94043248a08d9f6bb1b04%7C686ea1d3bc2b4c6fa9
> 2cd99c
> >
> 5c301635%7C0%7C0%7C637812105743913684%7CUnknown%7CTWFpbGZsb3
> d8eyJWIjoi
> >
> MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C300
> 0&amp;
> >
> sdata=H9kdNlPJ1KPOyvS%2FLm%2Bj6NrPe5N1mD%2BrfgWoNhEUYgU%3D&
> amp;reserve
> > d=0
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
> >
> ir.bootlin.com%2Flinux%2Fv5.17-rc5%2Fsource%2Fdrivers%2Fnet%2Fethern
> et
> > %2Ffreescale%2Ffec_main.c%23L4119&amp;data=04%7C01%7Cqiangqing.z
> hang%4
> >
> 0nxp.com%7C2d4ab9a7efa94043248a08d9f6bb1b04%7C686ea1d3bc2b4c6fa9
> 2cd99c
> >
> 5c301635%7C0%7C0%7C637812105743913684%7CUnknown%7CTWFpbGZsb3
> d8eyJWIjoi
> >
> MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C300
> 0&amp;
> >
> sdata=MH30p5o2fjlp%2FLXzMSPP20I7RToQNr9kYrTGl%2FZSHbw%3D&amp;r
> eserved=
> > 0
> >
> > > This only affects userspace with older ethtool versions. Newer ones
> > > use netlink and disabling before enabling will be refused before
> > > reaching the driver.
> >
> > Ahh, what I misunderstand? All the description makes me confusion.
> Please use the latest kernel.
> 
> This patch was forward ported from v5.16. I should have had a closer look
> before posting, then I maybe would have realized that 0b6f65c707e5
> ("net: fec: fix system hang during suspend/resume") already fixes the issue.
> 
> Sorry for the noise.

Never mind!! 
diff mbox series

Patch

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: