block: do not allow updates through sysfs until registration completes 82/290882/2
authorTahsin Erdogan <tahsin@google.com>
Wed, 15 Feb 2017 03:27:38 +0000 (19:27 -0800)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 5 Apr 2023 01:20:14 +0000 (10:20 +0900)
commit6bb323e9561e440bb617d8e70a45892399ad0381
tree626ffafc0a30d9dd2f13ce5faf420b6896cd8a41
parentd96ff7ccd94334aca6f5b4a7daeb6cd91e340193
block: do not allow updates through sysfs until registration completes

When a new disk shows up, sysfs queue directory is created before elevator
is registered. This allows a user to attempt a scheduler switch even though
the initial registration hasn't completed yet.

In one scenario, blk_register_queue() calls elv_register_queue() and
right before cfq_registered_queue() is called, another process executes
elevator_switch() and replaces q->elevator with deadline scheduler. When
cfq_registered_queue() executes it interprets e->elevator_data as struct
cfq_data even though it is actually struct deadline_data.

Grab q->sysfs_lock in blk_register_queue() to synchronize with sysfs
callers.

Signed-off-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
[sw0312.kim: backport mainline commit b410aff2bd9f to fix possible deadlock in blk-mq for cpu hotplug]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ifcdada904f565a7eb456d7b69966f7408ac256a3
block/blk-sysfs.c