diff options
author | Mike Snitzer <snitzer@redhat.com> | 2018-01-11 14:11:01 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-01-15 10:41:38 -0500 |
commit | 667257e8b2988c0183ba23e2bcd6900e87961606 (patch) | |
tree | ae0ec92e1fe69f71788169e07789096357f0c4ba /block/blk-sysfs.c | |
parent | bc8d062c36e3525e81ea8237ff0ab3264c2317b6 (diff) |
block: properly protect the 'queue' kobj in blk_unregister_queue
The original commit e9a823fb34a8b (block: fix warning when I/O elevator
is changed as request_queue is being removed) is pretty conflated.
"conflated" because the resource being protected by q->sysfs_lock isn't
the queue_flags (it is the 'queue' kobj).
q->sysfs_lock serializes __elevator_change() (via elv_iosched_store)
from racing with blk_unregister_queue():
1) By holding q->sysfs_lock first, __elevator_change() can complete
before a racing blk_unregister_queue().
2) Conversely, __elevator_change() is testing for QUEUE_FLAG_REGISTERED
in case elv_iosched_store() loses the race with blk_unregister_queue(),
it needs a way to know the 'queue' kobj isn't there.
Expand the scope of blk_unregister_queue()'s q->sysfs_lock use so it is
held until after the 'queue' kobj is removed.
To do so blk_mq_unregister_dev() must not also take q->sysfs_lock. So
rename __blk_mq_unregister_dev() to blk_mq_unregister_dev().
Also, blk_unregister_queue() should use q->queue_lock to protect against
any concurrent writes to q->queue_flags -- even though chances are the
queue is being cleaned up so no concurrent writes are likely.
Fixes: e9a823fb34a8b ("block: fix warning when I/O elevator is changed as request_queue is being removed")
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-sysfs.c')
-rw-r--r-- | block/blk-sysfs.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 870484eaed1f..9272452ff456 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c | |||
@@ -929,12 +929,17 @@ void blk_unregister_queue(struct gendisk *disk) | |||
929 | if (WARN_ON(!q)) | 929 | if (WARN_ON(!q)) |
930 | return; | 930 | return; |
931 | 931 | ||
932 | /* | ||
933 | * Protect against the 'queue' kobj being accessed | ||
934 | * while/after it is removed. | ||
935 | */ | ||
932 | mutex_lock(&q->sysfs_lock); | 936 | mutex_lock(&q->sysfs_lock); |
933 | queue_flag_clear_unlocked(QUEUE_FLAG_REGISTERED, q); | ||
934 | mutex_unlock(&q->sysfs_lock); | ||
935 | 937 | ||
936 | wbt_exit(q); | 938 | spin_lock_irq(q->queue_lock); |
939 | queue_flag_clear(QUEUE_FLAG_REGISTERED, q); | ||
940 | spin_unlock_irq(q->queue_lock); | ||
937 | 941 | ||
942 | wbt_exit(q); | ||
938 | 943 | ||
939 | if (q->mq_ops) | 944 | if (q->mq_ops) |
940 | blk_mq_unregister_dev(disk_to_dev(disk), q); | 945 | blk_mq_unregister_dev(disk_to_dev(disk), q); |
@@ -946,4 +951,6 @@ void blk_unregister_queue(struct gendisk *disk) | |||
946 | kobject_del(&q->kobj); | 951 | kobject_del(&q->kobj); |
947 | blk_trace_remove_sysfs(disk_to_dev(disk)); | 952 | blk_trace_remove_sysfs(disk_to_dev(disk)); |
948 | kobject_put(&disk_to_dev(disk)->kobj); | 953 | kobject_put(&disk_to_dev(disk)->kobj); |
954 | |||
955 | mutex_unlock(&q->sysfs_lock); | ||
949 | } | 956 | } |