Skip to content

Commit 3a6d400

Browse files
bvanasschegregkh
authored andcommitted
blk-mq: Fix a race between bt_clear_tag() and bt_get()
commit c38d185 upstream. What we need is the following two guarantees: * Any thread that observes the effect of the test_and_set_bit() by __bt_get_word() also observes the preceding addition of 'current' to the appropriate wait list. This is guaranteed by the semantics of the spin_unlock() operation performed by prepare_and_wait(). Hence the conversion of test_and_set_bit_lock() into test_and_set_bit(). * The wait lists are examined by bt_clear() after the tag bit has been cleared. clear_bit_unlock() guarantees that any thread that observes that the bit has been cleared also observes the store operations preceding clear_bit_unlock(). However, clear_bit_unlock() does not prevent that the wait lists are examined before that the tag bit is cleared. Hence the addition of a memory barrier between clear_bit() and the wait list examination. 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 d04e14a commit 3a6d400

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎block/blk-mq-tag.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag)
158158
return -1;
159159
}
160160
last_tag = tag + 1;
161-
} while (test_and_set_bit_lock(tag, &bm->word));
161+
} while (test_and_set_bit(tag, &bm->word));
162162

163163
return tag;
164164
}
@@ -342,11 +342,10 @@ static void bt_clear_tag(struct blk_mq_bitmap_tags *bt, unsigned int tag)
342342
struct bt_wait_state *bs;
343343
int wait_cnt;
344344

345-
/*
346-
* The unlock memory barrier need to order access to req in free
347-
* path and clearing tag bit
348-
*/
349-
clear_bit_unlock(TAG_TO_BIT(bt, tag), &bt->map[index].word);
345+
clear_bit(TAG_TO_BIT(bt, tag), &bt->map[index].word);
346+
347+
/* Ensure that the wait list checks occur after clear_bit(). */
348+
smp_mb();
350349

351350
bs = bt_wake_ptr(bt);
352351
if (!bs)

0 commit comments

Comments
 (0)