diff mbox series

[net] pktgen: use cpus_read_lock() in pg_net_init()

Message ID 20240821175339.1191779-1-edumazet@google.com (mailing list archive)
State Accepted
Commit 979b581e4c69257acab1af415ddad6b2d78a2fa5
Delegated to: Netdev Maintainers
Headers show
Series [net] pktgen: use cpus_read_lock() in pg_net_init() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: liangchen.linux@gmail.com
netdev/build_clang success Errors and warnings before: 16 this patch: 16
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 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-2024-08-22--03-00 (tests: 711)

Commit Message

Eric Dumazet Aug. 21, 2024, 5:53 p.m. UTC
I have seen the WARN_ON(smp_processor_id() != cpu) firing
in pktgen_thread_worker() during tests.

We must use cpus_read_lock()/cpus_read_unlock()
around the for_each_online_cpu(cpu) loop.

While we are at it use WARN_ON_ONCE() to avoid a possible syslog flood.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/pktgen.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

patchwork-bot+netdevbpf@kernel.org Aug. 23, 2024, 1:20 a.m. UTC | #1
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 21 Aug 2024 17:53:39 +0000 you wrote:
> I have seen the WARN_ON(smp_processor_id() != cpu) firing
> in pktgen_thread_worker() during tests.
> 
> We must use cpus_read_lock()/cpus_read_unlock()
> around the for_each_online_cpu(cpu) loop.
> 
> While we are at it use WARN_ON_ONCE() to avoid a possible syslog flood.
> 
> [...]

Here is the summary with links:
  - [net] pktgen: use cpus_read_lock() in pg_net_init()
    https://git.kernel.org/netdev/net/c/979b581e4c69

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index ea55a758a475ab0ee22d9ac91f0ac9f0a6975e1f..197a50ef8e2e1bbe9f3906dfb80e80d913534b81 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3654,7 +3654,7 @@  static int pktgen_thread_worker(void *arg)
 	struct pktgen_dev *pkt_dev = NULL;
 	int cpu = t->cpu;
 
-	WARN_ON(smp_processor_id() != cpu);
+	WARN_ON_ONCE(smp_processor_id() != cpu);
 
 	init_waitqueue_head(&t->queue);
 	complete(&t->start_done);
@@ -3989,6 +3989,7 @@  static int __net_init pg_net_init(struct net *net)
 		goto remove;
 	}
 
+	cpus_read_lock();
 	for_each_online_cpu(cpu) {
 		int err;
 
@@ -3997,6 +3998,7 @@  static int __net_init pg_net_init(struct net *net)
 			pr_warn("Cannot create thread for cpu %d (%d)\n",
 				   cpu, err);
 	}
+	cpus_read_unlock();
 
 	if (list_empty(&pn->pktgen_threads)) {
 		pr_err("Initialization failed for all threads\n");