diff mbox series

[v2,net-next] checkpatch: Discourage a new use of rtnl_lock() variants.

Message ID 20250214045414.56291-1-kuniyu@amazon.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [v2,net-next] checkpatch: Discourage a new use of rtnl_lock() variants. | 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/ynl success Generated files up to date; no warnings/errors; no diff in generated;
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: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
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: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-14--18-00 (tests: 889)

Commit Message

Kuniyuki Iwashima Feb. 14, 2025, 4:54 a.m. UTC
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>
Reviewed-by: Simon Horman <horms@kernel.org>
---
v2:
  * Remove unnecessary "^\+.*"
  * Match "rtnl_lock	 ()"

v1: https://lore.kernel.org/netdev/20250211070447.25001-1-kuniyu@amazon.com/
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Mateusz Polchlopek Feb. 14, 2025, 9:24 a.m. UTC | #1
On 2/14/2025 5:54 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>
> Reviewed-by: Simon Horman <horms@kernel.org>
> ---
> v2:
>    * Remove unnecessary "^\+.*"
>    * Match "rtnl_lock	 ()"
> 
> v1: https://lore.kernel.org/netdev/20250211070447.25001-1-kuniyu@amazon.com/
> ---
>   scripts/checkpatch.pl | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7b28ad331742..eca4f082ac3f 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)?\s*\(\)/) {
> +			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",

Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com>
Joe Perches Feb. 14, 2025, 2 p.m. UTC | #2
On Fri, 2025-02-14 at 10:24 +0100, Mateusz Polchlopek wrote:
> 
> On 2/14/2025 5:54 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>
> > Reviewed-by: Simon Horman <horms@kernel.org>
> > ---
> > v2:
> >    * Remove unnecessary "^\+.*"
> >    * Match "rtnl_lock	 ()"
> > 
> > v1: https://lore.kernel.org/netdev/20250211070447.25001-1-kuniyu@amazon.com/
> > ---
> >   scripts/checkpatch.pl | 6 ++++++
> >   1 file changed, 6 insertions(+)
> > 
> > diff --git 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)?\s*\(\)/) {
> > +			WARN("rtnl_lock()",
> > +			     "A new use of rtnl_lock() variants is discouraged, try to use rtnl_net_lock(net) variants\n" . $herecurr);

UPPER_CASE ALPHANUMERIC only for the key value please
and there could be whitespace between the parentheses

Perhaps:
		if ($line =~ /\brtnl_((?:try)?lock(?:_interruptible|_killable)?)\s*\(\s*\)/) {
			WARN("RTNL_LOCK",
			     "New use of rtnl_$1, prefer rtnl_net_$1(net)\n" . $herecurr);
		}

though there doesn't seem to be any uses of interruptible variants
in the tree I looked at.
Eric Dumazet Feb. 14, 2025, 2:15 p.m. UTC | #3
On Fri, Feb 14, 2025 at 5:54 AM Kuniyuki Iwashima <kuniyu@amazon.com> 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();

I do wonder if this is not premature.

After all, we have nothing in Documentation/ yet about this.
Kuniyuki Iwashima Feb. 15, 2025, 9:35 a.m. UTC | #4
From: Eric Dumazet <edumazet@google.com>
Date: Fri, 14 Feb 2025 15:15:48 +0100
> On Fri, Feb 14, 2025 at 5:54 AM Kuniyuki Iwashima <kuniyu@amazon.com> 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();
> 
> I do wonder if this is not premature.
> 
> After all, we have nothing in Documentation/ yet about this.

Fair point.  I'll defer this patch at least until rtnetlink
handlers are fully converted and the left thing to do is almost
replacing existing RTNL, then I'll repost with a small doc.
diff mbox series

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b28ad331742..eca4f082ac3f 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)?\s*\(\)/) {
+			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",