blk-mq: Fix a race between bt_clear_tag() and bt_get()
authorBart Van Assche <bvanassche@acm.org>
Tue, 9 Dec 2014 15:58:35 +0000 (16:58 +0100)
committerJens Axboe <axboe@fb.com>
Mon, 30 Mar 2015 18:54:56 +0000 (12:54 -0600)
commit4deaf951c734b006642e5090fb301f4729cc2db8
tree6f6620f1d51c07be29c10218cfe5558152f1fd04
parent7535a7995709a97ce74f449eeecdad1a738d63ea
blk-mq: Fix a race between bt_clear_tag() and bt_get()

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>
Cc: <stable@vger.kernel.org> # v3.13+
Signed-off-by: Jens Axboe <axboe@fb.com>
block/blk-mq-tag.c