* [PATCH v2] workqueue: Warn when work flush own workqueue @ 2020-08-25 3:06 Qianli Zhao [not found] ` <8aef74ea-5b28-07e1-d66b-91ed9e0920e9@web.de> 0 siblings, 1 reply; 3+ messages in thread From: Qianli Zhao @ 2020-08-25 3:06 UTC (permalink / raw) To: tj, jiangshanlai, Markus.Elfring; +Cc: linux-kernel, zhaoqianli From: Qianli Zhao <zhaoqianli@xiaomi.com> Flushing own workqueue or work self in work context will lead to a deadlock. Catch this incorrect usage and issue a warning when issue happened crash> ps 10856 PID PPID CPU TASK ST COMM 10856 2 2 ffffffc873428080 UN [kworker/u16:15] crash> bt 10856 PID: 10856 TASK: ffffffc873428080 CPU: 2 COMMAND: "kworker/u16:15" #0 [ffffff80270cb9a0] __switch_to at ffffff99bba8533c #1 [ffffff80270cba30] __schedule at ffffff99bcda18dc #2 [ffffff80270cba50] schedule at ffffff99bcda1cdc #3 [ffffff80270cbaf0] schedule_timeout at ffffff99bcda6674 #4 [ffffff80270cbb70] wait_for_common at ffffff99bcda2c68 #5 [ffffff80270cbb80] wait_for_completion at ffffff99bcda2b60 #6 [ffffff80270cbc30] flush_workqueue at ffffff99bbad7a60 #7 [ffffff80270cbc90] drain_workqueue at ffffff99bbad80fc #8 [ffffff80270cbcb0] destroy_workqueue at ffffff99bbad92f8 #9 [ffffff80270cbda0] dfc_svc_init at ffffff99bbfbfb6c #10 [ffffff80270cbdf0] process_one_work at ffffff99bbadc478 #11 [ffffff80270cbe50] worker_thread at ffffff99bbadc9dc #12 [ffffff80270cbeb0] kthread at ffffff99bbae1f84 Signed-off-by: Qianli Zhao <zhaoqianli@xiaomi.com> --- Changes in V2: - update changelog - update comment --- kernel/workqueue.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 3f5d4bf..9798d77 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2585,6 +2585,7 @@ static int rescuer_thread(void *__rescuer) * @target_work: work item being flushed (NULL for workqueue flushes) * * %current is trying to flush the whole @target_wq or @target_work on it. + * If a work flushing own workqueue or itself will lead to a deadlock. * If @target_wq doesn't have %WQ_MEM_RECLAIM, verify that %current is not * reclaiming memory or running on a workqueue which doesn't have * %WQ_MEM_RECLAIM as that can break forward-progress guarantee leading to @@ -2594,13 +2595,16 @@ static void check_flush_dependency(struct workqueue_struct *target_wq, struct work_struct *target_work) { work_func_t target_func = target_work ? target_work->func : NULL; - struct worker *worker; + struct worker *worker = current_wq_worker(); + + WARN_ONCE(worker && worker->current_pwq->wq == target_wq && + worker->task == current, + "workqueue: current work function:%ps is flushing own workqueue:%s", + worker->current_func, target_wq->name); if (target_wq->flags & WQ_MEM_RECLAIM) return; - worker = current_wq_worker(); - WARN_ONCE(current->flags & PF_MEMALLOC, "workqueue: PF_MEMALLOC task %d(%s) is flushing !WQ_MEM_RECLAIM %s:%ps", current->pid, current->comm, target_wq->name, target_func); -- 2.7.4 ^ permalink raw reply related [flat|nested] 3+ messages in thread
[parent not found: <8aef74ea-5b28-07e1-d66b-91ed9e0920e9@web.de>]
* Re: [PATCH v2] workqueue: Warn when work flush own workqueue [not found] ` <8aef74ea-5b28-07e1-d66b-91ed9e0920e9@web.de> @ 2020-08-25 8:55 ` qianli zhao 2020-08-25 10:04 ` Dan Carpenter 0 siblings, 1 reply; 3+ messages in thread From: qianli zhao @ 2020-08-25 8:55 UTC (permalink / raw) To: Markus Elfring Cc: Qianli Zhao, Tejun Heo, Lai Jiangshan, linux-kernel, kernel-janitors Markus Thanks for your suggestion,and sorry for my poor wording. On Tue, Aug 25, 2020 at 4:00 PM Markus Elfring <Markus.Elfring@web.de> wrote: > > > Flushing own workqueue or work self in work context will lead to > > a deadlock. > > I imagine that the wording “or work self” can become clearer another bit. > > > > Catch this incorrect usage and issue a warning when issue happened > > * Would you like to mark the end of such a sentence with a dot? > > * How do you think about to adjust the repetition of the word “issue”? How about below changelog? workqueue: Warn when work flush own workqueue Flushing itself or own workqueue in work context will lead to a deadlock. Catch this incorrect usage and warning when issue happened. > > > … > > - update comment > > --- > > kernel/workqueue.c | 10 +++++++--- > > I suggest to replace these triple dashes by a blank line. Ok > > > … > > @@ -2585,6 +2585,7 @@ static int rescuer_thread(void *__rescuer) > > * @target_work: work item being flushed (NULL for workqueue flushes) > > * > > * %current is trying to flush the whole @target_wq or @target_work on it. > > + * If a work flushing own workqueue or itself will lead to a deadlock. > > I stumble on understanding challenges for the wording “work flushing”. > Can an adjustment help in comparison to the term “work item”? How about below comment? * If a work item flushing own workqueue or itself will lead to a deadlock. > > Regards, > Markus ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] workqueue: Warn when work flush own workqueue 2020-08-25 8:55 ` qianli zhao @ 2020-08-25 10:04 ` Dan Carpenter 0 siblings, 0 replies; 3+ messages in thread From: Dan Carpenter @ 2020-08-25 10:04 UTC (permalink / raw) To: qianli zhao Cc: Markus Elfring, Qianli Zhao, Tejun Heo, Lai Jiangshan, linux-kernel, kernel-janitors We have asked Markus to stop harrassing people about commit messages but he refuses so I think he was banned from vger at the start of the month. On Tue, Aug 25, 2020 at 04:55:52PM +0800, qianli zhao wrote: > Markus > > Thanks for your suggestion,and sorry for my poor wording. > > On Tue, Aug 25, 2020 at 4:00 PM Markus Elfring <Markus.Elfring@web.de> wrote: > > > > > Flushing own workqueue or work self in work context will lead to > > > a deadlock. > > > > I imagine that the wording “or work self” can become clearer another bit. > > > > > > > Catch this incorrect usage and issue a warning when issue happened > > > > * Would you like to mark the end of such a sentence with a dot? > > > > * How do you think about to adjust the repetition of the word “issue”? > > How about below changelog? > > workqueue: Warn when work flush own workqueue > > Flushing itself or own workqueue in work context will > lead to a deadlock. > Catch this incorrect usage and warning when issue happened. "If a workqueue flushes itself then that will lead to a deadlock. Print a warning and a stack trace when this happens." > > > > > > > … > > > - update comment > > > --- > > > kernel/workqueue.c | 10 +++++++--- > > > > I suggest to replace these triple dashes by a blank line. > Ok This does not matter at all. Keep the dashes or remove them. It doesn't matter at all. > > > > > > … > > > @@ -2585,6 +2585,7 @@ static int rescuer_thread(void *__rescuer) > > > * @target_work: work item being flushed (NULL for workqueue flushes) > > > * > > > * %current is trying to flush the whole @target_wq or @target_work on it. > > > + * If a work flushing own workqueue or itself will lead to a deadlock. > > > > I stumble on understanding challenges for the wording “work flushing”. > > Can an adjustment help in comparison to the term “work item”? > > How about below comment? > > * If a work item flushing own workqueue or itself will lead to a deadlock. Write this: * If a work queue flushes itself, that will lead to a deadlock regards, dan carpenter ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-25 10:05 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-08-25 3:06 [PATCH v2] workqueue: Warn when work flush own workqueue Qianli Zhao [not found] ` <8aef74ea-5b28-07e1-d66b-91ed9e0920e9@web.de> 2020-08-25 8:55 ` qianli zhao 2020-08-25 10:04 ` Dan Carpenter
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).