Skip to content

Commit d04e14a

Browse files
bvanasschegregkh
authored andcommitted
blk-mq: Avoid that __bt_get_word() wraps multiple times
commit 9e98e9d upstream. If __bt_get_word() is called with last_tag != 0, if the first find_next_zero_bit() fails, if after wrap-around the test_and_set_bit() call fails and find_next_zero_bit() succeeds, if the next test_and_set_bit() call fails and subsequently find_next_zero_bit() does not find a zero bit, then another wrap-around will occur. Avoid this by introducing an additional local variable. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Robert Elliott <elliott@hp.com> Cc: Ming Lei <ming.lei@canonical.com> Cc: Alexander Gordeev <agordeev@redhat.com> Signed-off-by: Jens Axboe <axboe@fb.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b041392 commit d04e14a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎block/blk-mq-tag.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
137137
static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag)
138138
{
139139
int tag, org_last_tag, end;
140+
bool wrap = last_tag != 0;
140141

141142
org_last_tag = last_tag;
142143
end = bm->depth;
@@ -148,8 +149,9 @@ static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag)
148149
* We started with an offset, start from 0 to
149150
* exhaust the map.
150151
*/
151-
if (org_last_tag && last_tag) {
152-
end = last_tag;
152+
if (wrap) {
153+
wrap = false;
154+
end = org_last_tag;
153155
last_tag = 0;
154156
goto restart;
155157
}

0 commit comments

Comments
 (0)