Skip to content

Commit ad5f498

Browse files
Mikulas Patockasnitm
authored andcommitted
dm: initialize non-blk-mq queue data before queue is used
Commit bfebd1c ("dm: add full blk-mq support to request-based DM") moves the initialization of the fields backing_dev_info.congested_fn, backing_dev_info.congested_data and queuedata from the function dm_init_md_queue (that is called when the device is created) to dm_init_old_md_queue (that is called after the device type is determined). There is no locking when accessing these variables, thus it is possible for other parts of the kernel to briefly see this data in a transient state (e.g. queue->backing_dev_info.congested_fn initialized and md->queue->backing_dev_info.congested_data uninitialized, resulting in passing an incorrect parameter to the function dm_any_congested). This queue data is left initialized for blk-mq devices even though they that don't use it. Fixes: bfebd1c ("dm: add full blk-mq support to request-based DM") Signed-off-by: Mikulas Patocka <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Cc: [email protected] # v4.1+
1 parent a6dd102 commit ad5f498

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/md/dm.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,13 @@ static void dm_init_md_queue(struct mapped_device *md)
21972197
* This queue is new, so no concurrency on the queue_flags.
21982198
*/
21992199
queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
2200+
2201+
/*
2202+
* Initialize data that will only be used by a non-blk-mq DM queue
2203+
* - must do so here (in alloc_dev callchain) before queue is used
2204+
*/
2205+
md->queue->queuedata = md;
2206+
md->queue->backing_dev_info.congested_data = md;
22002207
}
22012208

22022209
static void dm_init_old_md_queue(struct mapped_device *md)
@@ -2207,10 +2214,7 @@ static void dm_init_old_md_queue(struct mapped_device *md)
22072214
/*
22082215
* Initialize aspects of queue that aren't relevant for blk-mq
22092216
*/
2210-
md->queue->queuedata = md;
22112217
md->queue->backing_dev_info.congested_fn = dm_any_congested;
2212-
md->queue->backing_dev_info.congested_data = md;
2213-
22142218
blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
22152219
}
22162220

0 commit comments

Comments
 (0)