[PATCH net 2/2] net: sh_eth: Fix missing rtnl lock in suspend path

Kory Maincent posted 2 patches 11 months ago
There is a newer version of this series
[PATCH net 2/2] net: sh_eth: Fix missing rtnl lock in suspend path
Posted by Kory Maincent 11 months ago
Fix the suspend path by ensuring the rtnl lock is held where required.
Calls to sh_eth_close, sh_eth_open and wol operations must be performed
under the rtnl lock to prevent conflicts with ongoing ndo operations.

Fixes: b71af04676e9 ("sh_eth: add more PM methods")
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
 drivers/net/ethernet/renesas/sh_eth.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 8887b8921009..5fc8027c92c7 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -3494,10 +3494,12 @@ static int sh_eth_suspend(struct device *dev)
 
 	netif_device_detach(ndev);
 
+	rtnl_lock();
 	if (mdp->wol_enabled)
 		ret = sh_eth_wol_setup(ndev);
 	else
 		ret = sh_eth_close(ndev);
+	rtnl_unlock();
 
 	return ret;
 }
@@ -3511,10 +3513,12 @@ static int sh_eth_resume(struct device *dev)
 	if (!netif_running(ndev))
 		return 0;
 
+	rtnl_lock();
 	if (mdp->wol_enabled)
 		ret = sh_eth_wol_restore(ndev);
 	else
 		ret = sh_eth_open(ndev);
+	rtnl_unlock();
 
 	if (ret < 0)
 		return ret;

-- 
2.34.1
Re: [PATCH net 2/2] net: sh_eth: Fix missing rtnl lock in suspend path
Posted by Sergey Shtylyov 11 months ago
On 1/22/25 7:19 PM, Kory Maincent wrote:

> Fix the suspend path by ensuring the rtnl lock is held where required.

   Maybe suspend/resume path (the same w/the subject)?

> Calls to sh_eth_close, sh_eth_open and wol operations must be performed
> under the rtnl lock to prevent conflicts with ongoing ndo operations.
> 
> Fixes: b71af04676e9 ("sh_eth: add more PM methods")
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>

    FWIW:

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

MBR, Sergey
Re: [PATCH net 2/2] net: sh_eth: Fix missing rtnl lock in suspend path
Posted by Niklas Söderlund 11 months ago
Hi Kory,

Thanks for your work.

On 2025-01-22 17:19:29 +0100, Kory Maincent wrote:
> Fix the suspend path by ensuring the rtnl lock is held where required.
> Calls to sh_eth_close, sh_eth_open and wol operations must be performed
> under the rtnl lock to prevent conflicts with ongoing ndo operations.
> 
> Fixes: b71af04676e9 ("sh_eth: add more PM methods")
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>

Tested on R-Car M2,

Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  drivers/net/ethernet/renesas/sh_eth.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
> index 8887b8921009..5fc8027c92c7 100644
> --- a/drivers/net/ethernet/renesas/sh_eth.c
> +++ b/drivers/net/ethernet/renesas/sh_eth.c
> @@ -3494,10 +3494,12 @@ static int sh_eth_suspend(struct device *dev)
>  
>  	netif_device_detach(ndev);
>  
> +	rtnl_lock();
>  	if (mdp->wol_enabled)
>  		ret = sh_eth_wol_setup(ndev);
>  	else
>  		ret = sh_eth_close(ndev);
> +	rtnl_unlock();
>  
>  	return ret;
>  }
> @@ -3511,10 +3513,12 @@ static int sh_eth_resume(struct device *dev)
>  	if (!netif_running(ndev))
>  		return 0;
>  
> +	rtnl_lock();
>  	if (mdp->wol_enabled)
>  		ret = sh_eth_wol_restore(ndev);
>  	else
>  		ret = sh_eth_open(ndev);
> +	rtnl_unlock();
>  
>  	if (ret < 0)
>  		return ret;
> 
> -- 
> 2.34.1
> 

-- 
Kind Regards,
Niklas Söderlund