Skip to contentSkip to conversation

kthread: Work could not be queued when worker being destroyed

PATCH NAK [email protected] 2 participants 3 messages Jul 7, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 kthread: Work could not be queued when worker being destroyed

From: Zhang Qiang <[email protected]>

Before the work is put into the queue of the worker thread, the state of the worker thread needs to be detected,because the worker thread may be in the destruction state at this time.

---
v1->v2:
Add warning information for condition "!worker->task".
v2->v3:
Modify submission information and add "Reviewed-by" tags.
v3->v4:
Fix spi controller register trigger Warning.
when a spi controller register, a "kthread_worker_fn" worker is created through "kthread_run" instead of "kthread_create_worker" which in this func the "worker->task" will be initialized. and then the "spi_start_queue" func queue a work to worker queue, at this time, if the worker has not begin to running, the "!worker->task" will be true, so a warning is triggered.

 kernel/kthread.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/kthread.c +5 -0
index bfbfa481be3a..825bd4dcdb95 100644
@@ -791,6 +791,11 @@ static inline bool queuing_blocked(struct kthread_worker *worker,
 {
 	lockdep_assert_held(&worker->lock);
 
+	if (kthread_should_stop()) {
+		WARN_ON(1);
+		return true;
+	}
+
 	return !list_empty(&work->node) || work->canceling;
 }
 
Signature · 1 line
2.24.1
Nacked-by on v4 1/1 NAK
#1 lore raw
Quoted 9 lines · On Mon 2020-07-06 13:46:47, [email protected] wrote:

From: Zhang Qiang <[email protected]>

Before the work is put into the queue of the worker thread, the state of the worker thread needs to be detected,because the worker thread may be in the destruction state at this time.

This patch is completely different from the one that I suggested or acked. Please, never keep acks when doing major rework and people did not agree with it.

For this patch:

See below why.

Quoted 21 lines

---
v1->v2:
Add warning information for condition "!worker->task".
v2->v3:
Modify submission information and add "Reviewed-by" tags.
v3->v4:
Fix spi controller register trigger Warning.
when a spi controller register, a "kthread_worker_fn" worker is created through "kthread_run" instead of "kthread_create_worker" which in this func the "worker->task" will be initialized. and then the "spi_start_queue" func queue a work to worker queue, at this time, if the worker has not begin to running, the "!worker->task" will be true, so a warning is triggered.

 kernel/kthread.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/kthread.c +0 -0
index bfbfa481be3a..825bd4dcdb95 100644

kernel/kthread.c static inline bool queuing_blocked(struct kthread_worker *worker, · line 794

Quoted 4 lines
kernel/kthread.c +1 -0
@@ -791,6 +791,11 @@ static inline bool queuing_blocked(struct kthread_worker *worker,
 {
 	lockdep_assert_held(&worker->lock);
 
+	if (kthread_should_stop()) {

This does not make much sense.

kthread_should_stop() checks a flag set for the "current" process. It works only when called from inside the kthread worker thread.

queuing_blocked() is called from kthread_queue_work() or kthread_queue_delayed_work(). These are typically called from another process. The only exception is when they get re-queued from inside the work.

Best Regards,
Petr

Quoted 9 lines
kernel/kthread.c +4 -0
+		WARN_ON(1);
+		return true;
+	}
+
 	return !list_empty(&work->node) || work->canceling;
 }
 
Signature · 1 line
2.24.1
author Nacked-by Petr Mladek NAK
#2 lore raw

Sorry, Pter Mladek, this is my mistake please ignore this change.

________________________________________
发件人: [email protected] <[email protected]> 代表 Petr Mladek <[email protected]>
发送时间: 2020年7月7日 17:06
收件人: Zhang, Qiang
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] 主题: Re: [PATCH v4] kthread: Work could not be queued when worker being destroyed

Quoted 9 lines · On Mon 2020-07-06 13:46:47, [email protected] wrote:

From: Zhang Qiang <[email protected]>

Before the work is put into the queue of the worker thread, the state of the worker thread needs to be detected,because the worker thread may be in the destruction state at this time.

This patch is completely different from the one that I suggested or acked. Please, never keep acks when doing major rework and people did not agree with it.

For this patch:

See below why.

Quoted 21 lines

---
v1->v2:
Add warning information for condition "!worker->task".
v2->v3:
Modify submission information and add "Reviewed-by" tags.
v3->v4:
Fix spi controller register trigger Warning.
when a spi controller register, a "kthread_worker_fn" worker is created through "kthread_run" instead of "kthread_create_worker" which in this func the "worker->task" will be initialized. and then the "spi_start_queue" func queue a work to worker queue, at this time, if the worker has not begin to running, the "!worker->task" will be true, so a warning is triggered.

 kernel/kthread.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/kthread.c +0 -0
index bfbfa481be3a..825bd4dcdb95 100644

kernel/kthread.c static inline bool queuing_blocked(struct kthread_worker *worker, · line 794

Quoted 4 lines
kernel/kthread.c +1 -0
@@ -791,6 +791,11 @@ static inline bool queuing_blocked(struct kthread_worker *worker,
 {
      lockdep_assert_held(&worker->lock);
 
+     if (kthread_should_stop()) {

This does not make much sense.

kthread_should_stop() checks a flag set for the "current" process. It works only when called from inside the kthread worker thread.

queuing_blocked() is called from kthread_queue_work() or kthread_queue_delayed_work(). These are typically called from another process. The only exception is when they get re-queued from inside the work.

Best Regards,
Petr

Quoted 9 lines
kernel/kthread.c +4 -1
+             WARN_ON(1);
+             return true;
+     }
+
      return !list_empty(&work->node) || work->canceling;
 }
 
--

2.24.1