]> git.ipfire.org Git - thirdparty/linux.git/commit - block/blk-mq-tag.h
blk-mq: clear stale request in tags->rq[] before freeing one request pool
authorMing Lei <ming.lei@redhat.com>
Tue, 11 May 2021 15:22:35 +0000 (23:22 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 24 May 2021 12:47:22 +0000 (06:47 -0600)
commitbd63141d585bef14f4caf111f6d0e27fe2300ec6
tree18c509a0a1fb0b90746396b360a5b1e5b46bae37
parent2e315dc07df009c3e29d6926871f62a30cfae394
blk-mq: clear stale request in tags->rq[] before freeing one request pool

refcount_inc_not_zero() in bt_tags_iter() still may read one freed
request.

Fix the issue by the following approach:

1) hold a per-tags spinlock when reading ->rqs[tag] and calling
refcount_inc_not_zero in bt_tags_iter()

2) clearing stale request referred via ->rqs[tag] before freeing
request pool, the per-tags spinlock is held for clearing stale
->rq[tag]

So after we cleared stale requests, bt_tags_iter() won't observe
freed request any more, also the clearing will wait for pending
request reference.

The idea of clearing ->rqs[] is borrowed from John Garry's previous
patch and one recent David's patch.

Tested-by: John Garry <john.garry@huawei.com>
Reviewed-by: David Jeffery <djeffery@redhat.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20210511152236.763464-4-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq-tag.c
block/blk-mq-tag.h
block/blk-mq.c