Skip to content

Commit 00e885e

Browse files
cleechaxboe
authored andcommitted
blk-mq: fix "bad unlock balance detected" on q->srcu in __blk_mq_run_dispatch_ops
The 'q' parameter of the macro __blk_mq_run_dispatch_ops may not be one local variable, such as, it is rq->q, then request queue pointed by this variable could be changed to another queue in case of BLK_MQ_F_TAG_QUEUE_SHARED after 'dispatch_ops' returns, then 'bad unlock balance' is triggered. Fixes the issue by adding one local variable for doing srcu lock/unlock. Fixes: 2a904d0 ("blk-mq: remove hctx_lock and hctx_unlock") Cc: Marco Patalano <[email protected]> Signed-off-by: Chris Leech <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 9b0cb77 commit 00e885e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

block/blk-mq.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,13 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
378378
#define __blk_mq_run_dispatch_ops(q, check_sleep, dispatch_ops) \
379379
do { \
380380
if ((q)->tag_set->flags & BLK_MQ_F_BLOCKING) { \
381+
struct blk_mq_tag_set *__tag_set = (q)->tag_set; \
381382
int srcu_idx; \
382383
\
383384
might_sleep_if(check_sleep); \
384-
srcu_idx = srcu_read_lock((q)->tag_set->srcu); \
385+
srcu_idx = srcu_read_lock(__tag_set->srcu); \
385386
(dispatch_ops); \
386-
srcu_read_unlock((q)->tag_set->srcu, srcu_idx); \
387+
srcu_read_unlock(__tag_set->srcu, srcu_idx); \
387388
} else { \
388389
rcu_read_lock(); \
389390
(dispatch_ops); \

0 commit comments

Comments
 (0)