diff mbox series

[net-next] sh_eth: remove open coded netif_running()

Message ID 20230321065826.2044-1-wsa+renesas@sang-engineering.com (mailing list archive)
State Accepted
Commit ce1fdb065695f49ef6f126d35c1abbfe645d62d5
Delegated to: Netdev Maintainers
Headers show
Series [net-next] sh_eth: remove open coded netif_running() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 56 this patch: 56
netdev/cc_maintainers warning 1 maintainers not CCed: andrew@lunn.ch
netdev/build_clang success Errors and warnings before: 278 this patch: 278
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 56 this patch: 56
netdev/checkpatch warning WARNING: Reported-by: should be immediately followed by Link: with a URL to the report
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Wolfram Sang March 21, 2023, 6:58 a.m. UTC
It had a purpose back in the days, but today we have a handy helper.

Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

Based on 6.3-rc3 and tested on a Renesas Lager board (R-Car H2).

 drivers/net/ethernet/renesas/sh_eth.c | 6 +-----
 drivers/net/ethernet/renesas/sh_eth.h | 1 -
 2 files changed, 1 insertion(+), 6 deletions(-)

Comments

Leon Romanovsky March 21, 2023, 8:22 a.m. UTC | #1
On Tue, Mar 21, 2023 at 07:58:26AM +0100, Wolfram Sang wrote:
> It had a purpose back in the days, but today we have a handy helper.
> 
> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> 
> Based on 6.3-rc3 and tested on a Renesas Lager board (R-Car H2).
> 
>  drivers/net/ethernet/renesas/sh_eth.c | 6 +-----
>  drivers/net/ethernet/renesas/sh_eth.h | 1 -
>  2 files changed, 1 insertion(+), 6 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Geert Uytterhoeven March 21, 2023, 2:33 p.m. UTC | #2
On Tue, Mar 21, 2023 at 7:58 AM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> It had a purpose back in the days, but today we have a handy helper.
>
> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

No regressions seen on R-Car M2-W, RZ/A1H, and RZ/A2M.
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
Florian Fainelli March 21, 2023, 4:58 p.m. UTC | #3
On 3/20/23 23:58, Wolfram Sang wrote:
> It had a purpose back in the days, but today we have a handy helper.
> 
> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
patchwork-bot+netdevbpf@kernel.org March 22, 2023, 12:30 p.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Tue, 21 Mar 2023 07:58:26 +0100 you wrote:
> It had a purpose back in the days, but today we have a handy helper.
> 
> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> 
> Based on 6.3-rc3 and tested on a Renesas Lager board (R-Car H2).
> 
> [...]

Here is the summary with links:
  - [net-next] sh_eth: remove open coded netif_running()
    https://git.kernel.org/netdev/net-next/c/ce1fdb065695

You are awesome, thank you!
Sergey Shtylyov March 22, 2023, 8:54 p.m. UTC | #5
On 3/21/23 9:58 AM, Wolfram Sang wrote:

> It had a purpose back in the days, but today we have a handy helper.

   Well, the is_opened flag doesn't get set/cleared at the same time as
__LINK_STATE_START. I'm not sure they are interchangeable...
 
> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> 
> Based on 6.3-rc3 and tested on a Renesas Lager board (R-Car H2).
> 
>  drivers/net/ethernet/renesas/sh_eth.c | 6 +-----
>  drivers/net/ethernet/renesas/sh_eth.h | 1 -
>  2 files changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
> index d8ec729825be..2d9787231099 100644
> --- a/drivers/net/ethernet/renesas/sh_eth.c
> +++ b/drivers/net/ethernet/renesas/sh_eth.c
> @@ -2441,8 +2441,6 @@ static int sh_eth_open(struct net_device *ndev)
>  
>  	netif_start_queue(ndev);
>  
> -	mdp->is_opened = 1;
> -

   __LINK_STATE_START gets set before the ndo_open() method call, so
