History

Merge branch 'for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq

Pull workqueue updates from Tejun Heo: "Mostly cleanups and other trivial changes. The only interesting change is Sebastian's rcuwait conversion for RT" * 'for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: use BUILD_BUG_ON() for compile time test instead of WARN_ON() workqueue: fix a piece of comment about reserved bits for work flags workqueue: remove useless unlock() and lock() in series workqueue: void unneeded requeuing the pwq in rescuer thread workqueue: Convert the pool::lock and wq_mayday_lock to raw_spinlock_t workqueue: Use rcuwait for wq_manager_wait workqueue: Remove unnecessary kfree() call in rcu_free_wq() workqueue: Fix an use after free in init_rescuer() workqueue: Use IS_ERR and PTR_ERR instead of PTR_ERR_OR_ZERO.

Linus Torvalds committed 6 years ago

Commit fe3bc8a2 parents 4a7e89c 10cdb152 files · +110 −99Browse files

Unified · Split

2 files
  1. include/linux/workqueue.h +1 −1
  2. kernel/workqueue.c +109 −98
include/linux/workqueue.h+1−1
@@ -62,7 +62,7 @@ enum { · 61 unmodified lines
6262 WORK_CPU_UNBOUND = NR_CPUS,
6363
6464 /*
65− * Reserve 7 bits off of pwq pointer w/ debugobjects turned off.
65+ * Reserve 8 bits off of pwq pointer w/ debugobjects turned off.
6666 * This makes pwqs aligned to 256 bytes and allows 15 workqueue
6767 * flush colors.
6868 */
kernel/workqueue.c+109−98
@@ -145,7 +145,7 @@ enum { · 144 unmodified lines
145145 /* struct worker is defined in workqueue_internal.h */
146146
147147 struct worker_pool {
148− spinlock_t lock; /* the pool lock */
148+ raw_spinlock_t lock; /* the pool lock */
149149 int cpu; /* I: the associated cpu */
150150 int node; /* I: the associated node ID */
151151 int id; /* I: pool ID */
@@ -300,8 +300,9 @@ static struct workqueue_attrs *wq_update_unbound_numa_attrs_buf; · 148 unmodified lines
300300
301301 static DEFINE_MUTEX(wq_pool_mutex); /* protects pools and workqueues list */
302302 static DEFINE_MUTEX(wq_pool_attach_mutex); /* protects worker attach/detach */
303−static DEFINE_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */
304−static DECLARE_WAIT_QUEUE_HEAD(wq_manager_wait); /* wait for manager to go away */
303+static DEFINE_RAW_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */
304+/* wait for manager to go away */
305+static struct rcuwait manager_wait = __RCUWAIT_INITIALIZER(manager_wait);
305306
306307 static LIST_HEAD(workqueues); /* PR: list of all workqueues */
307308 static bool workqueue_freezing; /* PL: have wqs started freezing? */
@@ -826,7 +827,7 @@ static struct worker *first_idle_worker(struct worker_pool *pool) · 518 unmodified lines
826827 * Wake up the first idle worker of @pool.
827828 *
828829 * CONTEXT:
829− * spin_lock_irq(pool->lock).
830+ * raw_spin_lock_irq(pool->lock).
830831 */
831832 static void wake_up_worker(struct worker_pool *pool)
832833 {
@@ -881,7 +882,7 @@ void wq_worker_sleeping(struct task_struct *task) · 48 unmodified lines
881882 return;
882883
883884 worker->sleeping = 1;
884− spin_lock_irq(&pool->lock);
885+ raw_spin_lock_irq(&pool->lock);
885886
886887 /*
887888 * The counterpart of the following dec_and_test, implied mb,
@@ -900,7 +901,7 @@ void wq_worker_sleeping(struct task_struct *task) · 12 unmodified lines
900901 if (next)
901902 wake_up_process(next->task);
902903 }
903− spin_unlock_irq(&pool->lock);
904+ raw_spin_unlock_irq(&pool->lock);
904905 }
905906
906907 /**
@@ -911,7 +912,7 @@ void wq_worker_sleeping(struct task_struct *task) · 4 unmodified lines
911912 * the scheduler to get a worker's last known identity.
912913 *
913914 * CONTEXT:
914− * spin_lock_irq(rq->lock)
915+ * raw_spin_lock_irq(rq->lock)
915916 *
916917 * This function is called during schedule() when a kworker is going
917918 * to sleep. It's used by psi to identify aggregation workers during
@@ -942,7 +943,7 @@ work_func_t wq_worker_last_func(struct task_struct *task) · 24 unmodified lines
942943 * Set @flags in @worker->flags and adjust nr_running accordingly.
943944 *
944945 * CONTEXT:
945− * spin_lock_irq(pool->lock)
946+ * raw_spin_lock_irq(pool->lock)
946947 */
947948 static inline void worker_set_flags(struct worker *worker, unsigned int flags)
948949 {
@@ -967,7 +968,7 @@ static inline void worker_set_flags(struct worker *worker, unsigned int flags) · 18 unmodified lines
967968 * Clear @flags in @worker->flags and adjust nr_running accordingly.
968969 *
969970 * CONTEXT:
970− * spin_lock_irq(pool->lock)
971+ * raw_spin_lock_irq(pool->lock)
971972 */
972973 static inline void worker_clr_flags(struct worker *worker, unsigned int flags)
973974 {
@@ -1015,7 +1016,7 @@ static inline void worker_clr_flags(struct worker *worker, unsigned int flags) · 41 unmodified lines
10151016 * actually occurs, it should be easy to locate the culprit work function.
10161017 *
10171018 * CONTEXT:
1018− * spin_lock_irq(pool->lock).
1019+ * raw_spin_lock_irq(pool->lock).
10191020 *
10201021 * Return:
10211022 * Pointer to worker which is executing @work if found, %NULL
@@ -1050,7 +1051,7 @@ static struct worker *find_worker_executing_work(struct worker_pool *pool, · 28 unmodified lines
10501051 * nested inside outer list_for_each_entry_safe().
10511052 *
10521053 * CONTEXT:
1053− * spin_lock_irq(pool->lock).
1054+ * raw_spin_lock_irq(pool->lock).
10541055 */
10551056 static void move_linked_works(struct work_struct *work, struct list_head *head,
10561057 struct work_struct **nextp)
@@ -1128,9 +1129,9 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq) · 71 unmodified lines
11281129 * As both pwqs and pools are RCU protected, the
11291130 * following lock operations are safe.
11301131 */
1131− spin_lock_irq(&pwq->pool->lock);
1132+ raw_spin_lock_irq(&pwq->pool->lock);
11321133 put_pwq(pwq);
1133− spin_unlock_irq(&pwq->pool->lock);
1134+ raw_spin_unlock_irq(&pwq->pool->lock);
11341135 }
11351136 }
11361137
@@ -1163,7 +1164,7 @@ static void pwq_activate_first_delayed(struct pool_workqueue *pwq) · 26 unmodified lines
11631164 * decrement nr_in_flight of its pwq and handle workqueue flushing.
11641165 *
11651166 * CONTEXT:
1166− * spin_lock_irq(pool->lock).
1167+ * raw_spin_lock_irq(pool->lock).
11671168 */
11681169 static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, int color)
11691170 {
@@ -1262,7 +1263,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork, · 92 unmodified lines
12621263 if (!pool)
12631264 goto fail;
12641265
1265− spin_lock(&pool->lock);
1266+ raw_spin_lock(&pool->lock);
12661267 /*
12671268 * work->data is guaranteed to point to pwq only while the work
12681269 * item is queued on pwq->wq, and both updating work->data to point
@@ -1291,11 +1292,11 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork, · 22 unmodified lines
12911292 /* work->data points to pwq iff queued, point to pool */
12921293 set_work_pool_and_keep_pending(work, pool->id);
12931294
1294− spin_unlock(&pool->lock);
1295+ raw_spin_unlock(&pool->lock);
12951296 rcu_read_unlock();
12961297 return 1;
12971298 }
1298− spin_unlock(&pool->lock);
1299+ raw_spin_unlock(&pool->lock);
12991300 fail:
13001301 rcu_read_unlock();
13011302 local_irq_restore(*flags);
@@ -1316,7 +1317,7 @@ fail: · 14 unmodified lines
13161317 * work_struct flags.
13171318 *
13181319 * CONTEXT:
1319− * spin_lock_irq(pool->lock).
1320+ * raw_spin_lock_irq(pool->lock).
13201321 */
13211322 static void insert_work(struct pool_workqueue *pwq, struct work_struct *work,
13221323 struct list_head *head, unsigned int extra_flags)
@@ -1433,7 +1434,7 @@ retry: · 110 unmodified lines
14331434 if (last_pool && last_pool != pwq->pool) {
14341435 struct worker *worker;
14351436
1436− spin_lock(&last_pool->lock);
1437+ raw_spin_lock(&last_pool->lock);
14371438
14381439 worker = find_worker_executing_work(last_pool, work);
14391440
@@ -1441,11 +1442,11 @@ retry: · 1 unmodified line
14411442 pwq = worker->current_pwq;
14421443 } else {
14431444 /* meh... not running there, queue here */
1444− spin_unlock(&last_pool->lock);
1445− spin_lock(&pwq->pool->lock);
1445+ raw_spin_unlock(&last_pool->lock);
1446+ raw_spin_lock(&pwq->pool->lock);
14461447 }
14471448 } else {
1448− spin_lock(&pwq->pool->lock);
1449+ raw_spin_lock(&pwq->pool->lock);
14491450 }
14501451
14511452 /*
@@ -1458,7 +1459,7 @@ retry: · 6 unmodified lines
14581459 */
14591460 if (unlikely(!pwq->refcnt)) {
14601461 if (wq->flags & WQ_UNBOUND) {
1461− spin_unlock(&pwq->pool->lock);
1462+ raw_spin_unlock(&pwq->pool->lock);
14621463 cpu_relax();
14631464 goto retry;
14641465 }
@@ -1490,7 +1491,7 @@ retry: · 25 unmodified lines
14901491 insert_work(pwq, work, worklist, work_flags);
14911492
14921493 out:
1493− spin_unlock(&pwq->pool->lock);
1494+ raw_spin_unlock(&pwq->pool->lock);
14941495 rcu_read_unlock();
14951496 }
14961497
@@ -1759,7 +1760,7 @@ EXPORT_SYMBOL(queue_rcu_work); · 262 unmodified lines
17591760 * necessary.
17601761 *
17611762 * LOCKING:
1762− * spin_lock_irq(pool->lock).
1763+ * raw_spin_lock_irq(pool->lock).
17631764 */
17641765 static void worker_enter_idle(struct worker *worker)
17651766 {
@@ -1799,7 +1800,7 @@ static void worker_enter_idle(struct worker *worker) · 33 unmodified lines
17991800 * @worker is leaving idle state. Update stats.
18001801 *
18011802 * LOCKING:
1802− * spin_lock_irq(pool->lock).
1803+ * raw_spin_lock_irq(pool->lock).
18031804 */
18041805 static void worker_leave_idle(struct worker *worker)
18051806 {
@@ -1937,11 +1938,11 @@ static struct worker *create_worker(struct worker_pool *pool) · 131 unmodified lines
19371938 worker_attach_to_pool(worker, pool);
19381939
19391940 /* start the newly created worker */
1940− spin_lock_irq(&pool->lock);
1941+ raw_spin_lock_irq(&pool->lock);
19411942 worker->pool->nr_workers++;
19421943 worker_enter_idle(worker);
19431944 wake_up_process(worker->task);
1944− spin_unlock_irq(&pool->lock);
1945+ raw_spin_unlock_irq(&pool->lock);
19451946
19461947 return worker;
19471948
@@ -1960,7 +1961,7 @@ fail: · 12 unmodified lines
19601961 * be idle.
19611962 *
19621963 * CONTEXT:
1963− * spin_lock_irq(pool->lock).
1964+ * raw_spin_lock_irq(pool->lock).
19641965 */
19651966 static void destroy_worker(struct worker *worker)
19661967 {
@@ -1986,7 +1987,7 @@ static void idle_worker_timeout(struct timer_list *t) · 19 unmodified lines
19861987 {
19871988 struct worker_pool *pool = from_timer(pool, t, idle_timer);
19881989
1989− spin_lock_irq(&pool->lock);
1990+ raw_spin_lock_irq(&pool->lock);
19901991
19911992 while (too_many_workers(pool)) {
19921993 struct worker *worker;
@@ -2004,7 +2005,7 @@ static void idle_worker_timeout(struct timer_list *t) · 11 unmodified lines
20042005 destroy_worker(worker);
20052006 }
20062007
2007− spin_unlock_irq(&pool->lock);
2008+ raw_spin_unlock_irq(&pool->lock);
20082009 }
20092010
20102011 static void send_mayday(struct work_struct *work)
@@ -2035,8 +2036,8 @@ static void pool_mayday_timeout(struct timer_list *t) · 24 unmodified lines
20352036 struct worker_pool *pool = from_timer(pool, t, mayday_timer);
20362037 struct work_struct *work;
20372038
2038− spin_lock_irq(&pool->lock);
2039− spin_lock(&wq_mayday_lock); /* for wq->maydays */
2039+ raw_spin_lock_irq(&pool->lock);
2040+ raw_spin_lock(&wq_mayday_lock); /* for wq->maydays */
20402041
20412042 if (need_to_create_worker(pool)) {
20422043 /*
@@ -2049,8 +2050,8 @@ static void pool_mayday_timeout(struct timer_list *t) · 6 unmodified lines
20492050 send_mayday(work);
20502051 }
20512052
2052− spin_unlock(&wq_mayday_lock);
2053− spin_unlock_irq(&pool->lock);
2053+ raw_spin_unlock(&wq_mayday_lock);
2054+ raw_spin_unlock_irq(&pool->lock);
20542055
20552056 mod_timer(&pool->mayday_timer, jiffies + MAYDAY_INTERVAL);
20562057 }
@@ -2069,7 +2070,7 @@ static void pool_mayday_timeout(struct timer_list *t) · 12 unmodified lines
20692070 * may_start_working() %true.
20702071 *
20712072 * LOCKING:
2072− * spin_lock_irq(pool->lock) which may be released and regrabbed
2073+ * raw_spin_lock_irq(pool->lock) which may be released and regrabbed
20732074 * multiple times. Does GFP_KERNEL allocations. Called only from
20742075 * manager.
20752076 */
@@ -2078,7 +2079,7 @@ __releases(&pool->lock) · 2 unmodified lines
20782079 __acquires(&pool->lock)
20792080 {
20802081 restart:
2081− spin_unlock_irq(&pool->lock);
2082+ raw_spin_unlock_irq(&pool->lock);
20822083
20832084 /* if we don't make progress in MAYDAY_INITIAL_TIMEOUT, call for help */
20842085 mod_timer(&pool->mayday_timer, jiffies + MAYDAY_INITIAL_TIMEOUT);
@@ -2094,7 +2095,7 @@ restart: · 9 unmodified lines
20942095 }
20952096
20962097 del_timer_sync(&pool->mayday_timer);
2097− spin_lock_irq(&pool->lock);
2098+ raw_spin_lock_irq(&pool->lock);
20982099 /*
20992100 * This is necessary even after a new worker was just successfully
21002101 * created as @pool->lock was dropped and the new worker might have
@@ -2117,7 +2118,7 @@ restart: · 16 unmodified lines
21172118 * and may_start_working() is true.
21182119 *
21192120 * CONTEXT:
2120− * spin_lock_irq(pool->lock) which may be released and regrabbed
2121+ * raw_spin_lock_irq(pool->lock) which may be released and regrabbed
21212122 * multiple times. Does GFP_KERNEL allocations.
21222123 *
21232124 * Return:
@@ -2140,7 +2141,7 @@ static bool manage_workers(struct worker *worker) · 16 unmodified lines
21402141
21412142 pool->manager = NULL;
21422143 pool->flags &= ~POOL_MANAGER_ACTIVE;
2143− wake_up(&wq_manager_wait);
2144+ rcuwait_wake_up(&manager_wait);
21442145 return true;
21452146 }
21462147
@@ -2156,7 +2157,7 @@ static bool manage_workers(struct worker *worker) · 9 unmodified lines
21562157 * call this function to process a work.
21572158 *
21582159 * CONTEXT:
2159− * spin_lock_irq(pool->lock) which is released and regrabbed.
2160+ * raw_spin_lock_irq(pool->lock) which is released and regrabbed.
21602161 */
21612162 static void process_one_work(struct worker *worker, struct work_struct *work)
21622163 __releases(&pool->lock)
@@ -2238,7 +2239,7 @@ __acquires(&pool->lock) · 75 unmodified lines
22382239 */
22392240 set_work_pool_and_clear_pending(work, pool->id);
22402241
2241− spin_unlock_irq(&pool->lock);
2242+ raw_spin_unlock_irq(&pool->lock);
22422243
22432244 lock_map_acquire(&pwq->wq->lockdep_map);
22442245 lock_map_acquire(&lockdep_map);
@@ -2293,7 +2294,7 @@ __acquires(&pool->lock) · 48 unmodified lines
22932294 */
22942295 cond_resched();
22952296
2296− spin_lock_irq(&pool->lock);
2297+ raw_spin_lock_irq(&pool->lock);
22972298
22982299 /* clear cpu intensive status */
22992300 if (unlikely(cpu_intensive))
@@ -2319,7 +2320,7 @@ __acquires(&pool->lock) · 19 unmodified lines
23192320 * fetches a work from the top and executes it.
23202321 *
23212322 * CONTEXT:
2322− * spin_lock_irq(pool->lock) which may be released and regrabbed
2323+ * raw_spin_lock_irq(pool->lock) which may be released and regrabbed
23232324 * multiple times.
23242325 */
23252326 static void process_scheduled_works(struct worker *worker)
@@ -2361,11 +2362,11 @@ static int worker_thread(void *__worker) · 35 unmodified lines
23612362 /* tell the scheduler that this is a workqueue worker */
23622363 set_pf_worker(true);
23632364 woke_up:
2364− spin_lock_irq(&pool->lock);
2365+ raw_spin_lock_irq(&pool->lock);
23652366
23662367 /* am I supposed to die? */
23672368 if (unlikely(worker->flags & WORKER_DIE)) {
2368− spin_unlock_irq(&pool->lock);
2369+ raw_spin_unlock_irq(&pool->lock);
23692370 WARN_ON_ONCE(!list_empty(&worker->entry));
23702371 set_pf_worker(false);
23712372
@@ -2431,7 +2432,7 @@ sleep: · 59 unmodified lines
24312432 */
24322433 worker_enter_idle(worker);
24332434 __set_current_state(TASK_IDLE);
2434− spin_unlock_irq(&pool->lock);
2435+ raw_spin_unlock_irq(&pool->lock);
24352436 schedule();
24362437 goto woke_up;
24372438 }
@@ -2485,7 +2486,7 @@ repeat: · 47 unmodified lines
24852486 should_stop = kthread_should_stop();
24862487
24872488 /* see whether any pwq is asking for help */
2488− spin_lock_irq(&wq_mayday_lock);
2489+ raw_spin_lock_irq(&wq_mayday_lock);
24892490
24902491 while (!list_empty(&wq->maydays)) {
24912492 struct pool_workqueue *pwq = list_first_entry(&wq->maydays,
@@ -2497,11 +2498,11 @@ repeat: · 5 unmodified lines
24972498 __set_current_state(TASK_RUNNING);
24982499 list_del_init(&pwq->mayday_node);
24992500
2500− spin_unlock_irq(&wq_mayday_lock);
2501+ raw_spin_unlock_irq(&wq_mayday_lock);
25012502
25022503 worker_attach_to_pool(rescuer, pool);
25032504
2504− spin_lock_irq(&pool->lock);
2505+ raw_spin_lock_irq(&pool->lock);
25052506
25062507 /*
25072508 * Slurp in all works issued via this workqueue and
@@ -2529,8 +2530,8 @@ repeat: · 21 unmodified lines
25292530 * being used to relieve memory pressure, don't
25302531 * incur MAYDAY_INTERVAL delay inbetween.
25312532 */
2532− if (need_to_create_worker(pool)) {
2533− spin_lock(&wq_mayday_lock);
2533+ if (pwq->nr_active && need_to_create_worker(pool)) {
2534+ raw_spin_lock(&wq_mayday_lock);
25342535 /*
25352536 * Queue iff we aren't racing destruction
25362537 * and somebody else hasn't queued it already.
@@ -2539,7 +2540,7 @@ repeat: · 2 unmodified lines
25392540 get_pwq(pwq);
25402541 list_add_tail(&pwq->mayday_node, &wq->maydays);
25412542 }
2542− spin_unlock(&wq_mayday_lock);
2543+ raw_spin_unlock(&wq_mayday_lock);
25432544 }
25442545 }
25452546
@@ -2557,14 +2558,14 @@ repeat: · 11 unmodified lines
25572558 if (need_more_worker(pool))
25582559 wake_up_worker(pool);
25592560
2560− spin_unlock_irq(&pool->lock);
2561+ raw_spin_unlock_irq(&pool->lock);
25612562
25622563 worker_detach_from_pool(rescuer);
25632564
2564− spin_lock_irq(&wq_mayday_lock);
2565+ raw_spin_lock_irq(&wq_mayday_lock);
25652566 }
25662567
2567− spin_unlock_irq(&wq_mayday_lock);
2568+ raw_spin_unlock_irq(&wq_mayday_lock);
25682569
25692570 if (should_stop) {
25702571 __set_current_state(TASK_RUNNING);
@@ -2644,7 +2645,7 @@ static void wq_barrier_func(struct work_struct *work) · 73 unmodified lines
26442645 * underneath us, so we can't reliably determine pwq from @target.
26452646 *
26462647 * CONTEXT:
2647− * spin_lock_irq(pool->lock).
2648+ * raw_spin_lock_irq(pool->lock).
26482649 */
26492650 static void insert_wq_barrier(struct pool_workqueue *pwq,
26502651 struct wq_barrier *barr,
@@ -2731,7 +2732,7 @@ static bool flush_workqueue_prep_pwqs(struct workqueue_struct *wq, · 80 unmodified lines
27312732 for_each_pwq(pwq, wq) {
27322733 struct worker_pool *pool = pwq->pool;
27332734
2734− spin_lock_irq(&pool->lock);
2735+ raw_spin_lock_irq(&pool->lock);
27352736
27362737 if (flush_color >= 0) {
27372738 WARN_ON_ONCE(pwq->flush_color != -1);
@@ -2748,7 +2749,7 @@ static bool flush_workqueue_prep_pwqs(struct workqueue_struct *wq, · 10 unmodified lines
27482749 pwq->work_color = work_color;
27492750 }
27502751
2751− spin_unlock_irq(&pool->lock);
2752+ raw_spin_unlock_irq(&pool->lock);
27522753 }
27532754
27542755 if (flush_color >= 0 && atomic_dec_and_test(&wq->nr_pwqs_to_flush))
@@ -2948,9 +2949,9 @@ reflush: · 193 unmodified lines
29482949 for_each_pwq(pwq, wq) {
29492950 bool drained;
29502951
2951− spin_lock_irq(&pwq->pool->lock);
2952+ raw_spin_lock_irq(&pwq->pool->lock);
29522953 drained = !pwq->nr_active && list_empty(&pwq->delayed_works);
2953− spin_unlock_irq(&pwq->pool->lock);
2954+ raw_spin_unlock_irq(&pwq->pool->lock);
29542955
29552956 if (drained)
29562957 continue;
@@ -2986,7 +2987,7 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr, · 29 unmodified lines
29862987 return false;
29872988 }
29882989
2989− spin_lock_irq(&pool->lock);
2990+ raw_spin_lock_irq(&pool->lock);
29902991 /* see the comment in try_to_grab_pending() with the same code */
29912992 pwq = get_work_pwq(work);
29922993 if (pwq) {
@@ -3002,7 +3003,7 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr, · 9 unmodified lines
30023003 check_flush_dependency(pwq->wq, work);
30033004
30043005 insert_wq_barrier(pwq, barr, work, worker);
3005− spin_unlock_irq(&pool->lock);
3006+ raw_spin_unlock_irq(&pool->lock);
30063007
30073008 /*
30083009 * Force a lock recursion deadlock when using flush_work() inside a
@@ -3021,7 +3022,7 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr, · 12 unmodified lines
30213022 rcu_read_unlock();
30223023 return true;
30233024 already_gone:
3024− spin_unlock_irq(&pool->lock);
3025+ raw_spin_unlock_irq(&pool->lock);
30253026 rcu_read_unlock();
30263027 return false;
30273028 }
@@ -3414,7 +3415,7 @@ static bool wqattrs_equal(const struct workqueue_attrs *a, · 386 unmodified lines
34143415 */
34153416 static int init_worker_pool(struct worker_pool *pool)
34163417 {
3417− spin_lock_init(&pool->lock);
3418+ raw_spin_lock_init(&pool->lock);
34183419 pool->id = -1;
34193420 pool->cpu = -1;
34203421 pool->node = NUMA_NO_NODE;
@@ -3491,7 +3492,6 @@ static void rcu_free_wq(struct rcu_head *rcu) · 70 unmodified lines
34913492 else
34923493 free_workqueue_attrs(wq->unbound_attrs);
34933494
3494− kfree(wq->rescuer);
34953495 kfree(wq);
34963496 }
34973497
@@ -3504,6 +3504,18 @@ static void rcu_free_pool(struct rcu_head *rcu) · 6 unmodified lines
35043504 kfree(pool);
35053505 }
35063506
3507+/* This returns with the lock held on success (pool manager is inactive). */
3508+static bool wq_manager_inactive(struct worker_pool *pool)
3509+{
3510+ raw_spin_lock_irq(&pool->lock);
3511+
3512+ if (pool->flags & POOL_MANAGER_ACTIVE) {
3513+ raw_spin_unlock_irq(&pool->lock);
3514+ return false;
3515+ }
3516+ return true;
3517+}
3518+
35073519 /**
35083520 * put_unbound_pool - put a worker_pool
35093521 * @pool: worker_pool to put
@@ -3539,16 +3551,17 @@ static void put_unbound_pool(struct worker_pool *pool) · 29 unmodified lines
35393551 * Become the manager and destroy all workers. This prevents
35403552 * @pool's workers from blocking on attach_mutex. We're the last
35413553 * manager and @pool gets freed with the flag set.
3554+ * Because of how wq_manager_inactive() works, we will hold the
3555+ * spinlock after a successful wait.
35423556 */
3543− spin_lock_irq(&pool->lock);
3544− wait_event_lock_irq(wq_manager_wait,
3545− !(pool->flags & POOL_MANAGER_ACTIVE), pool->lock);
3557+ rcuwait_wait_event(&manager_wait, wq_manager_inactive(pool),
3558+ TASK_UNINTERRUPTIBLE);
35463559 pool->flags |= POOL_MANAGER_ACTIVE;
35473560
35483561 while ((worker = first_idle_worker(pool)))
35493562 destroy_worker(worker);
35503563 WARN_ON(pool->nr_workers || pool->nr_idle);
3551− spin_unlock_irq(&pool->lock);
3564+ raw_spin_unlock_irq(&pool->lock);
35523565
35533566 mutex_lock(&wq_pool_attach_mutex);
35543567 if (!list_empty(&pool->workers))
@@ -3704,7 +3717,7 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq) · 149 unmodified lines
37043717 return;
37053718
37063719 /* this function can be called during early boot w/ irq disabled */
3707− spin_lock_irqsave(&pwq->pool->lock, flags);
3720+ raw_spin_lock_irqsave(&pwq->pool->lock, flags);
37083721
37093722 /*
37103723 * During [un]freezing, the caller is responsible for ensuring that
@@ -3727,7 +3740,7 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq) · 16 unmodified lines
37273740 pwq->max_active = 0;
37283741 }
37293742
3730− spin_unlock_irqrestore(&pwq->pool->lock, flags);
3743+ raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
37313744 }
37323745
37333746 /* initialize newly alloced @pwq which is associated with @wq and @pool */
@@ -4129,9 +4142,9 @@ static void wq_update_unbound_numa(struct workqueue_struct *wq, int cpu, · 395 unmodified lines
41294142
41304143 use_dfl_pwq:
41314144 mutex_lock(&wq->mutex);
4132− spin_lock_irq(&wq->dfl_pwq->pool->lock);
4145+ raw_spin_lock_irq(&wq->dfl_pwq->pool->lock);
41334146 get_pwq(wq->dfl_pwq);
4134− spin_unlock_irq(&wq->dfl_pwq->pool->lock);
4147+ raw_spin_unlock_irq(&wq->dfl_pwq->pool->lock);
41354148 old_pwq = numa_pwq_tbl_install(wq, node, wq->dfl_pwq);
41364149 out_unlock:
41374150 mutex_unlock(&wq->mutex);
@@ -4208,8 +4221,8 @@ static int init_rescuer(struct workqueue_struct *wq) · 70 unmodified lines
42084221
42094222 rescuer->rescue_wq = wq;
42104223 rescuer->task = kthread_create(rescuer_thread, rescuer, "%s", wq->name);
4211− ret = PTR_ERR_OR_ZERO(rescuer->task);
4212− if (ret) {
4224+ if (IS_ERR(rescuer->task)) {
4225+ ret = PTR_ERR(rescuer->task);
42134226 kfree(rescuer);
42144227 return ret;
42154228 }
@@ -4360,9 +4373,9 @@ void destroy_workqueue(struct workqueue_struct *wq) · 144 unmodified lines
43604373 struct worker *rescuer = wq->rescuer;
43614374
43624375 /* this prevents new queueing */
4363− spin_lock_irq(&wq_mayday_lock);
4376+ raw_spin_lock_irq(&wq_mayday_lock);
43644377 wq->rescuer = NULL;
4365− spin_unlock_irq(&wq_mayday_lock);
4378+ raw_spin_unlock_irq(&wq_mayday_lock);
43664379
43674380 /* rescuer will empty maydays list before exiting */
43684381 kthread_stop(rescuer->task);
@@ -4376,27 +4389,25 @@ void destroy_workqueue(struct workqueue_struct *wq) · 7 unmodified lines
43764389 mutex_lock(&wq_pool_mutex);
43774390 mutex_lock(&wq->mutex);
43784391 for_each_pwq(pwq, wq) {
4379− spin_lock_irq(&pwq->pool->lock);
4392+ raw_spin_lock_irq(&pwq->pool->lock);
43804393 if (WARN_ON(pwq_busy(pwq))) {
43814394 pr_warn("%s: %s has the following busy pwq\n",
43824395 __func__, wq->name);
43834396 show_pwq(pwq);
4384− spin_unlock_irq(&pwq->pool->lock);
4397+ raw_spin_unlock_irq(&pwq->pool->lock);
43854398 mutex_unlock(&wq->mutex);
43864399 mutex_unlock(&wq_pool_mutex);
43874400 show_workqueue_state();
43884401 return;
43894402 }
4390− spin_unlock_irq(&pwq->pool->lock);
4403+ raw_spin_unlock_irq(&pwq->pool->lock);
43914404 }
43924405 mutex_unlock(&wq->mutex);
4393− mutex_unlock(&wq_pool_mutex);
43944406
43954407 /*
43964408 * wq list is used to freeze wq, remove from list after
43974409 * flushing is complete in case freeze races us.
43984410 */
4399− mutex_lock(&wq_pool_mutex);
44004411 list_del_rcu(&wq->list);
44014412 mutex_unlock(&wq_pool_mutex);
44024413
@@ -4558,10 +4569,10 @@ unsigned int work_busy(struct work_struct *work) · 155 unmodified lines
45584569 rcu_read_lock();
45594570 pool = get_work_pool(work);
45604571 if (pool) {
4561− spin_lock_irqsave(&pool->lock, flags);
4572+ raw_spin_lock_irqsave(&pool->lock, flags);
45624573 if (find_worker_executing_work(pool, work))
45634574 ret |= WORK_BUSY_RUNNING;
4564− spin_unlock_irqrestore(&pool->lock, flags);
4575+ raw_spin_unlock_irqrestore(&pool->lock, flags);
45654576 }
45664577 rcu_read_unlock();
45674578
@@ -4768,10 +4779,10 @@ void show_workqueue_state(void) · 200 unmodified lines
47684779 pr_info("workqueue %s: flags=0x%x\n", wq->name, wq->flags);
47694780
47704781 for_each_pwq(pwq, wq) {
4771− spin_lock_irqsave(&pwq->pool->lock, flags);
4782+ raw_spin_lock_irqsave(&pwq->pool->lock, flags);
47724783 if (pwq->nr_active || !list_empty(&pwq->delayed_works))
47734784 show_pwq(pwq);
4774− spin_unlock_irqrestore(&pwq->pool->lock, flags);
4785+ raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
47754786 /*
47764787 * We could be printing a lot from atomic context, e.g.
47774788 * sysrq-t -> show_workqueue_state(). Avoid triggering
@@ -4785,7 +4796,7 @@ void show_workqueue_state(void) · 7 unmodified lines
47854796 struct worker *worker;
47864797 bool first = true;
47874798
4788− spin_lock_irqsave(&pool->lock, flags);
4799+ raw_spin_lock_irqsave(&pool->lock, flags);
47894800 if (pool->nr_workers == pool->nr_idle)
47904801 goto next_pool;
47914802
@@ -4804,7 +4815,7 @@ void show_workqueue_state(void) · 12 unmodified lines
48044815 }
48054816 pr_cont("\n");
48064817 next_pool:
4807− spin_unlock_irqrestore(&pool->lock, flags);
4818+ raw_spin_unlock_irqrestore(&pool->lock, flags);
48084819 /*
48094820 * We could be printing a lot from atomic context, e.g.
48104821 * sysrq-t -> show_workqueue_state(). Avoid triggering
@@ -4834,7 +4845,7 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task) · 23 unmodified lines
48344845 struct worker_pool *pool = worker->pool;
48354846
48364847 if (pool) {
4837− spin_lock_irq(&pool->lock);
4848+ raw_spin_lock_irq(&pool->lock);
48384849 /*
48394850 * ->desc tracks information (wq name or
48404851 * set_worker_desc()) for the latest execution. If
@@ -4848,7 +4859,7 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task) · 7 unmodified lines
48484859 scnprintf(buf + off, size - off, "-%s",
48494860 worker->desc);
48504861 }
4851− spin_unlock_irq(&pool->lock);
4862+ raw_spin_unlock_irq(&pool->lock);
48524863 }
48534864 }
48544865
@@ -4879,7 +4890,7 @@ static void unbind_workers(int cpu) · 24 unmodified lines
48794890
48804891 for_each_cpu_worker_pool(pool, cpu) {
48814892 mutex_lock(&wq_pool_attach_mutex);
4882− spin_lock_irq(&pool->lock);
4893+ raw_spin_lock_irq(&pool->lock);
48834894
48844895 /*
48854896 * We've blocked all attach/detach operations. Make all workers
@@ -4893,7 +4904,7 @@ static void unbind_workers(int cpu) · 7 unmodified lines
48934904
48944905 pool->flags |= POOL_DISASSOCIATED;
48954906
4896− spin_unlock_irq(&pool->lock);
4907+ raw_spin_unlock_irq(&pool->lock);
48974908 mutex_unlock(&wq_pool_attach_mutex);
48984909
48994910 /*
@@ -4919,9 +4930,9 @@ static void unbind_workers(int cpu) · 19 unmodified lines
49194930 * worker blocking could lead to lengthy stalls. Kick off
49204931 * unbound chain execution of currently pending work items.
49214932 */
4922− spin_lock_irq(&pool->lock);
4933+ raw_spin_lock_irq(&pool->lock);
49234934 wake_up_worker(pool);
4924− spin_unlock_irq(&pool->lock);
4935+ raw_spin_unlock_irq(&pool->lock);
49254936 }
49264937 }
49274938
@@ -4948,7 +4959,7 @@ static void rebind_workers(struct worker_pool *pool) · 20 unmodified lines
49484959 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
49494960 pool->attrs->cpumask) < 0);
49504961
4951− spin_lock_irq(&pool->lock);
4962+ raw_spin_lock_irq(&pool->lock);
49524963
49534964 pool->flags &= ~POOL_DISASSOCIATED;
49544965
@@ -4987,7 +4998,7 @@ static void rebind_workers(struct worker_pool *pool) · 32 unmodified lines
49874998 WRITE_ONCE(worker->flags, worker_flags);
49884999 }
49895000
4990− spin_unlock_irq(&pool->lock);
5001+ raw_spin_unlock_irq(&pool->lock);
49915002 }
49925003
49935004 /**
@@ -5906,7 +5917,7 @@ void __init workqueue_init_early(void) · 912 unmodified lines
59065917 int hk_flags = HK_FLAG_DOMAIN | HK_FLAG_WQ;
59075918 int i, cpu;
59085919
5909− WARN_ON(__alignof__(struct pool_workqueue) < __alignof__(long long));
5920+ BUILD_BUG_ON(__alignof__(struct pool_workqueue) < __alignof__(long long));
59105921
59115922 BUG_ON(!alloc_cpumask_var(&wq_unbound_cpumask, GFP_KERNEL));
59125923 cpumask_copy(wq_unbound_cpumask, housekeeping_cpumask(hk_flags));