netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants.
@ 2025-02-11  7:04 Kuniyuki Iwashima
  2025-02-12 18:23 ` Simon Horman
  2025-02-13 11:03 ` Paolo Abeni
  0 siblings, 2 replies; 5+ messages in thread
From: Kuniyuki Iwashima @ 2025-02-11  7:04 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman
  Cc: Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn,
	Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

rtnl_lock() is a "Big Kernel Lock" in the networking slow path
and still serialises most of RTM_(NEW|DEL|SET)* rtnetlink requests.

Commit 76aed95319da ("rtnetlink: Add per-netns RTNL.") started a
very large, in-progress, effort to make the RTNL lock scope per
network namespace.

However, there are still some patches that newly use rtnl_lock(),
which is now discouraged, and we need to revisit it later.

Let's warn about the case by checkpatch.

The target functions are as follows:

  * rtnl_lock()
  * rtnl_trylock()
  * rtnl_lock_interruptible()
  * rtnl_lock_killable()

and the warning will be like:

  WARNING: A new use of rtnl_lock() variants is discouraged, try to use rtnl_net_lock(net) variants
  #18: FILE: net/core/rtnetlink.c:79:
  +	rtnl_lock();

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
It would be nice if this patch goes through net-next.git to catch
new rtnl_lock() users by netdev CI.
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b28ad331742..09d5420436cc 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6995,6 +6995,12 @@ sub process {
 #			}
 #		}
 
+# A new use of rtnl_lock() is discouraged as it's being converted to rtnl_net_lock(net).
+		if ($line =~ /^\+.*\brtnl_(try)?lock(_interruptible|_killable)?\(\)/) {
+			WARN("rtnl_lock()",
+			     "A new use of rtnl_lock() variants is discouraged, try to use rtnl_net_lock(net) variants\n" . $herecurr);
+		}
+
 # strcpy uses that should likely be strscpy
 		if ($line =~ /\bstrcpy\s*\(/) {
 			WARN("STRCPY",
-- 
2.39.5 (Apple Git-154)


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

* Re: [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants.
  2025-02-11  7:04 [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants Kuniyuki Iwashima
@ 2025-02-12 18:23 ` Simon Horman
  2025-02-13 11:03 ` Paolo Abeni
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Horman @ 2025-02-12 18:23 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn,
	Kuniyuki Iwashima, netdev

On Tue, Feb 11, 2025 at 04:04:47PM +0900, Kuniyuki Iwashima wrote:
> rtnl_lock() is a "Big Kernel Lock" in the networking slow path
> and still serialises most of RTM_(NEW|DEL|SET)* rtnetlink requests.
> 
> Commit 76aed95319da ("rtnetlink: Add per-netns RTNL.") started a
> very large, in-progress, effort to make the RTNL lock scope per
> network namespace.
> 
> However, there are still some patches that newly use rtnl_lock(),
> which is now discouraged, and we need to revisit it later.
> 
> Let's warn about the case by checkpatch.
> 
> The target functions are as follows:
> 
>   * rtnl_lock()
>   * rtnl_trylock()
>   * rtnl_lock_interruptible()
>   * rtnl_lock_killable()
> 
> and the warning will be like:
> 
>   WARNING: A new use of rtnl_lock() variants is discouraged, try to use rtnl_net_lock(net) variants
>   #18: FILE: net/core/rtnetlink.c:79:
>   +	rtnl_lock();
> 
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> It would be nice if this patch goes through net-next.git to catch
> new rtnl_lock() users by netdev CI.

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants.
  2025-02-11  7:04 [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants Kuniyuki Iwashima
  2025-02-12 18:23 ` Simon Horman
@ 2025-02-13 11:03 ` Paolo Abeni
  2025-02-13 12:10   ` Kuniyuki Iwashima
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2025-02-13 11:03 UTC (permalink / raw)
  To: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Simon Horman
  Cc: Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn,
	Kuniyuki Iwashima, netdev



On 2/11/25 8:04 AM, Kuniyuki Iwashima wrote:
> rtnl_lock() is a "Big Kernel Lock" in the networking slow path
> and still serialises most of RTM_(NEW|DEL|SET)* rtnetlink requests.
> 
> Commit 76aed95319da ("rtnetlink: Add per-netns RTNL.") started a
> very large, in-progress, effort to make the RTNL lock scope per
> network namespace.
> 
> However, there are still some patches that newly use rtnl_lock(),
> which is now discouraged, and we need to revisit it later.
> 
> Let's warn about the case by checkpatch.
> 
> The target functions are as follows:
> 
>   * rtnl_lock()
>   * rtnl_trylock()
>   * rtnl_lock_interruptible()
>   * rtnl_lock_killable()
> 
> and the warning will be like:
> 
>   WARNING: A new use of rtnl_lock() variants is discouraged, try to use rtnl_net_lock(net) variants
>   #18: FILE: net/core/rtnetlink.c:79:
>   +	rtnl_lock();
> 
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> It would be nice if this patch goes through net-next.git to catch
> new rtnl_lock() users by netdev CI.
> ---
>  scripts/checkpatch.pl | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7b28ad331742..09d5420436cc 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6995,6 +6995,12 @@ sub process {
>  #			}
>  #		}
>  
> +# A new use of rtnl_lock() is discouraged as it's being converted to rtnl_net_lock(net).
> +		if ($line =~ /^\+.*\brtnl_(try)?lock(_interruptible|_killable)?\(\)/) {

I think you need to add '\s*' just before  '\(' to avoid the test being
fooled by some bad formatting.
Also I'm unsure if the '^\+.*' header is strictly required - it should
but some/most existing tests don't use it, do you know why?

Thanks,

Paolo


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

* Re: [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants.
  2025-02-13 11:03 ` Paolo Abeni
@ 2025-02-13 12:10   ` Kuniyuki Iwashima
  2025-02-13 12:18     ` Kuniyuki Iwashima
  0 siblings, 1 reply; 5+ messages in thread
From: Kuniyuki Iwashima @ 2025-02-13 12:10 UTC (permalink / raw)
  To: pabeni
  Cc: apw, davem, dwaipayanray1, edumazet, horms, joe, kuba, kuni1840,
	kuniyu, lukas.bulwahn, netdev

From: Paolo Abeni <pabeni@redhat.com>
Date: Thu, 13 Feb 2025 12:03:51 +0100
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 7b28ad331742..09d5420436cc 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -6995,6 +6995,12 @@ sub process {
> >  #			}
> >  #		}
> >  
> > +# A new use of rtnl_lock() is discouraged as it's being converted to rtnl_net_lock(net).
> > +		if ($line =~ /^\+.*\brtnl_(try)?lock(_interruptible|_killable)?\(\)/) {
> 
> I think you need to add '\s*' just before  '\(' to avoid the test being
> fooled by some bad formatting.

Will add that.  BTW, it's also caught by another warning.

  WARNING: space prohibited between function name and open parenthesis '('
  #18: FILE: net/core/rtnetlink.c:79:
  +	rtnl_lock ();


> Also I'm unsure if the '^\+.*' header is strictly required - it should
> but some/most existing tests don't use it, do you know why?

I didn't notice but exactly, the following matches only + line.

  if ($line =~ /\brtnl_(try)?lock(_interruptible|_killable)?\s*\(\)/) {

Looks like the '-' diff is filtered, matching '-' doesn't make sense.

This function looks suspicious ? (maybe wrong, I'm not familiar with perl)

---8<---
sub raw_line {
        my ($linenr, $cnt) = @_;

        my $offset = $linenr - 1;
        $cnt++;

        my $line;
        while ($cnt) {
                $line = $rawlines[$offset++];
                next if (defined($line) && $line =~ /^-/);
                $cnt--;
        }

        return $line;
}
---8<---

Thanks!

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

* Re: [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants.
  2025-02-13 12:10   ` Kuniyuki Iwashima
@ 2025-02-13 12:18     ` Kuniyuki Iwashima
  0 siblings, 0 replies; 5+ messages in thread
From: Kuniyuki Iwashima @ 2025-02-13 12:18 UTC (permalink / raw)
  To: kuniyu
  Cc: apw, davem, dwaipayanray1, edumazet, horms, joe, kuba, kuni1840,
	lukas.bulwahn, netdev, pabeni

From: Kuniyuki Iwashima <kuniyu@amazon.com>
Date: Thu, 13 Feb 2025 21:10:28 +0900
> > Also I'm unsure if the '^\+.*' header is strictly required - it should
> > but some/most existing tests don't use it, do you know why?
> 
> I didn't notice but exactly, the following matches only + line.
> 
>   if ($line =~ /\brtnl_(try)?lock(_interruptible|_killable)?\s*\(\)/) {
> 
> Looks like the '-' diff is filtered, matching '-' doesn't make sense.
> 
> This function looks suspicious ? (maybe wrong, I'm not familiar with perl)

I was wrong, this part did the filtering :)

---8<---
#ignore lines not being added
                next if ($line =~ /^[^\+]/);
---8<---

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

end of thread, other threads:[~2025-02-13 12:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-11  7:04 [PATCH v1 net-next] checkpatch: Discourage a new use of rtnl_lock() variants Kuniyuki Iwashima
2025-02-12 18:23 ` Simon Horman
2025-02-13 11:03 ` Paolo Abeni
2025-02-13 12:10   ` Kuniyuki Iwashima
2025-02-13 12:18     ` Kuniyuki Iwashima

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