before the RPM call that enbales the clocks...

>  	return ret;
>  
>  out_free_irq:
> @@ -2565,7 +2563,7 @@ static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
>  	if (mdp->cd->no_tx_cntrs)
>  		return &ndev->stats;
>  
> -	if (!mdp->is_opened)
> +	if (!netif_running(ndev))
>  		return &ndev->stats;

   I guess mdp->is_opened is checked here to avoid reading the counter
regs when RPM hasn't been called yet to enable the clocks...

[...]

MBR, Sergey
Sergey Shtylyov March 22, 2023, 8:57 p.m. UTC | #6
On 3/22/23 3:30 PM, patchwork-bot+netdevbpf@kernel.org wrote:
[...]

> This patch was applied to netdev/net-next.git (main)
> by Paolo Abeni <pabeni@redhat.com>:
> 
> On Tue, 21 Mar 2023 07:58:26 +0100 you wrote:
>> It had a purpose back in the days, but today we have a handy helper.
>>
>> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
>> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
>> ---
>>
>> Based on 6.3-rc3 and tested on a Renesas Lager board (R-Car H2).
>>
>> [...]
> 
> Here is the summary with links:
>   - [net-next] sh_eth: remove open coded netif_running()
>     https://git.kernel.org/netdev/net-next/c/ce1fdb065695
> 
> You are awesome, thank you!

   I don't think this needed to be merged circumventing my review.
The patch was posted yesterday...

MBR, Sergey
Geert Uytterhoeven March 23, 2023, 8:32 a.m. UTC | #7
Hi Sergey,

On Wed, Mar 22, 2023 at 9:54 PM Sergey Shtylyov <s.shtylyov@omp.ru> wrote:
> On 3/21/23 9:58 AM, Wolfram Sang wrote:
> > It had a purpose back in the days, but today we have a handy helper.
>
>    Well, the is_opened flag doesn't get set/cleared at the same time as
> __LINK_STATE_START. I'm not sure they are interchangeable...
>
> > Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

> > --- a/drivers/net/ethernet/renesas/sh_eth.c
> > +++ b/drivers/net/ethernet/renesas/sh_eth.c
> > @@ -2441,8 +2441,6 @@ static int sh_eth_open(struct net_device *ndev)
> >
> >       netif_start_queue(ndev);
> >
> > -     mdp->is_opened = 1;
> > -
>
>    __LINK_STATE_START gets set before the ndo_open() method call, so
> before the RPM call that enbales the clocks...
>
> >       return ret;
> >
> >  out_free_irq:
> > @@ -2565,7 +2563,7 @@ static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
> >       if (mdp->cd->no_tx_cntrs)
> >               return &ndev->stats;
> >
> > -     if (!mdp->is_opened)
> > +     if (!netif_running(ndev))
> >               return &ndev->stats;
>
>    I guess mdp->is_opened is checked here to avoid reading the counter
> regs when RPM hasn't been called yet to enable the clocks...

