Skip to contentSkip to conversation

kernel/sched/wait.c: set timeout to 0 when kthread should stop

PATCH New Qingjie Xing 1 participant 1 message May 14, 2020 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/sched/wait.c: set timeout to 0 when kthread should stop

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.

---
 kernel/sched/wait.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/sched/wait.c +2 -0
index ba059fb..a27bbbd 100644
@@ -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);
 
 	/*
Signature · 1 line
1.8.3.1