Skip to content

Commit 20bdeda

Browse files
Tetsuo Handahtejun
authored andcommitted
workqueue: Warn attempt to flush system-wide workqueues.
Based on commit c4f135d ("workqueue: Wrap flush_workqueue() using a macro"), all in-tree users stopped flushing system-wide workqueues. Therefore, start emitting runtime message so that all out-of-tree users will understand that they need to update their code. Signed-off-by: Tetsuo Handa <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 3f01e9f commit 20bdeda

File tree

2 files changed

+8
-47
lines changed

2 files changed

+8
-47
lines changed

include/linux/workqueue.h

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -569,59 +569,21 @@ static inline bool schedule_work(struct work_struct *work)
569569

570570
/*
571571
* Detect attempt to flush system-wide workqueues at compile time when possible.
572+
* Warn attempt to flush system-wide workqueues at runtime.
572573
*
573574
* See https://lkml.kernel.org/r/[email protected]
574575
* for reasons and steps for converting system-wide workqueues into local workqueues.
575576
*/
576577
extern void __warn_flushing_systemwide_wq(void)
577578
__compiletime_warning("Please avoid flushing system-wide workqueues.");
578579

579-
/**
580-
* flush_scheduled_work - ensure that any scheduled work has run to completion.
581-
*
582-
* Forces execution of the kernel-global workqueue and blocks until its
583-
* completion.
584-
*
585-
* It's very easy to get into trouble if you don't take great care.
586-
* Either of the following situations will lead to deadlock:
587-
*
588-
* One of the work items currently on the workqueue needs to acquire
589-
* a lock held by your code or its caller.
590-
*
591-
* Your code is running in the context of a work routine.
592-
*
593-
* They will be detected by lockdep when they occur, but the first might not
594-
* occur very often. It depends on what work items are on the workqueue and
595-
* what locks they need, which you have no control over.
596-
*
597-
* In most situations flushing the entire workqueue is overkill; you merely
598-
* need to know that a particular work item isn't queued and isn't running.
599-
* In such cases you should use cancel_delayed_work_sync() or
600-
* cancel_work_sync() instead.
601-
*
602-
* Please stop calling this function! A conversion to stop flushing system-wide
603-
* workqueues is in progress. This function will be removed after all in-tree
604-
* users stopped calling this function.
605-
*/
606-
/*
607-
* The background of commit 771c035372a036f8 ("deprecate the
608-
* '__deprecated' attribute warnings entirely and for good") is that,
609-
* since Linus builds all modules between every single pull he does,
610-
* the standard kernel build needs to be _clean_ in order to be able to
611-
* notice when new problems happen. Therefore, don't emit warning while
612-
* there are in-tree users.
613-
*/
580+
/* Please stop using this function, for this function will be removed in near future. */
614581
#define flush_scheduled_work() \
615582
({ \
616-
if (0) \
617-
__warn_flushing_systemwide_wq(); \
583+
__warn_flushing_systemwide_wq(); \
618584
__flush_workqueue(system_wq); \
619585
})
620586

621-
/*
622-
* Although there is no longer in-tree caller, for now just emit warning
623-
* in order to give out-of-tree callers time to update.
624-
*/
625587
#define flush_workqueue(wq) \
626588
({ \
627589
struct workqueue_struct *_wq = (wq); \

kernel/workqueue.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6571,10 +6571,9 @@ void __init workqueue_init(void)
65716571
wq_watchdog_init();
65726572
}
65736573

6574-
/*
6575-
* Despite the naming, this is a no-op function which is here only for avoiding
6576-
* link error. Since compile-time warning may fail to catch, we will need to
6577-
* emit run-time warning from __flush_workqueue().
6578-
*/
6579-
void __warn_flushing_systemwide_wq(void) { }
6574+
void __warn_flushing_systemwide_wq(void)
6575+
{
6576+
pr_warn("WARNING: Flushing system-wide workqueues will be prohibited in near future.\n");
6577+
dump_stack();
6578+
}
65806579
EXPORT_SYMBOL(__warn_flushing_systemwide_wq);

0 commit comments

Comments
 (0)