• Ming Lei's avatar
    block: fix race between switching elevator and removing queues · 0a67b5a9
    Ming Lei authored
    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: default avatarMing Lei <ming.lei@redhat.com>
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    0a67b5a9
blk-sysfs.c 26.5 KB