Skip to content

Commit b0cb8db

Browse files
committed
Merge tag 'wq-for-5.19-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
Pull workqueue fixes from Tejun Heo: "Tetsuo's patch to trigger build warnings if system-wide wq's are flushed along with a TP type update and trivial comment update" * tag 'wq-for-5.19-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: Switch to new kerneldoc syntax for named variable macro argument workqueue: Fix type of cpu in trace event workqueue: Wrap flush_workqueue() using a macro
2 parents e3b8e2d + 8bee9dd commit b0cb8db

File tree

3 files changed

+73
-17
lines changed

3 files changed

+73
-17
lines changed

include/linux/workqueue.h

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...);
406406
* alloc_ordered_workqueue - allocate an ordered workqueue
407407
* @fmt: printf format for the name of the workqueue
408408
* @flags: WQ_* flags (only WQ_FREEZABLE and WQ_MEM_RECLAIM are meaningful)
409-
* @args...: args for @fmt
409+
* @args: args for @fmt
410410
*
411411
* Allocate an ordered workqueue. An ordered workqueue executes at
412412
* most one work item at any given time in the queued order. They are
@@ -445,7 +445,7 @@ extern bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
445445
struct delayed_work *dwork, unsigned long delay);
446446
extern bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork);
447447

448-
extern void flush_workqueue(struct workqueue_struct *wq);
448+
extern void __flush_workqueue(struct workqueue_struct *wq);
449449
extern void drain_workqueue(struct workqueue_struct *wq);
450450

451451
extern int schedule_on_each_cpu(work_func_t func);
@@ -563,15 +563,23 @@ static inline bool schedule_work(struct work_struct *work)
563563
return queue_work(system_wq, work);
564564
}
565565

566+
/*
567+
* Detect attempt to flush system-wide workqueues at compile time when possible.
568+
*
569+
* See https://lkml.kernel.org/r/[email protected]
570+
* for reasons and steps for converting system-wide workqueues into local workqueues.
571+
*/
572+
extern void __warn_flushing_systemwide_wq(void)
573+
__compiletime_warning("Please avoid flushing system-wide workqueues.");
574+
566575
/**
567576
* flush_scheduled_work - ensure that any scheduled work has run to completion.
568577
*
569578
* Forces execution of the kernel-global workqueue and blocks until its
570579
* completion.
571580
*
572-
* Think twice before calling this function! It's very easy to get into
573-
* trouble if you don't take great care. Either of the following situations
574-
* will lead to deadlock:
581+
* It's very easy to get into trouble if you don't take great care.
582+
* Either of the following situations will lead to deadlock:
575583
*
576584
* One of the work items currently on the workqueue needs to acquire
577585
* a lock held by your code or its caller.
@@ -586,11 +594,51 @@ static inline bool schedule_work(struct work_struct *work)
586594
* need to know that a particular work item isn't queued and isn't running.
587595
* In such cases you should use cancel_delayed_work_sync() or
588596
* cancel_work_sync() instead.
597+
*
598+
* Please stop calling this function! A conversion to stop flushing system-wide
599+
* workqueues is in progress. This function will be removed after all in-tree
600+
* users stopped calling this function.
589601
*/
590-
static inline void flush_scheduled_work(void)
591-
{
592-
flush_workqueue(system_wq);
593-
}
602+
/*
603+
* The background of commit 771c035372a036f8 ("deprecate the
604+
* '__deprecated' attribute warnings entirely and for good") is that,
605+
* since Linus builds all modules between every single pull he does,
606+
* the standard kernel build needs to be _clean_ in order to be able to
607+
* notice when new problems happen. Therefore, don't emit warning while
608+
* there are in-tree users.
609+
*/
610+
#define flush_scheduled_work() \
611+
({ \
612+
if (0) \
613+
__warn_flushing_systemwide_wq(); \
614+
__flush_workqueue(system_wq); \
615+
})
616+
617+
/*
618+
* Although there is no longer in-tree caller, for now just emit warning
619+
* in order to give out-of-tree callers time to update.
620+
*/
621+
#define flush_workqueue(wq) \
622+
({ \
623+
struct workqueue_struct *_wq = (wq); \
624+
\
625+
if ((__builtin_constant_p(_wq == system_wq) && \
626+
_wq == system_wq) || \
627+
(__builtin_constant_p(_wq == system_highpri_wq) && \
628+
_wq == system_highpri_wq) || \
629+
(__builtin_constant_p(_wq == system_long_wq) && \
630+
_wq == system_long_wq) || \
631+
(__builtin_constant_p(_wq == system_unbound_wq) && \
632+
_wq == system_unbound_wq) || \
633+
(__builtin_constant_p(_wq == system_freezable_wq) && \
634+
_wq == system_freezable_wq) || \
635+
(__builtin_constant_p(_wq == system_power_efficient_wq) && \
636+
_wq == system_power_efficient_wq) || \
637+
(__builtin_constant_p(_wq == system_freezable_power_efficient_wq) && \
638+
_wq == system_freezable_power_efficient_wq)) \
639+
__warn_flushing_systemwide_wq(); \
640+
__flush_workqueue(_wq); \
641+
})
594642

