Skip to contentSkip to conversation

checkpatch: Discourage a new use of rtnl_lock() variants.

PATCH In review Kuniyuki Iwashima 4 participants 5 messages Feb 14, 2025 – Feb 15, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checkpatch: Discourage a new use of rtnl_lock() variants.

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();

---
v2:
* Remove unnecessary "^\+.*"
* Match "rtnl_lock ()"

v1: https://lore.kernel.org/netdev/[email protected]/

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
index 7b28ad331742..eca4f082ac3f 100755
@@ -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",
Signature · 1 line
2.39.5 (Apple Git-154)
Reviewed-by on v2 1/1
#1 lore raw
Quoted 44 lines · Kuniyuki Iwashima

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();

---
v2:
* Remove unnecessary "^\+.*"
* Match "rtnl_lock ()"

v1: https://lore.kernel.org/netdev/[email protected]/

---
  scripts/checkpatch.pl | 6 ++++++
  1 file changed, 6 insertions(+)
scripts/checkpatch.pl +0 -0
index 7b28ad331742..eca4f082ac3f 100755
@@ -6995,6 +6995,12 @@ sub process {
  #			}
  #		}

scripts/checkpatch.pl sub process { · line 7006

Quoted 10 lines
scripts/checkpatch.pl +6 -0
 
+# 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",
maintainer
#2 lore raw
Quoted 34 lines · Mateusz Polchlopek
Quoted 32 lines · Kuniyuki Iwashima

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();

---
v2:
* Remove unnecessary "^\+.*"
* Match "rtnl_lock ()"

Quoted 6 lines

scripts/checkpatch.pl

Quoted 6 lines

v1: https://lore.kernel.org/netdev/[email protected]/

---
  scripts/checkpatch.pl | 6 ++++++
  1 file changed, 6 insertions(+)
scripts/checkpatch.pl +0 -0

[]

Quoted 8 lines

scripts/checkpatch.pl sub process { · line 7001

Quoted 8 lines
scripts/checkpatch.pl +4 -0
@@ -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.

#3 lore raw
In reply to Kuniyuki Iwashima
Quoted 20 lines · Kuniyuki Iwashima

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

Quoted 5 lines

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.

#4 lore raw

From: Eric Dumazet <[email protected]>
Date: Fri, 14 Feb 2025 15:15:48 +0100

Quoted 23 lines · Kuniyuki Iwashima
Quoted 22 lines

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:

Quoted 7 lines
Quoted 3 lines

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.