Skip to content

Commit 9e78c38

Browse files
damien-lemoalaxboe
authored andcommitted
block: Hold a reference on zone write plugs to schedule submission
Since a zone write plug BIO work is a field of struct blk_zone_wplug, we must ensure that a zone write plug is never freed when its BIO submission work is queued or running. Do this by holding a reference on the zone write plug when the submission work is scheduled for execution with queue_work() and releasing the reference at the end of the execution of the work function blk_zone_wplug_bio_work(). The helper function disk_zone_wplug_schedule_bio_work() is introduced to get a reference on a zone write plug and queue its work. This helper is used in disk_zone_wplug_unplug_bio() and disk_zone_wplug_handle_error(). Fixes: dd291d7 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20240501110907.96950-6-dlemoal@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 19aad27 commit 9e78c38

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

block/blk-zoned.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,19 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
11321132
}
11331133
EXPORT_SYMBOL_GPL(blk_zone_plug_bio);
11341134

1135+
static void disk_zone_wplug_schedule_bio_work(struct gendisk *disk,
1136+
struct blk_zone_wplug *zwplug)
1137+
{
1138+
/*
1139+
* Take a reference on the zone write plug and schedule the submission
1140+
* of the next plugged BIO. blk_zone_wplug_bio_work() will release the
1141+
* reference we take here.
1142+
*/
1143+
WARN_ON_ONCE(!(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED));
1144+
atomic_inc(&zwplug->ref);
1145+
queue_work(disk->zone_wplugs_wq, &zwplug->bio_work);
1146+
}
1147+
11351148
static void disk_zone_wplug_unplug_bio(struct gendisk *disk,
11361149
struct blk_zone_wplug *zwplug)
11371150
{
@@ -1151,8 +1164,8 @@ static void disk_zone_wplug_unplug_bio(struct gendisk *disk,
11511164

11521165
/* Schedule submission of the next plugged BIO if we have one. */
11531166
if (!bio_list_empty(&zwplug->bio_list)) {
1167+
disk_zone_wplug_schedule_bio_work(disk, zwplug);
11541168
spin_unlock_irqrestore(&zwplug->lock, flags);
1155-
queue_work(disk->zone_wplugs_wq, &zwplug->bio_work);
11561169
return;
11571170
}
11581171

@@ -1252,14 +1265,14 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
12521265
if (!bio) {
12531266
zwplug->flags &= ~BLK_ZONE_WPLUG_PLUGGED;
12541267
spin_unlock_irqrestore(&zwplug->lock, flags);
1255-
return;
1268+
goto put_zwplug;
12561269
}
12571270

12581271
if (!blk_zone_wplug_prepare_bio(zwplug, bio)) {
12591272
/* Error recovery will decide what to do with the BIO. */
12601273
bio_list_add_head(&zwplug->bio_list, bio);
12611274
spin_unlock_irqrestore(&zwplug->lock, flags);
1262-
return;
1275+
goto put_zwplug;
12631276
}
12641277

12651278
spin_unlock_irqrestore(&zwplug->lock, flags);
@@ -1275,6 +1288,10 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
12751288
*/
12761289
if (bdev->bd_has_submit_bio)
12771290
blk_queue_exit(bdev->bd_disk->queue);
1291+
1292+
put_zwplug:
1293+
/* Drop the reference we took in disk_zone_wplug_schedule_bio_work(). */
1294+
disk_put_zone_wplug(zwplug);
12781295
}
12791296

12801297
static unsigned int blk_zone_wp_offset(struct blk_zone *zone)
@@ -1354,8 +1371,7 @@ static void disk_zone_wplug_handle_error(struct gendisk *disk,
13541371

13551372
/* Restart BIO submission if we still have any BIO left. */
13561373
if (!bio_list_empty(&zwplug->bio_list)) {
1357-
WARN_ON_ONCE(!(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED));
1358-
queue_work(disk->zone_wplugs_wq, &zwplug->bio_work);
1374+
disk_zone_wplug_schedule_bio_work(disk, zwplug);
13591375
goto unlock;
13601376
}
13611377

0 commit comments

Comments
 (0)