diff options
author | Ming Lei <ming.lei@redhat.com> | 2021-05-11 17:22:35 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2021-05-24 14:47:22 +0200 |
commit | bd63141d585bef14f4caf111f6d0e27fe2300ec6 (patch) | |
tree | 18c509a0a1fb0b90746396b360a5b1e5b46bae37 /block/blk-mq-tag.h | |
parent | blk-mq: grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter (diff) | |
download | linux-bd63141d585bef14f4caf111f6d0e27fe2300ec6.tar.xz linux-bd63141d585bef14f4caf111f6d0e27fe2300ec6.zip |
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>
Diffstat (limited to 'block/blk-mq-tag.h')
-rw-r--r-- | block/blk-mq-tag.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/block/blk-mq-tag.h b/block/blk-mq-tag.h index 7d3e6b333a4a..f887988e5ef6 100644 --- a/block/blk-mq-tag.h +++ b/block/blk-mq-tag.h @@ -20,6 +20,12 @@ struct blk_mq_tags { struct request **rqs; struct request **static_rqs; struct list_head page_list; + + /* + * used to clear request reference in rqs[] before freeing one + * request pool + */ + spinlock_t lock; }; extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, |