linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop()
@ 2015-07-08 19:41 Oleg Nesterov
  2015-07-08 19:42 ` [PATCH 1/2] " Oleg Nesterov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Oleg Nesterov @ 2015-07-08 19:41 UTC (permalink / raw)
  To: Alexei Starovoitov, David S. Miller, Eric Dumazet
  Cc: Jan Stancek, Marcelo Leitner, netdev, linux-kernel

Hello,

I am not familiar with this code and I have no idea how to test
these changes, so 2/2 comes as a separate change. 1/2 looks like
the obvious bugfix, and probably candidate for -stable.

Oleg.

 net/core/pktgen.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)


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

* [PATCH 1/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop()
  2015-07-08 19:41 [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Oleg Nesterov
@ 2015-07-08 19:42 ` Oleg Nesterov
  2015-07-08 19:42 ` [PATCH 2/2] net: pktgen: kill the "Wait for kthread_stop" code in pktgen_thread_worker() Oleg Nesterov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2015-07-08 19:42 UTC (permalink / raw)
  To: Alexei Starovoitov, David S. Miller, Eric Dumazet
  Cc: Jan Stancek, Marcelo Leitner, netdev, linux-kernel

pktgen_thread_worker() is obviously racy, kthread_stop() can come
between the kthread_should_stop() check and set_current_state().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reported-by: Jan Stancek <jstancek@redhat.com>
Reported-by: Marcelo Leitner <mleitner@redhat.com>
---
 net/core/pktgen.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 508155b..043ea18 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3490,8 +3490,10 @@ static int pktgen_thread_worker(void *arg)
 	pktgen_rem_thread(t);
 
 	/* Wait for kthread_stop */
-	while (!kthread_should_stop()) {
+	for (;;) {
 		set_current_state(TASK_INTERRUPTIBLE);
+		if (kthread_should_stop())
+			break;
 		schedule();
 	}
 	__set_current_state(TASK_RUNNING);
-- 
1.5.5.1


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

* [PATCH 2/2] net: pktgen: kill the "Wait for kthread_stop" code in pktgen_thread_worker()
  2015-07-08 19:41 [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Oleg Nesterov
  2015-07-08 19:42 ` [PATCH 1/2] " Oleg Nesterov
@ 2015-07-08 19:42 ` Oleg Nesterov
  2015-07-09 22:06 ` [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() David Miller
  2015-07-10 11:32 ` Marcelo Ricardo Leitner
  3 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2015-07-08 19:42 UTC (permalink / raw)
  To: Alexei Starovoitov, David S. Miller, Eric Dumazet
  Cc: Jan Stancek, Marcelo Leitner, netdev, linux-kernel

pktgen_thread_worker() doesn't need to wait for kthread_stop(), it
can simply exit. Just pktgen_create_thread() and pg_net_exit() should
do get_task_struct()/put_task_struct(). kthread_stop(dead_thread) is
fine.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 net/core/pktgen.c |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 043ea18..8e0181a 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3489,15 +3489,6 @@ static int pktgen_thread_worker(void *arg)
 	pr_debug("%s removing thread\n", t->tsk->comm);
 	pktgen_rem_thread(t);
 
-	/* Wait for kthread_stop */
-	for (;;) {
-		set_current_state(TASK_INTERRUPTIBLE);
-		if (kthread_should_stop())
-			break;
-		schedule();
-	}
-	__set_current_state(TASK_RUNNING);
-
 	return 0;
 }
 
@@ -3689,6 +3680,7 @@ static int __net_init pktgen_create_thread(int cpu, struct pktgen_net *pn)
 	}
 
 	t->net = pn;
+	get_task_struct(p);
 	wake_up_process(p);
 	wait_for_completion(&t->start_done);
 
@@ -3811,6 +3803,7 @@ static void __net_exit pg_net_exit(struct net *net)
 		t = list_entry(q, struct pktgen_thread, th_list);
 		list_del(&t->th_list);
 		kthread_stop(t->tsk);
+		put_task_struct(t->tsk);
 		kfree(t);
 	}
 
-- 
1.5.5.1


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

* Re: [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop()
  2015-07-08 19:41 [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Oleg Nesterov
  2015-07-08 19:42 ` [PATCH 1/2] " Oleg Nesterov
  2015-07-08 19:42 ` [PATCH 2/2] net: pktgen: kill the "Wait for kthread_stop" code in pktgen_thread_worker() Oleg Nesterov
@ 2015-07-09 22:06 ` David Miller
  2015-07-10 11:32 ` Marcelo Ricardo Leitner
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2015-07-09 22:06 UTC (permalink / raw)
  To: oleg; +Cc: ast, edumazet, jstancek, mleitner, netdev, linux-kernel

From: Oleg Nesterov <oleg@redhat.com>
Date: Wed, 8 Jul 2015 21:41:54 +0200

> I am not familiar with this code and I have no idea how to test
> these changes, so 2/2 comes as a separate change. 1/2 looks like
> the obvious bugfix, and probably candidate for -stable.

These look fine to me, applied and patch #1 queued up for -stable.

Thanks.

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

* Re: [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop()
  2015-07-08 19:41 [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Oleg Nesterov
                   ` (2 preceding siblings ...)
  2015-07-09 22:06 ` [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() David Miller
@ 2015-07-10 11:32 ` Marcelo Ricardo Leitner
  3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Ricardo Leitner @ 2015-07-10 11:32 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Alexei Starovoitov, David S. Miller, Eric Dumazet, Jan Stancek,
	netdev, linux-kernel

On Wed, Jul 08, 2015 at 09:41:54PM +0200, Oleg Nesterov wrote:
> Hello,
> 
> I am not familiar with this code and I have no idea how to test
> these changes, so 2/2 comes as a separate change. 1/2 looks like
> the obvious bugfix, and probably candidate for -stable.
> 
> Oleg.
> 
>  net/core/pktgen.c |    9 ++-------
>  1 files changed, 2 insertions(+), 7 deletions(-)
> 

Both patches tested here, works for me.

Thanks,
Marcelo


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

end of thread, other threads:[~2015-07-10 11:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-08 19:41 [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Oleg Nesterov
2015-07-08 19:42 ` [PATCH 1/2] " Oleg Nesterov
2015-07-08 19:42 ` [PATCH 2/2] net: pktgen: kill the "Wait for kthread_stop" code in pktgen_thread_worker() Oleg Nesterov
2015-07-09 22:06 ` [PATCH 0/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() David Miller
2015-07-10 11:32 ` Marcelo Ricardo Leitner

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