@@ -236,10 +236,12 @@ static void blk_delay_work(struct work_struct *work)
236236 * Description:
237237 * Sometimes queueing needs to be postponed for a little while, to allow
238238 * resources to come back. This function will make sure that queueing is
239- * restarted around the specified time. Queue lock must be held.
239+ * restarted around the specified time.
240240 */
241241void blk_delay_queue (struct request_queue * q , unsigned long msecs )
242242{
243+ lockdep_assert_held (q -> queue_lock );
244+
243245 if (likely (!blk_queue_dead (q )))
244246 queue_delayed_work (kblockd_workqueue , & q -> delay_work ,
245247 msecs_to_jiffies (msecs ));
@@ -257,6 +259,8 @@ EXPORT_SYMBOL(blk_delay_queue);
257259 **/
258260void blk_start_queue_async (struct request_queue * q )
259261{
262+ lockdep_assert_held (q -> queue_lock );
263+
260264 queue_flag_clear (QUEUE_FLAG_STOPPED , q );
261265 blk_run_queue_async (q );
262266}
@@ -269,10 +273,11 @@ EXPORT_SYMBOL(blk_start_queue_async);
269273 * Description:
270274 * blk_start_queue() will clear the stop flag on the queue, and call
271275 * the request_fn for the queue if it was in a stopped state when
272- * entered. Also see blk_stop_queue(). Queue lock must be held.
276+ * entered. Also see blk_stop_queue().
273277 **/
274278void blk_start_queue (struct request_queue * q )
275279{
280+ lockdep_assert_held (q -> queue_lock );
276281 WARN_ON (!irqs_disabled ());
277282
278283 queue_flag_clear (QUEUE_FLAG_STOPPED , q );
@@ -292,10 +297,12 @@ EXPORT_SYMBOL(blk_start_queue);
292297 * or if it simply chooses not to queue more I/O at one point, it can
293298 * call this function to prevent the request_fn from being called until
294299 * the driver has signalled it's ready to go again. This happens by calling
295- * blk_start_queue() to restart queue operations. Queue lock must be held.
300+ * blk_start_queue() to restart queue operations.
296301 **/
297302void blk_stop_queue (struct request_queue * q )
298303{
304+ lockdep_assert_held (q -> queue_lock );
305+
299306 cancel_delayed_work (& q -> delay_work );
300307 queue_flag_set (QUEUE_FLAG_STOPPED , q );
301308}
@@ -348,6 +355,8 @@ EXPORT_SYMBOL(blk_sync_queue);
348355 */
349356inline void __blk_run_queue_uncond (struct request_queue * q )
350357{
358+ lockdep_assert_held (q -> queue_lock );
359+
351360 if (unlikely (blk_queue_dead (q )))
352361 return ;
353362
@@ -369,11 +378,12 @@ EXPORT_SYMBOL_GPL(__blk_run_queue_uncond);
369378 * @q: The queue to run
370379 *
371380 * Description:
372- * See @blk_run_queue. This variant must be called with the queue lock
373- * held and interrupts disabled.
381+ * See @blk_run_queue.
374382 */
375383void __blk_run_queue (struct request_queue * q )
376384{
385+ lockdep_assert_held (q -> queue_lock );
386+
377387 if (unlikely (blk_queue_stopped (q )))
378388 return ;
379389
@@ -387,10 +397,17 @@ EXPORT_SYMBOL(__blk_run_queue);
387397 *
388398 * Description:
389399 * Tells kblockd to perform the equivalent of @blk_run_queue on behalf
390- * of us. The caller must hold the queue lock.
400+ * of us.
401+ *
402+ * Note:
403+ * Since it is not allowed to run q->delay_work after blk_cleanup_queue()
404+ * has canceled q->delay_work, callers must hold the queue lock to avoid
405+ * race conditions between blk_cleanup_queue() and blk_run_queue_async().
391406 */
392407void blk_run_queue_async (struct request_queue * q )
393408{
409+ lockdep_assert_held (q -> queue_lock );
410+
394411 if (likely (!blk_queue_stopped (q ) && !blk_queue_dead (q )))
395412 mod_delayed_work (kblockd_workqueue , & q -> delay_work , 0 );
396413}
@@ -1136,6 +1153,8 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,
11361153 int may_queue ;
11371154 req_flags_t rq_flags = RQF_ALLOCED ;
11381155
1156+ lockdep_assert_held (q -> queue_lock );
1157+
11391158 if (unlikely (blk_queue_dying (q )))
11401159 return ERR_PTR (- ENODEV );
11411160
@@ -1309,6 +1328,8 @@ static struct request *get_request(struct request_queue *q, unsigned int op,
13091328 struct request_list * rl ;
13101329 struct request * rq ;
13111330
1331+ lockdep_assert_held (q -> queue_lock );
1332+
13121333 rl = blk_get_rl (q , bio ); /* transferred to @rq on success */
13131334retry :
13141335 rq = __get_request (rl , op , bio , gfp_mask );
@@ -1402,6 +1423,8 @@ EXPORT_SYMBOL(blk_get_request);
14021423 */
14031424void blk_requeue_request (struct request_queue * q , struct request * rq )
14041425{
1426+ lockdep_assert_held (q -> queue_lock );
1427+
14051428 blk_delete_timer (rq );
14061429 blk_clear_rq_complete (rq );
14071430 trace_block_rq_requeue (q , rq );
@@ -1476,9 +1499,6 @@ static void blk_pm_put_request(struct request *rq)
14761499static inline void blk_pm_put_request (struct request * rq ) {}
14771500#endif
14781501
1479- /*
1480- * queue lock must be held
1481- */
14821502void __blk_put_request (struct request_queue * q , struct request * req )
14831503{
14841504 req_flags_t rq_flags = req -> rq_flags ;
@@ -1491,6 +1511,8 @@ void __blk_put_request(struct request_queue *q, struct request *req)
14911511 return ;
14921512 }
14931513
1514+ lockdep_assert_held (q -> queue_lock );
1515+
14941516 blk_pm_put_request (req );
14951517
14961518 elv_completed_request (q , req );
@@ -2327,9 +2349,6 @@ EXPORT_SYMBOL_GPL(blk_insert_cloned_request);
23272349 *
23282350 * Return:
23292351 * The number of bytes to fail.
2330- *
2331- * Context:
2332- * queue_lock must be held.
23332352 */
23342353unsigned int blk_rq_err_bytes (const struct request * rq )
23352354{
@@ -2469,15 +2488,14 @@ void blk_account_io_start(struct request *rq, bool new_io)
24692488 * Return:
24702489 * Pointer to the request at the top of @q if available. Null
24712490 * otherwise.
2472- *
2473- * Context:
2474- * queue_lock must be held.
24752491 */
24762492struct request * blk_peek_request (struct request_queue * q )
24772493{
24782494 struct request * rq ;
24792495 int ret ;
24802496
2497+ lockdep_assert_held (q -> queue_lock );
2498+
24812499 while ((rq = __elv_next_request (q )) != NULL ) {
24822500
24832501 rq = blk_pm_peek_request (q , rq );
@@ -2593,12 +2611,11 @@ void blk_dequeue_request(struct request *rq)
25932611 *
25942612 * Block internal functions which don't want to start timer should
25952613 * call blk_dequeue_request().
2596- *
2597- * Context:
2598- * queue_lock must be held.
25992614 */
26002615void blk_start_request (struct request * req )
26012616{
2617+ lockdep_assert_held (req -> q -> queue_lock );
2618+
26022619 blk_dequeue_request (req );
26032620
26042621 if (test_bit (QUEUE_FLAG_STATS , & req -> q -> queue_flags )) {
@@ -2623,14 +2640,13 @@ EXPORT_SYMBOL(blk_start_request);
26232640 * Return:
26242641 * Pointer to the request at the top of @q if available. Null
26252642 * otherwise.
2626- *
2627- * Context:
2628- * queue_lock must be held.
26292643 */
26302644struct request * blk_fetch_request (struct request_queue * q )
26312645{
26322646 struct request * rq ;
26332647
2648+ lockdep_assert_held (q -> queue_lock );
2649+
26342650 rq = blk_peek_request (q );
26352651 if (rq )
26362652 blk_start_request (rq );
@@ -2776,13 +2792,12 @@ void blk_unprep_request(struct request *req)
27762792}
27772793EXPORT_SYMBOL_GPL (blk_unprep_request );
27782794
2779- /*
2780- * queue lock must be held
2781- */
27822795void blk_finish_request (struct request * req , blk_status_t error )
27832796{
27842797 struct request_queue * q = req -> q ;
27852798
2799+ lockdep_assert_held (req -> q -> queue_lock );
2800+
27862801 if (req -> rq_flags & RQF_STATS )
27872802 blk_stat_add (req );
27882803
@@ -2864,6 +2879,8 @@ static bool blk_end_bidi_request(struct request *rq, blk_status_t error,
28642879static bool __blk_end_bidi_request (struct request * rq , blk_status_t error ,
28652880 unsigned int nr_bytes , unsigned int bidi_bytes )
28662881{
2882+ lockdep_assert_held (rq -> q -> queue_lock );
2883+
28672884 if (blk_update_bidi_request (rq , error , nr_bytes , bidi_bytes ))
28682885 return true;
28692886
@@ -2930,6 +2947,8 @@ EXPORT_SYMBOL(blk_end_request_all);
29302947bool __blk_end_request (struct request * rq , blk_status_t error ,
29312948 unsigned int nr_bytes )
29322949{
2950+ lockdep_assert_held (rq -> q -> queue_lock );
2951+
29332952 return __blk_end_bidi_request (rq , error , nr_bytes , 0 );
29342953}
29352954EXPORT_SYMBOL (__blk_end_request );
@@ -2947,6 +2966,8 @@ void __blk_end_request_all(struct request *rq, blk_status_t error)
29472966 bool pending ;
29482967 unsigned int bidi_bytes = 0 ;
29492968
2969+ lockdep_assert_held (rq -> q -> queue_lock );
2970+
29502971 if (unlikely (blk_bidi_rq (rq )))
29512972 bidi_bytes = blk_rq_bytes (rq -> next_rq );
29522973
@@ -3211,6 +3232,8 @@ static void queue_unplugged(struct request_queue *q, unsigned int depth,
32113232 bool from_schedule )
32123233 __releases (q - > queue_lock )
32133234{
3235+ lockdep_assert_held (q -> queue_lock );
3236+
32143237 trace_block_unplug (q , depth , !from_schedule );
32153238
32163239 if (from_schedule )
0 commit comments