Skip to content

Commit af28141

Browse files
Christoph Hellwigaxboe
Christoph Hellwig
authored andcommitted
block: freeze the queue in queue_attr_store
queue_attr_store updates attributes used to control generating I/O, and can cause malformed bios if changed with I/O in flight. Freeze the queue in common code instead of adding it to almost every attribute. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Link: https://lore.kernel.org/r/20240617060532.127975-12-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6b37778 commit af28141

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

block/blk-mq.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -4631,13 +4631,15 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
46314631
int ret;
46324632
unsigned long i;
46334633

4634+
if (WARN_ON_ONCE(!q->mq_freeze_depth))
4635+
return -EINVAL;
4636+
46344637
if (!set)
46354638
return -EINVAL;
46364639

46374640
if (q->nr_requests == nr)
46384641
return 0;
46394642

4640-
blk_mq_freeze_queue(q);
46414643
blk_mq_quiesce_queue(q);
46424644

46434645
ret = 0;
@@ -4671,7 +4673,6 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
46714673
}
46724674

46734675
blk_mq_unquiesce_queue(q);
4674-
blk_mq_unfreeze_queue(q);
46754676

46764677
return ret;
46774678
}

block/blk-sysfs.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,9 @@ static ssize_t queue_discard_max_store(struct request_queue *q,
189189
if ((max_discard_bytes >> SECTOR_SHIFT) > UINT_MAX)
190190
return -EINVAL;
191191

192-
blk_mq_freeze_queue(q);
193192
lim = queue_limits_start_update(q);
194193
lim.max_user_discard_sectors = max_discard_bytes >> SECTOR_SHIFT;
195194
err = queue_limits_commit_update(q, &lim);
196-
blk_mq_unfreeze_queue(q);
197-
198195
if (err)
199196
return err;
200197
return ret;
@@ -241,11 +238,9 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
241238
if (ret < 0)
242239
return ret;
243240

244-
blk_mq_freeze_queue(q);
245241
lim = queue_limits_start_update(q);
246242
lim.max_user_sectors = max_sectors_kb << 1;
247243
err = queue_limits_commit_update(q, &lim);
248-
blk_mq_unfreeze_queue(q);
249244
if (err)
250245
return err;
251246
return ret;
@@ -585,13 +580,11 @@ static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
585580
* ends up either enabling or disabling wbt completely. We can't
586581
* have IO inflight if that happens.
587582
*/
588-
blk_mq_freeze_queue(q);
589583
blk_mq_quiesce_queue(q);
590584

591585
wbt_set_min_lat(q, val);
592586

593587
blk_mq_unquiesce_queue(q);
594-
blk_mq_unfreeze_queue(q);
595588

596589
return count;
597590
}
@@ -722,9 +715,11 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
722715
if (!entry->store)
723716
return -EIO;
724717

718+
blk_mq_freeze_queue(q);
725719
mutex_lock(&q->sysfs_lock);
726720
res = entry->store(q, page, length);
727721
mutex_unlock(&q->sysfs_lock);
722+
blk_mq_unfreeze_queue(q);
728723
return res;
729724
}
730725

0 commit comments

Comments
 (0)