595643
/**
596644
* schedule_delayed_work_on - queue work in global workqueue on CPU after delay

include/trace/events/workqueue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct pool_workqueue;
2222
*/
2323
TRACE_EVENT(workqueue_queue_work,
2424

25-
TP_PROTO(unsigned int req_cpu, struct pool_workqueue *pwq,
25+
TP_PROTO(int req_cpu, struct pool_workqueue *pwq,
2626
struct work_struct *work),
2727

2828
TP_ARGS(req_cpu, pwq, work),
@@ -31,8 +31,8 @@ TRACE_EVENT(workqueue_queue_work,
3131
__field( void *, work )
3232
__field( void *, function)
3333
__string( workqueue, pwq->wq->name)
34-
__field( unsigned int, req_cpu )
35-
__field( unsigned int, cpu )
34+
__field( int, req_cpu )
35+
__field( int, cpu )
3636
),
3737

3838
TP_fast_assign(
@@ -43,7 +43,7 @@ TRACE_EVENT(workqueue_queue_work,
4343
__entry->cpu = pwq->pool->cpu;
4444
),
4545

46-
TP_printk("work struct=%p function=%ps workqueue=%s req_cpu=%u cpu=%u",
46+
TP_printk("work struct=%p function=%ps workqueue=%s req_cpu=%d cpu=%d",
4747
__entry->work, __entry->function, __get_str(workqueue),
4848
__entry->req_cpu, __entry->cpu)
4949
);

kernel/workqueue.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,13 +2788,13 @@ static bool flush_workqueue_prep_pwqs(struct workqueue_struct *wq,
27882788
}
27892789

27902790
/**
2791-
* flush_workqueue - ensure that any scheduled work has run to completion.
2791+
* __flush_workqueue - ensure that any scheduled work has run to completion.
27922792
* @wq: workqueue to flush
27932793
*
27942794
* This function sleeps until all work items which were queued on entry
27952795
* have finished execution, but it is not livelocked by new incoming ones.
27962796
*/
2797-
void flush_workqueue(struct workqueue_struct *wq)
2797+
void __flush_workqueue(struct workqueue_struct *wq)
27982798
{
27992799
struct wq_flusher this_flusher = {
28002800
.list = LIST_HEAD_INIT(this_flusher.list),
@@ -2943,7 +2943,7 @@ void flush_workqueue(struct workqueue_struct *wq)
29432943
out_unlock:
29442944
mutex_unlock(&wq->mutex);
29452945
}
2946-
EXPORT_SYMBOL(flush_workqueue);
2946+
EXPORT_SYMBOL(__flush_workqueue);
29472947

29482948
/**
29492949
* drain_workqueue - drain a workqueue
@@ -2971,7 +2971,7 @@ void drain_workqueue(struct workqueue_struct *wq)
29712971
wq->flags |= __WQ_DRAINING;
29722972
mutex_unlock(&wq->mutex);
29732973
reflush:
2974-
flush_workqueue(wq);
2974+
__flush_workqueue(wq);
29752975

29762976
mutex_lock(&wq->mutex);
29772977

@@ -6111,3 +6111,11 @@ void __init workqueue_init(void)
61116111
wq_online = true;
61126112
wq_watchdog_init();
61136113
}
6114+
6115+
/*
6116+
* Despite the naming, this is a no-op function which is here only for avoiding
6117+
* link error. Since compile-time warning may fail to catch, we will need to
6118+
* emit run-time warning from __flush_workqueue().
6119+
*/
6120+
void __warn_flushing_systemwide_wq(void) { }
6121+
EXPORT_SYMBOL(__warn_flushing_systemwide_wq);

0 commit comments

Comments
 (0)