All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/sched/wait.c: set timeout to 0 when kthread should stop
@ 2020-05-12  3:50 Qingjie Xing
  0 siblings, 0 replies; only message in thread
From: Qingjie Xing @ 2020-05-12  3:50 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, linux-kernel, Qingjie Xing

Using kthread_stop() to terminate a thread causes tcp_recvmsg()
to enter a dead loop when the kernel thread uses tcp_recvmsg()
to receive a message.

tcp_recvmsg()-->sk_wait_data()-->sk_wait_event()-->wait_woken().

wait_woken() will directly return unchanged timeout value rather
than be executed as normally.

tcp_recvmsg () will continues to execute sk_wait_data(). So finally
this situation will creat an endless loop that cannot be exited.

Signed-off-by: Qingjie Xing <xqjcool@gmail.com>
---
 kernel/sched/wait.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index ba059fb..a27bbbd 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -431,6 +431,8 @@ long wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout)
 	set_current_state(mode); /* A */
 	if (!(wq_entry->flags & WQ_FLAG_WOKEN) && !is_kthread_should_stop())
 		timeout = schedule_timeout(timeout);
+	if (is_kthread_should_stop())
+		timeout = 0;
 	__set_current_state(TASK_RUNNING);
 
 	/*
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-14  6:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12  3:50 [PATCH] kernel/sched/wait.c: set timeout to 0 when kthread should stop Qingjie Xing

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.