Exactly, cfr. commit 7fa2955ff70ce453 ("sh_eth: Fix sleeping function
called from invalid context").

So you mean sh_eth_get_stats() can now be called after setting
__LINK_STATE_START, but before RPM has enabled the clocks?
Is there some protection against parallel execution of ndo_open()
and get_stats()?

Gr{oetje,eeting}s,

                        Geert
Jakub Kicinski March 23, 2023, 4:40 p.m. UTC | #8
On Thu, 23 Mar 2023 09:32:27 +0100 Geert Uytterhoeven wrote:
> Is there some protection against parallel execution of ndo_open()
> and get_stats()?

Nope - one is under rtnl_lock, the other under just RCU, IIRC.
So this patch just makes the race worse, but it was already
racy before.
Sergey Shtylyov March 25, 2023, 8:27 p.m. UTC | #9
On 3/23/23 7:40 PM, Jakub Kicinski wrote:
[...]

>> Is there some protection against parallel execution of ndo_open()
>> and get_stats()?
> 
> Nope - one is under rtnl_lock, the other under just RCU, IIRC.
> So this patch just makes the race worse, but it was already
> racy before.

   How about reverting it then?

MBR, Sergey
Sergey Shtylyov March 25, 2023, 8:56 p.m. UTC | #10
Hello!

On 3/23/23 11:32 AM, Geert Uytterhoeven wrote:
[...]
>>> It had a purpose back in the days, but today we have a handy helper.
>>
>>    Well, the is_opened flag doesn't get set/cleared at the same time as
>> __LINK_STATE_START. I'm not sure they are interchangeable...
>>
>>> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
>>> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> 
>>> --- a/drivers/net/ethernet/renesas/sh_eth.c
>>> +++ b/drivers/net/ethernet/renesas/sh_eth.c
>>> @@ -2441,8 +2441,6 @@ static int sh_eth_open(struct net_device *ndev)
>>>
>>>       netif_start_queue(ndev);
>>>
>>> -     mdp->is_opened = 1;
>>> -
>>
>>    __LINK_STATE_START gets set before the ndo_open() method call, so
>> before the RPM call that enbales the clocks...
>>
>>>       return ret;
>>>
>>>  out_free_irq:
>>> @@ -2565,7 +2563,7 @@ static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
>>>       if (mdp->cd->no_tx_cntrs)
>>>               return &ndev->stats;
>>>
>>> -     if (!mdp->is_opened)
>>> +     if (!netif_running(ndev))
>>>               return &ndev->stats;
>>
>>    I guess mdp->is_opened is checked here to avoid reading the counter
>> regs when RPM hasn't been called yet to enable the clocks...
> 
> Exactly, cfr. commit 7fa2955ff70ce453 ("sh_eth: Fix sleeping function
> called from invalid context").

   Yeah, pm_runtime_get_sync() couldn't be called in this case as
netstat_show() invoked read_lock() that ensued calling preempt_disable()...

> So you mean sh_eth_get_stats() can now be called after setting
> __LINK_STATE_START, but before RPM has enabled the clocks?

   Yes, probably...

> Is there some protection against parallel execution of ndo_open()
> and get_stats()?

   Haven't seen it (yet?)...

> Gr{oetje,eeting}s,
> 
>                         Geert

MBR, Sergey
Wolfram Sang March 27, 2023, 8:14 a.m. UTC | #11
> > Nope - one is under rtnl_lock, the other under just RCU, IIRC.
> > So this patch just makes the race worse, but it was already
> > racy before.
> 
>    How about reverting it then?

Agreed. Will send a revert.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index d8ec729825be..2d9787231099 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -2441,8 +2441,6 @@  static int sh_eth_open(struct net_device *ndev)
 
 	netif_start_queue(ndev);
 
-	mdp->is_opened = 1;
-
 	return ret;
 
 out_free_irq:
@@ -2565,7 +2563,7 @@  static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
 	if (mdp->cd->no_tx_cntrs)
 		return &ndev->stats;
 
-	if (!mdp->is_opened)
+	if (!netif_running(ndev))
 		return &ndev->stats;
 
 	sh_eth_update_stat(ndev, &ndev->stats.tx_dropped, TROCR);
@@ -2614,8 +2612,6 @@  static int sh_eth_close(struct net_device *ndev)
 	/* Free all the skbuffs in the Rx queue and the DMA buffer. */
 	sh_eth_ring_free(ndev);
 
-	mdp->is_opened = 0;
-
 	pm_runtime_put(&mdp->pdev->dev);
 
 	return 0;
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index a5c07c6ff44a..f56dbc8a064a 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -560,7 +560,6 @@  struct sh_eth_private {
 
 	unsigned no_ether_link:1;
 	unsigned ether_link_active_low:1;
-	unsigned is_opened:1;
 	unsigned wol_enabled:1;
 };