Commit 87a13a34 authored by Bart Van Assche's avatar Bart Van Assche Committed by Luis Henriques

blk-mq: Avoid that __bt_get_word() wraps multiple times

commit 9e98e9d7 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: default avatarBart 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: default avatarJens Axboe <axboe@fb.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 294d7496
......@@ -137,6 +137,7 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag)
{
int tag, org_last_tag, end;
bool wrap = last_tag != 0;
org_last_tag = last_tag;
end = bm->depth;
......@@ -148,8 +149,9 @@ static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag)
* We started with an offset, start from 0 to
* exhaust the map.
*/
if (org_last_tag && last_tag) {
end = last_tag;
if (wrap) {
wrap = false;
end = org_last_tag;
last_tag = 0;
goto restart;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment