提交 5596d82c 编写于 作者: M Ming Lei 提交者: Yongqiang Liu

block: fix race between switching elevator and removing queues

mainline inclusion
from mainline-5.4-rc1
commit 0a67b5a9
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6HOKY
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.2&id=0a67b5a926e63ff5492c3c675eab5900580d056d

---------------------------

cecf5d87 ("block: split .sysfs_lock into two locks") starts to
release & actuire sysfs_lock again during switching elevator. So it
isn't enough to prevent switching elevator from happening by simply
clearing QUEUE_FLAG_REGISTERED with holding sysfs_lock, because
in-progress switch still can move on after re-acquiring the lock,
meantime the flag of QUEUE_FLAG_REGISTERED won't get checked.

Fixes this issue by checking 'q->elevator' directly & locklessly after
q->kobj is removed in blk_unregister_queue(), this way is safe because
q->elevator can't be changed at that time.

Fixes: cecf5d87 ("block: split .sysfs_lock into two locks")
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Mike Snitzer <snitzer@redhat.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: NMing Lei <ming.lei@redhat.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Conflict:
  block/blk-sysfs.c
Signed-off-by: NLi Lingfeng <lilingfeng3@huawei.com>
Reviewed-by: NHou Tao <houtao1@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 e5264f98
...@@ -1020,7 +1020,6 @@ EXPORT_SYMBOL_GPL(blk_register_queue); ...@@ -1020,7 +1020,6 @@ EXPORT_SYMBOL_GPL(blk_register_queue);
void blk_unregister_queue(struct gendisk *disk) void blk_unregister_queue(struct gendisk *disk)
{ {
struct request_queue *q = disk->queue; struct request_queue *q = disk->queue;
bool has_elevator;
if (WARN_ON(!q)) if (WARN_ON(!q))
return; return;
...@@ -1038,7 +1037,6 @@ void blk_unregister_queue(struct gendisk *disk) ...@@ -1038,7 +1037,6 @@ void blk_unregister_queue(struct gendisk *disk)
mutex_lock(&q->sysfs_lock); mutex_lock(&q->sysfs_lock);
blk_queue_flag_clear(QUEUE_FLAG_REGISTERED, q); blk_queue_flag_clear(QUEUE_FLAG_REGISTERED, q);
has_elevator = !!q->elevator;
mutex_unlock(&q->sysfs_lock); mutex_unlock(&q->sysfs_lock);
mutex_lock(&q->sysfs_dir_lock); mutex_lock(&q->sysfs_dir_lock);
...@@ -1051,7 +1049,11 @@ void blk_unregister_queue(struct gendisk *disk) ...@@ -1051,7 +1049,11 @@ void blk_unregister_queue(struct gendisk *disk)
blk_trace_remove_sysfs(disk_to_dev(disk)); blk_trace_remove_sysfs(disk_to_dev(disk));
if (q->request_fn || (q->mq_ops && has_elevator)) /*
* q->kobj has been removed, so it is safe to check if elevator
* exists without holding q->sysfs_lock.
*/
if (q->request_fn || (q->mq_ops && q->elevator))
elv_unregister_queue(q); elv_unregister_queue(q);
mutex_unlock(&q->sysfs_dir_lock); mutex_unlock(&q->sysfs_dir_lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册