hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
kernel/kernel/workqueue.c
....@@ -128,7 +128,7 @@
128128 *
129129 * PL: wq_pool_mutex protected.
130130 *
131
- * PR: wq_pool_mutex protected for writes. Sched-RCU protected for reads.
131
+ * PR: wq_pool_mutex protected for writes. RCU protected for reads.
132132 *
133133 * PW: wq_pool_mutex and wq->mutex protected for writes. Either for reads.
134134 *
....@@ -137,7 +137,7 @@
137137 *
138138 * WQ: wq->mutex protected.
139139 *
140
- * WR: wq->mutex protected for writes. Sched-RCU protected for reads.
140
+ * WR: wq->mutex protected for writes. RCU protected for reads.
141141 *
142142 * MD: wq_mayday_lock protected.
143143 */
....@@ -145,7 +145,7 @@
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 */
....@@ -184,7 +184,7 @@
184184 atomic_t nr_running ____cacheline_aligned_in_smp;
185185
186186 /*
187
- * Destruction of pool is sched-RCU protected to allow dereferences
187
+ * Destruction of pool is RCU protected to allow dereferences
188188 * from get_work_pool().
189189 */
190190 struct rcu_head rcu;
....@@ -213,7 +213,7 @@
213213 /*
214214 * Release of unbound pwq is punted to system_wq. See put_pwq()
215215 * and pwq_unbound_release_workfn() for details. pool_workqueue
216
- * itself is also sched-RCU protected so that the first pwq can be
216
+ * itself is also RCU protected so that the first pwq can be
217217 * determined without grabbing wq->mutex.
218218 */
219219 struct work_struct unbound_release_work;
....@@ -298,8 +298,8 @@
298298
299299 static DEFINE_MUTEX(wq_pool_mutex); /* protects pools and workqueues list */
300300 static DEFINE_MUTEX(wq_pool_attach_mutex); /* protects worker attach/detach */
301
-static DEFINE_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */
302
-static DECLARE_WAIT_QUEUE_HEAD(wq_manager_wait); /* wait for manager to go away */
301
+static DEFINE_RAW_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */
302
+static DECLARE_SWAIT_QUEUE_HEAD(wq_manager_wait); /* wait for manager to go away */
303303
304304 static LIST_HEAD(workqueues); /* PR: list of all workqueues */
305305 static bool workqueue_freezing; /* PL: have wqs started freezing? */
....@@ -358,20 +358,20 @@
358358 #include <trace/events/workqueue.h>
359359
360360 #define assert_rcu_or_pool_mutex() \
361
- RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
361
+ RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
362362 !lockdep_is_held(&wq_pool_mutex), \
363
- "sched RCU or wq_pool_mutex should be held")
363
+ "RCU or wq_pool_mutex should be held")
364364
365365 #define assert_rcu_or_wq_mutex(wq) \
366
- RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
366
+ RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
367367 !lockdep_is_held(&wq->mutex), \
368
- "sched RCU or wq->mutex should be held")
368
+ "RCU or wq->mutex should be held")
369369
370370 #define assert_rcu_or_wq_mutex_or_pool_mutex(wq) \
371
- RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
371
+ RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
372372 !lockdep_is_held(&wq->mutex) && \
373373 !lockdep_is_held(&wq_pool_mutex), \
374
- "sched RCU, wq->mutex or wq_pool_mutex should be held")
374
+ "RCU, wq->mutex or wq_pool_mutex should be held")
375375
376376 #define for_each_cpu_worker_pool(pool, cpu) \
377377 for ((pool) = &per_cpu(cpu_worker_pools, cpu)[0]; \
....@@ -383,7 +383,7 @@
383383 * @pool: iteration cursor
384384 * @pi: integer used for iteration
385385 *
386
- * This must be called either with wq_pool_mutex held or sched RCU read
386
+ * This must be called either with wq_pool_mutex held or RCU read
387387 * locked. If the pool needs to be used beyond the locking in effect, the
388388 * caller is responsible for guaranteeing that the pool stays online.
389389 *
....@@ -415,7 +415,7 @@
415415 * @pwq: iteration cursor
416416 * @wq: the target workqueue
417417 *
418
- * This must be called either with wq->mutex held or sched RCU read locked.
418
+ * This must be called either with wq->mutex held or RCU read locked.
419419 * If the pwq needs to be used beyond the locking in effect, the caller is
420420 * responsible for guaranteeing that the pwq stays online.
421421 *
....@@ -551,7 +551,7 @@
551551 * @wq: the target workqueue
552552 * @node: the node ID
553553 *
554
- * This must be called with any of wq_pool_mutex, wq->mutex or sched RCU
554
+ * This must be called with any of wq_pool_mutex, wq->mutex or RCU
555555 * read locked.
556556 * If the pwq needs to be used beyond the locking in effect, the caller is
557557 * responsible for guaranteeing that the pwq stays online.
....@@ -695,8 +695,8 @@
695695 * @work: the work item of interest
696696 *
697697 * Pools are created and destroyed under wq_pool_mutex, and allows read
698
- * access under sched-RCU read lock. As such, this function should be
699
- * called under wq_pool_mutex or with preemption disabled.
698
+ * access under RCU read lock. As such, this function should be
699
+ * called under wq_pool_mutex or inside of a rcu_read_lock() region.
700700 *
701701 * All fields of the returned pool are accessible as long as the above
702702 * mentioned locking is in effect. If the returned pool needs to be used
....@@ -829,7 +829,7 @@
829829 * Wake up the first idle worker of @pool.
830830 *
831831 * CONTEXT:
832
- * spin_lock_irq(pool->lock).
832
+ * raw_spin_lock_irq(pool->lock).
833833 */
834834 static void wake_up_worker(struct worker_pool *pool)
835835 {
....@@ -840,43 +840,32 @@
840840 }
841841
842842 /**
843
- * wq_worker_waking_up - a worker is waking up
843
+ * wq_worker_running - a worker is running again
844844 * @task: task waking up
845
- * @cpu: CPU @task is waking up to
846845 *
847
- * This function is called during try_to_wake_up() when a worker is
848
- * being awoken.
849
- *
850
- * CONTEXT:
851
- * spin_lock_irq(rq->lock)
846
+ * This function is called when a worker returns from schedule()
852847 */
853
-void wq_worker_waking_up(struct task_struct *task, int cpu)
848
+void wq_worker_running(struct task_struct *task)
854849 {
855850 struct worker *worker = kthread_data(task);
856851
857
- if (!(worker->flags & WORKER_NOT_RUNNING)) {
858
- WARN_ON_ONCE(worker->pool->cpu != cpu);
852
+ if (!worker->sleeping)
853
+ return;
854
+ if (!(worker->flags & WORKER_NOT_RUNNING))
859855 atomic_inc(&worker->pool->nr_running);
860
- }
856
+ worker->sleeping = 0;
861857 }
862858
863859 /**
864860 * wq_worker_sleeping - a worker is going to sleep
865861 * @task: task going to sleep
866862 *
867
- * This function is called during schedule() when a busy worker is
868
- * going to sleep. Worker on the same cpu can be woken up by
869
- * returning pointer to its task.
870
- *
871
- * CONTEXT:
872
- * spin_lock_irq(rq->lock)
873
- *
874
- * Return:
875
- * Worker task on @cpu to wake up, %NULL if none.
863
+ * This function is called from schedule() when a busy worker is
864
+ * going to sleep.
876865 */
877
-struct task_struct *wq_worker_sleeping(struct task_struct *task)
866
+void wq_worker_sleeping(struct task_struct *task)
878867 {
879
- struct worker *worker = kthread_data(task), *to_wakeup = NULL;
868
+ struct worker *next, *worker = kthread_data(task);
880869 struct worker_pool *pool;
881870
882871 /*
....@@ -885,13 +874,15 @@
885874 * checking NOT_RUNNING.
886875 */
887876 if (worker->flags & WORKER_NOT_RUNNING)
888
- return NULL;
877
+ return;
889878
890879 pool = worker->pool;
891880
892
- /* this can only happen on the local cpu */
893
- if (WARN_ON_ONCE(pool->cpu != raw_smp_processor_id()))
894
- return NULL;
881
+ if (WARN_ON_ONCE(worker->sleeping))
882
+ return;
883
+
884
+ worker->sleeping = 1;
885
+ raw_spin_lock_irq(&pool->lock);
895886
896887 /*
897888 * The counterpart of the following dec_and_test, implied mb,
....@@ -905,9 +896,12 @@
905896 * lock is safe.
906897 */
907898 if (atomic_dec_and_test(&pool->nr_running) &&
908
- !list_empty(&pool->worklist))
909
- to_wakeup = first_idle_worker(pool);
910
- return to_wakeup ? to_wakeup->task : NULL;
899
+ !list_empty(&pool->worklist)) {
900
+ next = first_idle_worker(pool);
901
+ if (next)
902
+ wake_up_process(next->task);
903
+ }
904
+ raw_spin_unlock_irq(&pool->lock);
911905 }
912906
913907 /**
....@@ -938,7 +932,7 @@
938932 * Set @flags in @worker->flags and adjust nr_running accordingly.
939933 *
940934 * CONTEXT:
941
- * spin_lock_irq(pool->lock)
935
+ * raw_spin_lock_irq(pool->lock)
942936 */
943937 static inline void worker_set_flags(struct worker *worker, unsigned int flags)
944938 {
....@@ -963,7 +957,7 @@
963957 * Clear @flags in @worker->flags and adjust nr_running accordingly.
964958 *
965959 * CONTEXT:
966
- * spin_lock_irq(pool->lock)
960
+ * raw_spin_lock_irq(pool->lock)
967961 */
968962 static inline void worker_clr_flags(struct worker *worker, unsigned int flags)
969963 {
....@@ -1011,7 +1005,7 @@
10111005 * actually occurs, it should be easy to locate the culprit work function.
10121006 *
10131007 * CONTEXT:
1014
- * spin_lock_irq(pool->lock).
1008
+ * raw_spin_lock_irq(pool->lock).
10151009 *
10161010 * Return:
10171011 * Pointer to worker which is executing @work if found, %NULL
....@@ -1046,7 +1040,7 @@
10461040 * nested inside outer list_for_each_entry_safe().
10471041 *
10481042 * CONTEXT:
1049
- * spin_lock_irq(pool->lock).
1043
+ * raw_spin_lock_irq(pool->lock).
10501044 */
10511045 static void move_linked_works(struct work_struct *work, struct list_head *head,
10521046 struct work_struct **nextp)
....@@ -1121,12 +1115,12 @@
11211115 {
11221116 if (pwq) {
11231117 /*
1124
- * As both pwqs and pools are sched-RCU protected, the
1118
+ * As both pwqs and pools are RCU protected, the
11251119 * following lock operations are safe.
11261120 */
1127
- spin_lock_irq(&pwq->pool->lock);
1121
+ raw_spin_lock_irq(&pwq->pool->lock);
11281122 put_pwq(pwq);
1129
- spin_unlock_irq(&pwq->pool->lock);
1123
+ raw_spin_unlock_irq(&pwq->pool->lock);
11301124 }
11311125 }
11321126
....@@ -1159,7 +1153,7 @@
11591153 * decrement nr_in_flight of its pwq and handle workqueue flushing.
11601154 *
11611155 * CONTEXT:
1162
- * spin_lock_irq(pool->lock).
1156
+ * raw_spin_lock_irq(pool->lock).
11631157 */
11641158 static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, int color)
11651159 {
....@@ -1249,6 +1243,7 @@
12491243 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)))
12501244 return 0;
12511245
1246
+ rcu_read_lock();
12521247 /*
12531248 * The queueing is in progress, or it is already queued. Try to
12541249 * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
....@@ -1257,7 +1252,7 @@
12571252 if (!pool)
12581253 goto fail;
12591254
1260
- spin_lock(&pool->lock);
1255
+ raw_spin_lock(&pool->lock);
12611256 /*
12621257 * work->data is guaranteed to point to pwq only while the work
12631258 * item is queued on pwq->wq, and both updating work->data to point
....@@ -1286,11 +1281,13 @@
12861281 /* work->data points to pwq iff queued, point to pool */
12871282 set_work_pool_and_keep_pending(work, pool->id);
12881283
1289
- spin_unlock(&pool->lock);
1284
+ raw_spin_unlock(&pool->lock);
1285
+ rcu_read_unlock();
12901286 return 1;
12911287 }
1292
- spin_unlock(&pool->lock);
1288
+ raw_spin_unlock(&pool->lock);
12931289 fail:
1290
+ rcu_read_unlock();
12941291 local_irq_restore(*flags);
12951292 if (work_is_canceling(work))
12961293 return -ENOENT;
....@@ -1309,7 +1306,7 @@
13091306 * work_struct flags.
13101307 *
13111308 * CONTEXT:
1312
- * spin_lock_irq(pool->lock).
1309
+ * raw_spin_lock_irq(pool->lock).
13131310 */
13141311 static void insert_work(struct pool_workqueue *pwq, struct work_struct *work,
13151312 struct list_head *head, unsigned int extra_flags)
....@@ -1403,6 +1400,7 @@
14031400 if (unlikely(wq->flags & __WQ_DRAINING) &&
14041401 WARN_ON_ONCE(!is_chained_work(wq)))
14051402 return;
1403
+ rcu_read_lock();
14061404 retry:
14071405 /* pwq which will be used unless @work is executing elsewhere */
14081406 if (wq->flags & WQ_UNBOUND) {
....@@ -1424,7 +1422,7 @@
14241422 if (last_pool && last_pool != pwq->pool) {
14251423 struct worker *worker;
14261424
1427
- spin_lock(&last_pool->lock);
1425
+ raw_spin_lock(&last_pool->lock);
14281426
14291427 worker = find_worker_executing_work(last_pool, work);
14301428
....@@ -1432,11 +1430,11 @@
14321430 pwq = worker->current_pwq;
14331431 } else {
14341432 /* meh... not running there, queue here */
1435
- spin_unlock(&last_pool->lock);
1436
- spin_lock(&pwq->pool->lock);
1433
+ raw_spin_unlock(&last_pool->lock);
1434
+ raw_spin_lock(&pwq->pool->lock);
14371435 }
14381436 } else {
1439
- spin_lock(&pwq->pool->lock);
1437
+ raw_spin_lock(&pwq->pool->lock);
14401438 }
14411439
14421440 /*
....@@ -1449,7 +1447,7 @@
14491447 */
14501448 if (unlikely(!pwq->refcnt)) {
14511449 if (wq->flags & WQ_UNBOUND) {
1452
- spin_unlock(&pwq->pool->lock);
1450
+ raw_spin_unlock(&pwq->pool->lock);
14531451 cpu_relax();
14541452 goto retry;
14551453 }
....@@ -1461,10 +1459,8 @@
14611459 /* pwq determined, queue */
14621460 trace_workqueue_queue_work(req_cpu, pwq, work);
14631461
1464
- if (WARN_ON(!list_empty(&work->entry))) {
1465
- spin_unlock(&pwq->pool->lock);
1466
- return;
1467
- }
1462
+ if (WARN_ON(!list_empty(&work->entry)))
1463
+ goto out;
14681464
14691465 pwq->nr_in_flight[pwq->work_color]++;
14701466 work_flags = work_color_to_flags(pwq->work_color);
....@@ -1483,7 +1479,9 @@
14831479 debug_work_activate(work);
14841480 insert_work(pwq, work, worklist, work_flags);
14851481
1486
- spin_unlock(&pwq->pool->lock);
1482
+out:
1483
+ raw_spin_unlock(&pwq->pool->lock);
1484
+ rcu_read_unlock();
14871485 }
14881486
14891487 /**
....@@ -1518,9 +1516,11 @@
15181516 void delayed_work_timer_fn(struct timer_list *t)
15191517 {
15201518 struct delayed_work *dwork = from_timer(dwork, t, timer);
1519
+ unsigned long flags;
15211520
1522
- /* should have been called from irqsafe timer with irq already off */
1521
+ local_irq_save(flags);
15231522 __queue_work(dwork->cpu, dwork->wq, &dwork->work);
1523
+ local_irq_restore(flags);
15241524 }
15251525 EXPORT_SYMBOL(delayed_work_timer_fn);
15261526
....@@ -1669,7 +1669,7 @@
16691669 * necessary.
16701670 *
16711671 * LOCKING:
1672
- * spin_lock_irq(pool->lock).
1672
+ * raw_spin_lock_irq(pool->lock).
16731673 */
16741674 static void worker_enter_idle(struct worker *worker)
16751675 {
....@@ -1709,7 +1709,7 @@
17091709 * @worker is leaving idle state. Update stats.
17101710 *
17111711 * LOCKING:
1712
- * spin_lock_irq(pool->lock).
1712
+ * raw_spin_lock_irq(pool->lock).
17131713 */
17141714 static void worker_leave_idle(struct worker *worker)
17151715 {
....@@ -1844,11 +1844,11 @@
18441844 worker_attach_to_pool(worker, pool);
18451845
18461846 /* start the newly created worker */
1847
- spin_lock_irq(&pool->lock);
1847
+ raw_spin_lock_irq(&pool->lock);
18481848 worker->pool->nr_workers++;
18491849 worker_enter_idle(worker);
18501850 wake_up_process(worker->task);
1851
- spin_unlock_irq(&pool->lock);
1851
+ raw_spin_unlock_irq(&pool->lock);
18521852
18531853 return worker;
18541854
....@@ -1867,7 +1867,7 @@
18671867 * be idle.
18681868 *
18691869 * CONTEXT:
1870
- * spin_lock_irq(pool->lock).
1870
+ * raw_spin_lock_irq(pool->lock).
18711871 */
18721872 static void destroy_worker(struct worker *worker)
18731873 {
....@@ -1893,7 +1893,7 @@
18931893 {
18941894 struct worker_pool *pool = from_timer(pool, t, idle_timer);
18951895
1896
- spin_lock_irq(&pool->lock);
1896
+ raw_spin_lock_irq(&pool->lock);
18971897
18981898 while (too_many_workers(pool)) {
18991899 struct worker *worker;
....@@ -1911,7 +1911,7 @@
19111911 destroy_worker(worker);
19121912 }
19131913
1914
- spin_unlock_irq(&pool->lock);
1914
+ raw_spin_unlock_irq(&pool->lock);
19151915 }
19161916
19171917 static void send_mayday(struct work_struct *work)
....@@ -1942,8 +1942,8 @@
19421942 struct worker_pool *pool = from_timer(pool, t, mayday_timer);
19431943 struct work_struct *work;
19441944
1945
- spin_lock_irq(&pool->lock);
1946
- spin_lock(&wq_mayday_lock); /* for wq->maydays */
1945
+ raw_spin_lock_irq(&pool->lock);
1946
+ raw_spin_lock(&wq_mayday_lock); /* for wq->maydays */
19471947
19481948 if (need_to_create_worker(pool)) {
19491949 /*
....@@ -1956,8 +1956,8 @@
19561956 send_mayday(work);
19571957 }
19581958
1959
- spin_unlock(&wq_mayday_lock);
1960
- spin_unlock_irq(&pool->lock);
1959
+ raw_spin_unlock(&wq_mayday_lock);
1960
+ raw_spin_unlock_irq(&pool->lock);
19611961
19621962 mod_timer(&pool->mayday_timer, jiffies + MAYDAY_INTERVAL);
19631963 }
....@@ -1976,7 +1976,7 @@
19761976 * may_start_working() %true.
19771977 *
19781978 * LOCKING:
1979
- * spin_lock_irq(pool->lock) which may be released and regrabbed
1979
+ * raw_spin_lock_irq(pool->lock) which may be released and regrabbed
19801980 * multiple times. Does GFP_KERNEL allocations. Called only from
19811981 * manager.
19821982 */
....@@ -1985,7 +1985,7 @@
19851985 __acquires(&pool->lock)
19861986 {
19871987 restart:
1988
- spin_unlock_irq(&pool->lock);
1988
+ raw_spin_unlock_irq(&pool->lock);
19891989
19901990 /* if we don't make progress in MAYDAY_INITIAL_TIMEOUT, call for help */
19911991 mod_timer(&pool->mayday_timer, jiffies + MAYDAY_INITIAL_TIMEOUT);
....@@ -2001,7 +2001,7 @@
20012001 }
20022002
20032003 del_timer_sync(&pool->mayday_timer);
2004
- spin_lock_irq(&pool->lock);
2004
+ raw_spin_lock_irq(&pool->lock);
20052005 /*
20062006 * This is necessary even after a new worker was just successfully
20072007 * created as @pool->lock was dropped and the new worker might have
....@@ -2024,7 +2024,7 @@
20242024 * and may_start_working() is true.
20252025 *
20262026 * CONTEXT:
2027
- * spin_lock_irq(pool->lock) which may be released and regrabbed
2027
+ * raw_spin_lock_irq(pool->lock) which may be released and regrabbed
20282028 * multiple times. Does GFP_KERNEL allocations.
20292029 *
20302030 * Return:
....@@ -2047,7 +2047,7 @@
20472047
20482048 pool->manager = NULL;
20492049 pool->flags &= ~POOL_MANAGER_ACTIVE;
2050
- wake_up(&wq_manager_wait);
2050
+ swake_up_one(&wq_manager_wait);
20512051 return true;
20522052 }
20532053
....@@ -2063,7 +2063,7 @@
20632063 * call this function to process a work.
20642064 *
20652065 * CONTEXT:
2066
- * spin_lock_irq(pool->lock) which is released and regrabbed.
2066
+ * raw_spin_lock_irq(pool->lock) which is released and regrabbed.
20672067 */
20682068 static void process_one_work(struct worker *worker, struct work_struct *work)
20692069 __releases(&pool->lock)
....@@ -2145,7 +2145,7 @@
21452145 */
21462146 set_work_pool_and_clear_pending(work, pool->id);
21472147
2148
- spin_unlock_irq(&pool->lock);
2148
+ raw_spin_unlock_irq(&pool->lock);
21492149
21502150 lock_map_acquire(&pwq->wq->lockdep_map);
21512151 lock_map_acquire(&lockdep_map);
....@@ -2200,7 +2200,7 @@
22002200 */
22012201 cond_resched();
22022202
2203
- spin_lock_irq(&pool->lock);
2203
+ raw_spin_lock_irq(&pool->lock);
22042204
22052205 /* clear cpu intensive status */
22062206 if (unlikely(cpu_intensive))
....@@ -2226,7 +2226,7 @@
22262226 * fetches a work from the top and executes it.
22272227 *
22282228 * CONTEXT:
2229
- * spin_lock_irq(pool->lock) which may be released and regrabbed
2229
+ * raw_spin_lock_irq(pool->lock) which may be released and regrabbed
22302230 * multiple times.
22312231 */
22322232 static void process_scheduled_works(struct worker *worker)
....@@ -2268,11 +2268,11 @@
22682268 /* tell the scheduler that this is a workqueue worker */
22692269 set_pf_worker(true);
22702270 woke_up:
2271
- spin_lock_irq(&pool->lock);
2271
+ raw_spin_lock_irq(&pool->lock);
22722272
22732273 /* am I supposed to die? */
22742274 if (unlikely(worker->flags & WORKER_DIE)) {
2275
- spin_unlock_irq(&pool->lock);
2275
+ raw_spin_unlock_irq(&pool->lock);
22762276 WARN_ON_ONCE(!list_empty(&worker->entry));
22772277 set_pf_worker(false);
22782278
....@@ -2338,7 +2338,7 @@
23382338 */
23392339 worker_enter_idle(worker);
23402340 __set_current_state(TASK_IDLE);
2341
- spin_unlock_irq(&pool->lock);
2341
+ raw_spin_unlock_irq(&pool->lock);
23422342 schedule();
23432343 goto woke_up;
23442344 }
....@@ -2392,7 +2392,7 @@
23922392 should_stop = kthread_should_stop();
23932393
23942394 /* see whether any pwq is asking for help */
2395
- spin_lock_irq(&wq_mayday_lock);
2395
+ raw_spin_lock_irq(&wq_mayday_lock);
23962396
23972397 while (!list_empty(&wq->maydays)) {
23982398 struct pool_workqueue *pwq = list_first_entry(&wq->maydays,
....@@ -2404,11 +2404,11 @@
24042404 __set_current_state(TASK_RUNNING);
24052405 list_del_init(&pwq->mayday_node);
24062406
2407
- spin_unlock_irq(&wq_mayday_lock);
2407
+ raw_spin_unlock_irq(&wq_mayday_lock);
24082408
24092409 worker_attach_to_pool(rescuer, pool);
24102410
2411
- spin_lock_irq(&pool->lock);
2411
+ raw_spin_lock_irq(&pool->lock);
24122412
24132413 /*
24142414 * Slurp in all works issued via this workqueue and
....@@ -2437,7 +2437,7 @@
24372437 * incur MAYDAY_INTERVAL delay inbetween.
24382438 */
24392439 if (need_to_create_worker(pool)) {
2440
- spin_lock(&wq_mayday_lock);
2440
+ raw_spin_lock(&wq_mayday_lock);
24412441 /*
24422442 * Queue iff we aren't racing destruction
24432443 * and somebody else hasn't queued it already.
....@@ -2446,7 +2446,7 @@
24462446 get_pwq(pwq);
24472447 list_add_tail(&pwq->mayday_node, &wq->maydays);
24482448 }
2449
- spin_unlock(&wq_mayday_lock);
2449
+ raw_spin_unlock(&wq_mayday_lock);
24502450 }
24512451 }
24522452
....@@ -2464,14 +2464,14 @@
24642464 if (need_more_worker(pool))
24652465 wake_up_worker(pool);
24662466
2467
- spin_unlock_irq(&pool->lock);
2467
+ raw_spin_unlock_irq(&pool->lock);
24682468
24692469 worker_detach_from_pool(rescuer);
24702470
2471
- spin_lock_irq(&wq_mayday_lock);
2471
+ raw_spin_lock_irq(&wq_mayday_lock);
24722472 }
24732473
2474
- spin_unlock_irq(&wq_mayday_lock);
2474
+ raw_spin_unlock_irq(&wq_mayday_lock);
24752475
24762476 if (should_stop) {
24772477 __set_current_state(TASK_RUNNING);
....@@ -2551,7 +2551,7 @@
25512551 * underneath us, so we can't reliably determine pwq from @target.
25522552 *
25532553 * CONTEXT:
2554
- * spin_lock_irq(pool->lock).
2554
+ * raw_spin_lock_irq(pool->lock).
25552555 */
25562556 static void insert_wq_barrier(struct pool_workqueue *pwq,
25572557 struct wq_barrier *barr,
....@@ -2638,7 +2638,7 @@
26382638 for_each_pwq(pwq, wq) {
26392639 struct worker_pool *pool = pwq->pool;
26402640
2641
- spin_lock_irq(&pool->lock);
2641
+ raw_spin_lock_irq(&pool->lock);
26422642
26432643 if (flush_color >= 0) {
26442644 WARN_ON_ONCE(pwq->flush_color != -1);
....@@ -2655,7 +2655,7 @@
26552655 pwq->work_color = work_color;
26562656 }
26572657
2658
- spin_unlock_irq(&pool->lock);
2658
+ raw_spin_unlock_irq(&pool->lock);
26592659 }
26602660
26612661 if (flush_color >= 0 && atomic_dec_and_test(&wq->nr_pwqs_to_flush))
....@@ -2855,9 +2855,9 @@
28552855 for_each_pwq(pwq, wq) {
28562856 bool drained;
28572857
2858
- spin_lock_irq(&pwq->pool->lock);
2858
+ raw_spin_lock_irq(&pwq->pool->lock);
28592859 drained = !pwq->nr_active && list_empty(&pwq->delayed_works);
2860
- spin_unlock_irq(&pwq->pool->lock);
2860
+ raw_spin_unlock_irq(&pwq->pool->lock);
28612861
28622862 if (drained)
28632863 continue;
....@@ -2886,14 +2886,14 @@
28862886
28872887 might_sleep();
28882888
2889
- local_irq_disable();
2889
+ rcu_read_lock();
28902890 pool = get_work_pool(work);
28912891 if (!pool) {
2892
- local_irq_enable();
2892
+ rcu_read_unlock();
28932893 return false;
28942894 }
28952895
2896
- spin_lock(&pool->lock);
2896
+ raw_spin_lock_irq(&pool->lock);
28972897 /* see the comment in try_to_grab_pending() with the same code */
28982898 pwq = get_work_pwq(work);
28992899 if (pwq) {
....@@ -2909,7 +2909,7 @@
29092909 check_flush_dependency(pwq->wq, work);
29102910
29112911 insert_wq_barrier(pwq, barr, work, worker);
2912
- spin_unlock_irq(&pool->lock);
2912
+ raw_spin_unlock_irq(&pool->lock);
29132913
29142914 /*
29152915 * Force a lock recursion deadlock when using flush_work() inside a
....@@ -2925,10 +2925,11 @@
29252925 lock_map_acquire(&pwq->wq->lockdep_map);
29262926 lock_map_release(&pwq->wq->lockdep_map);
29272927 }
2928
-
2928
+ rcu_read_unlock();
29292929 return true;
29302930 already_gone:
2931
- spin_unlock_irq(&pool->lock);
2931
+ raw_spin_unlock_irq(&pool->lock);
2932
+ rcu_read_unlock();
29322933 return false;
29332934 }
29342935
....@@ -3240,7 +3241,7 @@
32403241 *
32413242 * Undo alloc_workqueue_attrs().
32423243 */
3243
-void free_workqueue_attrs(struct workqueue_attrs *attrs)
3244
+static void free_workqueue_attrs(struct workqueue_attrs *attrs)
32443245 {
32453246 if (attrs) {
32463247 free_cpumask_var(attrs->cpumask);
....@@ -3250,21 +3251,20 @@
32503251
32513252 /**
32523253 * alloc_workqueue_attrs - allocate a workqueue_attrs
3253
- * @gfp_mask: allocation mask to use
32543254 *
32553255 * Allocate a new workqueue_attrs, initialize with default settings and
32563256 * return it.
32573257 *
32583258 * Return: The allocated new workqueue_attr on success. %NULL on failure.
32593259 */
3260
-struct workqueue_attrs *alloc_workqueue_attrs(gfp_t gfp_mask)
3260
+static struct workqueue_attrs *alloc_workqueue_attrs(void)
32613261 {
32623262 struct workqueue_attrs *attrs;
32633263
3264
- attrs = kzalloc(sizeof(*attrs), gfp_mask);
3264
+ attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
32653265 if (!attrs)
32663266 goto fail;
3267
- if (!alloc_cpumask_var(&attrs->cpumask, gfp_mask))
3267
+ if (!alloc_cpumask_var(&attrs->cpumask, GFP_KERNEL))
32683268 goto fail;
32693269
32703270 cpumask_copy(attrs->cpumask, cpu_possible_mask);
....@@ -3321,7 +3321,7 @@
33213321 */
33223322 static int init_worker_pool(struct worker_pool *pool)
33233323 {
3324
- spin_lock_init(&pool->lock);
3324
+ raw_spin_lock_init(&pool->lock);
33253325 pool->id = -1;
33263326 pool->cpu = -1;
33273327 pool->node = NUMA_NO_NODE;
....@@ -3342,7 +3342,7 @@
33423342 pool->refcnt = 1;
33433343
33443344 /* shouldn't fail above this point */
3345
- pool->attrs = alloc_workqueue_attrs(GFP_KERNEL);
3345
+ pool->attrs = alloc_workqueue_attrs();
33463346 if (!pool->attrs)
33473347 return -ENOMEM;
33483348 return 0;
....@@ -3375,7 +3375,7 @@
33753375 * put_unbound_pool - put a worker_pool
33763376 * @pool: worker_pool to put
33773377 *
3378
- * Put @pool. If its refcnt reaches zero, it gets destroyed in sched-RCU
3378
+ * Put @pool. If its refcnt reaches zero, it gets destroyed in RCU
33793379 * safe manner. get_unbound_pool() calls this function on its failure path
33803380 * and this function should be able to release pools which went through,
33813381 * successfully or not, init_worker_pool().
....@@ -3407,15 +3407,15 @@
34073407 * @pool's workers from blocking on attach_mutex. We're the last
34083408 * manager and @pool gets freed with the flag set.
34093409 */
3410
- spin_lock_irq(&pool->lock);
3411
- wait_event_lock_irq(wq_manager_wait,
3410
+ raw_spin_lock_irq(&pool->lock);
3411
+ swait_event_lock_irq(wq_manager_wait,
34123412 !(pool->flags & POOL_MANAGER_ACTIVE), pool->lock);
34133413 pool->flags |= POOL_MANAGER_ACTIVE;
34143414
34153415 while ((worker = first_idle_worker(pool)))
34163416 destroy_worker(worker);
34173417 WARN_ON(pool->nr_workers || pool->nr_idle);
3418
- spin_unlock_irq(&pool->lock);
3418
+ raw_spin_unlock_irq(&pool->lock);
34193419
34203420 mutex_lock(&wq_pool_attach_mutex);
34213421 if (!list_empty(&pool->workers))
....@@ -3429,8 +3429,8 @@
34293429 del_timer_sync(&pool->idle_timer);
34303430 del_timer_sync(&pool->mayday_timer);
34313431
3432
- /* sched-RCU protected to allow dereferences from get_work_pool() */
3433
- call_rcu_sched(&pool->rcu, rcu_free_pool);
3432
+ /* RCU protected to allow dereferences from get_work_pool() */
3433
+ call_rcu(&pool->rcu, rcu_free_pool);
34343434 }
34353435
34363436 /**
....@@ -3543,14 +3543,14 @@
35433543 put_unbound_pool(pool);
35443544 mutex_unlock(&wq_pool_mutex);
35453545
3546
- call_rcu_sched(&pwq->rcu, rcu_free_pwq);
3546
+ call_rcu(&pwq->rcu, rcu_free_pwq);
35473547
35483548 /*
35493549 * If we're the last pwq going away, @wq is already dead and no one
35503550 * is gonna access it anymore. Schedule RCU free.
35513551 */
35523552 if (is_last)
3553
- call_rcu_sched(&wq->rcu, rcu_free_wq);
3553
+ call_rcu(&wq->rcu, rcu_free_wq);
35543554 }
35553555
35563556 /**
....@@ -3575,7 +3575,7 @@
35753575 return;
35763576
35773577 /* this function can be called during early boot w/ irq disabled */
3578
- spin_lock_irqsave(&pwq->pool->lock, flags);
3578
+ raw_spin_lock_irqsave(&pwq->pool->lock, flags);
35793579
35803580 /*
35813581 * During [un]freezing, the caller is responsible for ensuring that
....@@ -3605,7 +3605,7 @@
36053605 pwq->max_active = 0;
36063606 }
36073607
3608
- spin_unlock_irqrestore(&pwq->pool->lock, flags);
3608
+ raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
36093609 }
36103610
36113611 /* initialize newly alloced @pwq which is associated with @wq and @pool */
....@@ -3778,8 +3778,8 @@
37783778
37793779 ctx = kzalloc(struct_size(ctx, pwq_tbl, nr_node_ids), GFP_KERNEL);
37803780
3781
- new_attrs = alloc_workqueue_attrs(GFP_KERNEL);
3782
- tmp_attrs = alloc_workqueue_attrs(GFP_KERNEL);
3781
+ new_attrs = alloc_workqueue_attrs();
3782
+ tmp_attrs = alloc_workqueue_attrs();
37833783 if (!ctx || !new_attrs || !tmp_attrs)
37843784 goto out_free;
37853785
....@@ -3915,7 +3915,7 @@
39153915 *
39163916 * Return: 0 on success and -errno on failure.
39173917 */
3918
-int apply_workqueue_attrs(struct workqueue_struct *wq,
3918
+static int apply_workqueue_attrs(struct workqueue_struct *wq,
39193919 const struct workqueue_attrs *attrs)
39203920 {
39213921 int ret;
....@@ -3926,7 +3926,6 @@
39263926
39273927 return ret;
39283928 }
3929
-EXPORT_SYMBOL_GPL(apply_workqueue_attrs);
39303929
39313930 /**
39323931 * wq_update_unbound_numa - update NUMA affinity of a wq for CPU hot[un]plug
....@@ -4004,9 +4003,9 @@
40044003
40054004 use_dfl_pwq:
40064005 mutex_lock(&wq->mutex);
4007
- spin_lock_irq(&wq->dfl_pwq->pool->lock);
4006
+ raw_spin_lock_irq(&wq->dfl_pwq->pool->lock);
40084007 get_pwq(wq->dfl_pwq);
4009
- spin_unlock_irq(&wq->dfl_pwq->pool->lock);
4008
+ raw_spin_unlock_irq(&wq->dfl_pwq->pool->lock);
40104009 old_pwq = numa_pwq_tbl_install(wq, node, wq->dfl_pwq);
40114010 out_unlock:
40124011 mutex_unlock(&wq->mutex);
....@@ -4125,7 +4124,7 @@
41254124 return NULL;
41264125
41274126 if (flags & WQ_UNBOUND) {
4128
- wq->unbound_attrs = alloc_workqueue_attrs(GFP_KERNEL);
4127
+ wq->unbound_attrs = alloc_workqueue_attrs();
41294128 if (!wq->unbound_attrs)
41304129 goto err_free_wq;
41314130 }
....@@ -4212,9 +4211,9 @@
42124211 struct worker *rescuer = wq->rescuer;
42134212
42144213 /* this prevents new queueing */
4215
- spin_lock_irq(&wq_mayday_lock);
4214
+ raw_spin_lock_irq(&wq_mayday_lock);
42164215 wq->rescuer = NULL;
4217
- spin_unlock_irq(&wq_mayday_lock);
4216
+ raw_spin_unlock_irq(&wq_mayday_lock);
42184217
42194218 /* rescuer will empty maydays list before exiting */
42204219 kthread_stop(rescuer->task);
....@@ -4257,7 +4256,7 @@
42574256 * The base ref is never dropped on per-cpu pwqs. Directly
42584257 * schedule RCU free.
42594258 */
4260
- call_rcu_sched(&wq->rcu, rcu_free_wq);
4259
+ call_rcu(&wq->rcu, rcu_free_wq);
42614260 } else {
42624261 /*
42634262 * We're the sole accessor of @wq at this point. Directly
....@@ -4367,7 +4366,8 @@
43674366 struct pool_workqueue *pwq;
43684367 bool ret;
43694368
4370
- rcu_read_lock_sched();
4369
+ rcu_read_lock();
4370
+ preempt_disable();
43714371
43724372 if (cpu == WORK_CPU_UNBOUND)
43734373 cpu = smp_processor_id();
....@@ -4378,7 +4378,8 @@
43784378 pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
43794379
43804380 ret = !list_empty(&pwq->delayed_works);
4381
- rcu_read_unlock_sched();
4381
+ preempt_enable();
4382
+ rcu_read_unlock();
43824383
43834384 return ret;
43844385 }
....@@ -4404,15 +4405,15 @@
44044405 if (work_pending(work))
44054406 ret |= WORK_BUSY_PENDING;
44064407
4407
- local_irq_save(flags);
4408
+ rcu_read_lock();
44084409 pool = get_work_pool(work);
44094410 if (pool) {
4410
- spin_lock(&pool->lock);
4411
+ raw_spin_lock_irqsave(&pool->lock, flags);
44114412 if (find_worker_executing_work(pool, work))
44124413 ret |= WORK_BUSY_RUNNING;
4413
- spin_unlock(&pool->lock);
4414
+ raw_spin_unlock_irqrestore(&pool->lock, flags);
44144415 }
4415
- local_irq_restore(flags);
4416
+ rcu_read_unlock();
44164417
44174418 return ret;
44184419 }
....@@ -4597,7 +4598,7 @@
45974598 unsigned long flags;
45984599 int pi;
45994600
4600
- rcu_read_lock_sched();
4601
+ rcu_read_lock();
46014602
46024603 pr_info("Showing busy workqueues and worker pools:\n");
46034604
....@@ -4617,10 +4618,10 @@
46174618 pr_info("workqueue %s: flags=0x%x\n", wq->name, wq->flags);
46184619
46194620 for_each_pwq(pwq, wq) {
4620
- spin_lock_irqsave(&pwq->pool->lock, flags);
4621
+ raw_spin_lock_irqsave(&pwq->pool->lock, flags);
46214622 if (pwq->nr_active || !list_empty(&pwq->delayed_works))
46224623 show_pwq(pwq);
4623
- spin_unlock_irqrestore(&pwq->pool->lock, flags);
4624
+ raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
46244625 /*
46254626 * We could be printing a lot from atomic context, e.g.
46264627 * sysrq-t -> show_workqueue_state(). Avoid triggering
....@@ -4634,7 +4635,7 @@
46344635 struct worker *worker;
46354636 bool first = true;
46364637
4637
- spin_lock_irqsave(&pool->lock, flags);
4638
+ raw_spin_lock_irqsave(&pool->lock, flags);
46384639 if (pool->nr_workers == pool->nr_idle)
46394640 goto next_pool;
46404641
....@@ -4653,7 +4654,7 @@
46534654 }
46544655 pr_cont("\n");
46554656 next_pool:
4656
- spin_unlock_irqrestore(&pool->lock, flags);
4657
+ raw_spin_unlock_irqrestore(&pool->lock, flags);
46574658 /*
46584659 * We could be printing a lot from atomic context, e.g.
46594660 * sysrq-t -> show_workqueue_state(). Avoid triggering
....@@ -4662,7 +4663,7 @@
46624663 touch_nmi_watchdog();
46634664 }
46644665
4665
- rcu_read_unlock_sched();
4666
+ rcu_read_unlock();
46664667 }
46674668
46684669 /* used to show worker information through /proc/PID/{comm,stat,status} */
....@@ -4683,7 +4684,7 @@
46834684 struct worker_pool *pool = worker->pool;
46844685
46854686 if (pool) {
4686
- spin_lock_irq(&pool->lock);
4687
+ raw_spin_lock_irq(&pool->lock);
46874688 /*
46884689 * ->desc tracks information (wq name or
46894690 * set_worker_desc()) for the latest execution. If
....@@ -4697,7 +4698,7 @@
46974698 scnprintf(buf + off, size - off, "-%s",
46984699 worker->desc);
46994700 }
4700
- spin_unlock_irq(&pool->lock);
4701
+ raw_spin_unlock_irq(&pool->lock);
47014702 }
47024703 }
47034704
....@@ -4728,7 +4729,7 @@
47284729
47294730 for_each_cpu_worker_pool(pool, cpu) {
47304731 mutex_lock(&wq_pool_attach_mutex);
4731
- spin_lock_irq(&pool->lock);
4732
+ raw_spin_lock_irq(&pool->lock);
47324733
47334734 /*
47344735 * We've blocked all attach/detach operations. Make all workers
....@@ -4742,7 +4743,7 @@
47424743
47434744 pool->flags |= POOL_DISASSOCIATED;
47444745
4745
- spin_unlock_irq(&pool->lock);
4746
+ raw_spin_unlock_irq(&pool->lock);
47464747 mutex_unlock(&wq_pool_attach_mutex);
47474748
47484749 /*
....@@ -4768,9 +4769,9 @@
47684769 * worker blocking could lead to lengthy stalls. Kick off
47694770 * unbound chain execution of currently pending work items.
47704771 */
4771
- spin_lock_irq(&pool->lock);
4772
+ raw_spin_lock_irq(&pool->lock);
47724773 wake_up_worker(pool);
4773
- spin_unlock_irq(&pool->lock);
4774
+ raw_spin_unlock_irq(&pool->lock);
47744775 }
47754776 }
47764777
....@@ -4797,7 +4798,7 @@
47974798 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
47984799 pool->attrs->cpumask) < 0);
47994800
4800
- spin_lock_irq(&pool->lock);
4801
+ raw_spin_lock_irq(&pool->lock);
48014802
48024803 pool->flags &= ~POOL_DISASSOCIATED;
48034804
....@@ -4836,7 +4837,7 @@
48364837 WRITE_ONCE(worker->flags, worker_flags);
48374838 }
48384839
4839
- spin_unlock_irq(&pool->lock);
4840
+ raw_spin_unlock_irq(&pool->lock);
48404841 }
48414842
48424843 /**
....@@ -5049,16 +5050,16 @@
50495050 * nr_active is monotonically decreasing. It's safe
50505051 * to peek without lock.
50515052 */
5052
- rcu_read_lock_sched();
5053
+ rcu_read_lock();
50535054 for_each_pwq(pwq, wq) {
50545055 WARN_ON_ONCE(pwq->nr_active < 0);
50555056 if (pwq->nr_active) {
50565057 busy = true;
5057
- rcu_read_unlock_sched();
5058
+ rcu_read_unlock();
50585059 goto out_unlock;
50595060 }
50605061 }
5061
- rcu_read_unlock_sched();
5062
+ rcu_read_unlock();
50625063 }
50635064 out_unlock:
50645065 mutex_unlock(&wq_pool_mutex);
....@@ -5260,7 +5261,8 @@
52605261 const char *delim = "";
52615262 int node, written = 0;
52625263
5263
- rcu_read_lock_sched();
5264
+ get_online_cpus();
5265
+ rcu_read_lock();
52645266 for_each_node(node) {
52655267 written += scnprintf(buf + written, PAGE_SIZE - written,
52665268 "%s%d:%d", delim, node,
....@@ -5268,7 +5270,8 @@
52685270 delim = " ";
52695271 }
52705272 written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
5271
- rcu_read_unlock_sched();
5273
+ rcu_read_unlock();
5274
+ put_online_cpus();
52725275
52735276 return written;
52745277 }
....@@ -5293,7 +5296,7 @@
52935296
52945297 lockdep_assert_held(&wq_pool_mutex);
52955298
5296
- attrs = alloc_workqueue_attrs(GFP_KERNEL);
5299
+ attrs = alloc_workqueue_attrs();
52975300 if (!attrs)
52985301 return NULL;
52995302
....@@ -5722,7 +5725,7 @@
57225725 return;
57235726 }
57245727
5725
- wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs(GFP_KERNEL);
5728
+ wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs();
57265729 BUG_ON(!wq_update_unbound_numa_attrs_buf);
57275730
57285731 /*
....@@ -5797,7 +5800,7 @@
57975800 for (i = 0; i < NR_STD_WORKER_POOLS; i++) {
57985801 struct workqueue_attrs *attrs;
57995802
5800
- BUG_ON(!(attrs = alloc_workqueue_attrs(GFP_KERNEL)));
5803
+ BUG_ON(!(attrs = alloc_workqueue_attrs()));
58015804 attrs->nice = std_nice[i];
58025805 unbound_std_wq_attrs[i] = attrs;
58035806
....@@ -5806,7 +5809,7 @@
58065809 * guaranteed by max_active which is enforced by pwqs.
58075810 * Turn off NUMA so that dfl_pwq is used for all nodes.
58085811 */
5809
- BUG_ON(!(attrs = alloc_workqueue_attrs(GFP_KERNEL)));
5812
+ BUG_ON(!(attrs = alloc_workqueue_attrs()));
58105813 attrs->nice = std_nice[i];
58115814 attrs->no_numa = true;
58125815 ordered_wq_attrs[i] = attrs;