Skip to contentSkip to conversation

net: annotate data-races around cleanup_net_task

PATCH Applied Eric Dumazet 3 participants 3 messages Jun 4, 2025 – Jun 5, 2025

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

PATCH 1/1 net: annotate data-races around cleanup_net_task

from_cleanup_net() reads cleanup_net_task locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations to avoid a potential KCSAN warning, even if the race is harmless.

Fixes 0734d7c3d93c ("net: expedite synchronize_net() for cleanup_net()")
---
 net/core/dev.c           | 2 +-
 net/core/net_namespace.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
net/core/dev.c +1 -1
index a388f459a3666e3d186fb38d1eebd7cd33eb6979..be97c440ecd5f993344ae08d76c0b5216c4d296a 100644
@@ -10499,7 +10499,7 @@ static void dev_index_release(struct net *net, int ifindex)
 static bool from_cleanup_net(void)
 {
 #ifdef CONFIG_NET_NS
-	return current == cleanup_net_task;
+	return current == READ_ONCE(cleanup_net_task);
 #else
 	return false;
 #endif
net/core/net_namespace.c +2 -2
index 42ee7fce3d95b5a2756d6a3780edba070f01ddb6..ae54f26709ca242567e5d62d7b5dcc7f6303da57 100644
@@ -654,7 +654,7 @@ static void cleanup_net(struct work_struct *work)
 	struct net *net, *tmp, *last;
 	LIST_HEAD(net_exit_list);
 
-	cleanup_net_task = current;
+	WRITE_ONCE(cleanup_net_task, current);
 
 	/* Atomically snapshot the list of namespaces to cleanup */
 	net_kill_list = llist_del_all(&cleanup_list);
@@ -704,7 +704,7 @@ static void cleanup_net(struct work_struct *work)
 		put_user_ns(net->user_ns);
 		net_passive_dec(net);
 	}
-	cleanup_net_task = NULL;
+	WRITE_ONCE(cleanup_net_task, NULL);
 }
 
 /**
Signature · 1 line
2.50.0.rc0.604.gd4ff7b7c86-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Dumazet

from_cleanup_net() reads cleanup_net_task locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations to avoid a potential KCSAN warning, even if the race is harmless.

Fixes 0734d7c3d93c ("net: expedite synchronize_net() for cleanup_net()")

Thanks,
Jason

#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 4 Jun 2025 09:39:28 +0000 you wrote:

from_cleanup_net() reads cleanup_net_task locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations to avoid a potential KCSAN warning, even if the race is harmless.

Fixes 0734d7c3d93c ("net: expedite synchronize_net() for cleanup_net()")

[...]

Here is the summary with links:
- [net] net: annotate data-races around cleanup_net_task

    https://git.kernel.org/netdev/net/c/535caaca921c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html