]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
block: fix race between switching elevator and removing queues
authorMing Lei <ming.lei@redhat.com>
Thu, 12 Sep 2019 04:02:24 +0000 (12:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Mar 2021 08:39:30 +0000 (09:39 +0100)
commit6c63a7be2b11b378f77adfa8dd81e66b0df2795b
treee89ddc72b4c679ebdc8e0348b2c9358ceec52eca
parentfa137b50f3264a157575413030464c19ab553b0e
block: fix race between switching elevator and removing queues

commit 0a67b5a926e63ff5492c3c675eab5900580d056d upstream.

cecf5d87ff20 ("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: cecf5d87ff20 ("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: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
block/blk-sysfs.c