Skip to content

Commit f2b3420

Browse files
committed
Merge tag 'block-5.15-2021-10-17' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "Bigger than usual for this point in time, the majority is fixing some issues around BDI lifetimes with the move from the request_queue to the disk in this release. In detail: - Series on draining fs IO for del_gendisk() (Christoph) - NVMe pull request via Christoph: - fix the abort command id (Keith Busch) - nvme: fix per-namespace chardev deletion (Adam Manzanares) - brd locking scope fix (Tetsuo) - BFQ fix (Paolo)" * tag 'block-5.15-2021-10-17' of git://git.kernel.dk/linux-block: block, bfq: reset last_bfqq_created on group change block: warn when putting the final reference on a registered disk brd: reduce the brd_devices_mutex scope kyber: avoid q->disk dereferences in trace points block: keep q_usage_counter in atomic mode after del_gendisk block: drain file system I/O on del_gendisk block: split bio_queue_enter from blk_queue_enter block: factor out a blk_try_enter_queue helper block: call submit_bio_checks under q_usage_counter nvme: fix per-namespace chardev deletion block/rnbd-clt-sysfs: fix a couple uninitialized variable bugs nvme-pci: Fix abort command id
2 parents cc0af0a + d29bd41 commit f2b3420

File tree

13 files changed

+171
-120
lines changed

13 files changed

+171
-120
lines changed

block/bfq-cgroup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,12 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
666666
bfq_put_idle_entity(bfq_entity_service_tree(entity), entity);
667667
bfqg_and_blkg_put(bfqq_group(bfqq));
668668

669+
if (entity->parent &&
670+
entity->parent->last_bfqq_created == bfqq)
671+
entity->parent->last_bfqq_created = NULL;
672+
else if (bfqd->last_bfqq_created == bfqq)
673+
bfqd->last_bfqq_created = NULL;
674+
669675
entity->parent = bfqg->my_entity;
670676
entity->sched_data = &bfqg->sched_data;
671677
/* pin down bfqg and its associated blkg */

block/blk-core.c

Lines changed: 78 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#include "blk-mq.h"
5050
#include "blk-mq-sched.h"
5151
#include "blk-pm.h"
52-
#include "blk-rq-qos.h"
5352

5453
struct dentry *blk_debugfs_root;
5554

@@ -337,23 +336,25 @@ void blk_put_queue(struct request_queue *q)
337336
}
338337
EXPORT_SYMBOL(blk_put_queue);
339338

340-
void blk_set_queue_dying(struct request_queue *q)
339+
void blk_queue_start_drain(struct request_queue *q)
341340
{
342-
blk_queue_flag_set(QUEUE_FLAG_DYING, q);
343-
344341
/*
345342
* When queue DYING flag is set, we need to block new req
346343
* entering queue, so we call blk_freeze_queue_start() to
347344
* prevent I/O from crossing blk_queue_enter().
348345
*/
349346
blk_freeze_queue_start(q);
350-
351347
if (queue_is_mq(q))
352348
blk_mq_wake_waiters(q);
353-
354349
/* Make blk_queue_enter() reexamine the DYING flag. */
355350
wake_up_all(&q->mq_freeze_wq);
356351
}
352+
353+
void blk_set_queue_dying(struct request_queue *q)
354+
{
355+
blk_queue_flag_set(QUEUE_FLAG_DYING, q);
356+
blk_queue_start_drain(q);
357+
}
357358
EXPORT_SYMBOL_GPL(blk_set_queue_dying);
358359

359360
/**
@@ -385,13 +386,8 @@ void blk_cleanup_queue(struct request_queue *q)
385386
*/
386387
blk_freeze_queue(q);
387388

388-
rq_qos_exit(q);
389-
390389
blk_queue_flag_set(QUEUE_FLAG_DEAD, q);
391390

392-
/* for synchronous bio-based driver finish in-flight integrity i/o */
393-
blk_flush_integrity();
394-
395391
blk_sync_queue(q);
396392
if (queue_is_mq(q))
397393
blk_mq_exit_queue(q);
@@ -416,6 +412,30 @@ void blk_cleanup_queue(struct request_queue *q)
416412
}
417413
EXPORT_SYMBOL(blk_cleanup_queue);
418414

415+
static bool blk_try_enter_queue(struct request_queue *q, bool pm)
416+
{
417+
rcu_read_lock();
418+
if (!percpu_ref_tryget_live(&q->q_usage_counter))
419+
goto fail;
420+
421+
/*
422+
* The code that increments the pm_only counter must ensure that the
423+
* counter is globally visible before the queue is unfrozen.
424+
*/
425+
if (blk_queue_pm_only(q) &&
426+
(!pm || queue_rpm_status(q) == RPM_SUSPENDED))
427+
goto fail_put;
428+
429+
rcu_read_unlock();
430+
return true;
431+
432+
fail_put:
433+
percpu_ref_put(&q->q_usage_counter);
434+
fail:
435+
rcu_read_unlock();
436+
return false;
437+
}
438+
419439
/**
420440
* blk_queue_enter() - try to increase q->q_usage_counter
421441
* @q: request queue pointer
@@ -425,64 +445,62 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)
425445
{
426446
const bool pm = flags & BLK_MQ_REQ_PM;
427447

428-
while (true) {
429-
bool success = false;
430-
431-
rcu_read_lock();
432-
if (percpu_ref_tryget_live(&q->q_usage_counter)) {
433-
/*
434-
* The code that increments the pm_only counter is
435-
* responsible for ensuring that that counter is
436-
* globally visible before the queue is unfrozen.
437-
*/
438-
if ((pm && queue_rpm_status(q) != RPM_SUSPENDED) ||
439-
!blk_queue_pm_only(q)) {
440-
success = true;
441-
} else {
442-
percpu_ref_put(&q->q_usage_counter);
443-
}
444-
}
445-
rcu_read_unlock();
446-
447-
if (success)
448-
return 0;
449-
448+
while (!blk_try_enter_queue(q, pm)) {
450449
if (flags & BLK_MQ_REQ_NOWAIT)
451450
return -EBUSY;
452451

453452
/*
454-
* read pair of barrier in blk_freeze_queue_start(),
455-
* we need to order reading __PERCPU_REF_DEAD flag of
456-
* .q_usage_counter and reading .mq_freeze_depth or
457-
* queue dying flag, otherwise the following wait may
458-
* never return if the two reads are reordered.
453+
* read pair of barrier in blk_freeze_queue_start(), we need to
454+
* order reading __PERCPU_REF_DEAD flag of .q_usage_counter and
455+
* reading .mq_freeze_depth or queue dying flag, otherwise the
456+
* following wait may never return if the two reads are
457+
* reordered.
459458
*/
460459
smp_rmb();
461-
462460
wait_event(q->mq_freeze_wq,
463461
(!q->mq_freeze_depth &&
464462
blk_pm_resume_queue(pm, q)) ||
465463
blk_queue_dying(q));
466464
if (blk_queue_dying(q))
467465
return -ENODEV;
468466
}
467+
468+
return 0;
469469
}
470470

471471
static inline int bio_queue_enter(struct bio *bio)
472472
{
473-
struct request_queue *q = bio->bi_bdev->bd_disk->queue;
474-
bool nowait = bio->bi_opf & REQ_NOWAIT;
475-
int ret;
473+
struct gendisk *disk = bio->bi_bdev->bd_disk;
474+
struct request_queue *q = disk->queue;
476475

477-
ret = blk_queue_enter(q, nowait ? BLK_MQ_REQ_NOWAIT : 0);
478-
if (unlikely(ret)) {
479-
if (nowait && !blk_queue_dying(q))
476+
while (!blk_try_enter_queue(q, false)) {
477+
if (bio->bi_opf & REQ_NOWAIT) {
478+
if (test_bit(GD_DEAD, &disk->state))
479+
goto dead;
480480
bio_wouldblock_error(bio);
481-
else
482-
bio_io_error(bio);
481+
return -EBUSY;
482+
}
483+
484+
/*
485+
* read pair of barrier in blk_freeze_queue_start(), we need to
486+
* order reading __PERCPU_REF_DEAD flag of .q_usage_counter and
487+
* reading .mq_freeze_depth or queue dying flag, otherwise the
488+
* following wait may never return if the two reads are
489+
* reordered.
490+
*/
491+
smp_rmb();
492+
wait_event(q->mq_freeze_wq,
493+
(!q->mq_freeze_depth &&
494+
blk_pm_resume_queue(false, q)) ||
495+
test_bit(GD_DEAD, &disk->state));
496+
if (test_bit(GD_DEAD, &disk->state))
497+
goto dead;
483498
}
484499

485-
return ret;
500+
return 0;
501+
dead:
502+
bio_io_error(bio);
503+
return -ENODEV;
486504
}
487505

488506
void blk_queue_exit(struct request_queue *q)
@@ -899,11 +917,18 @@ static blk_qc_t __submit_bio(struct bio *bio)
899917
struct gendisk *disk = bio->bi_bdev->bd_disk;
900918
blk_qc_t ret = BLK_QC_T_NONE;
901919

902-
if (blk_crypto_bio_prep(&bio)) {
903-
if (!disk->fops->submit_bio)
904-
return blk_mq_submit_bio(bio);
920+
if (unlikely(bio_queue_enter(bio) != 0))
921+
return BLK_QC_T_NONE;
922+
923+
if (!submit_bio_checks(bio) || !blk_crypto_bio_prep(&bio))
924+
goto queue_exit;
925+
if (disk->fops->submit_bio) {
905926
ret = disk->fops->submit_bio(bio);
927+
goto queue_exit;
906928
}
929+
return blk_mq_submit_bio(bio);
930+
931+
queue_exit:
907932
blk_queue_exit(disk->queue);
908933
return ret;
909934
}
@@ -941,9 +966,6 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio)
941966
struct request_queue *q = bio->bi_bdev->bd_disk->queue;
942967
struct bio_list lower, same;
943968

944-
if (unlikely(bio_queue_enter(bio) != 0))
945-
continue;
946-
947969
/*
948970
* Create a fresh bio_list for all subordinate requests.
949971
*/
@@ -979,23 +1001,12 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio)
9791001
static blk_qc_t __submit_bio_noacct_mq(struct bio *bio)
9801002
{
9811003
struct bio_list bio_list[2] = { };
982-
blk_qc_t ret = BLK_QC_T_NONE;
1004+
blk_qc_t ret;
9831005

9841006
current->bio_list = bio_list;
9851007

9861008
do {
987-
struct gendisk *disk = bio->bi_bdev->bd_disk;
988-
989-
if (unlikely(bio_queue_enter(bio) != 0))
990-
continue;
991-
992-
if (!blk_crypto_bio_prep(&bio)) {
993-
blk_queue_exit(disk->queue);
994-
ret = BLK_QC_T_NONE;
995-
continue;
996-
}
997-
998-
ret = blk_mq_submit_bio(bio);
1009+
ret = __submit_bio(bio);
9991010
} while ((bio = bio_list_pop(&bio_list[0])));
10001011

10011012
current->bio_list = NULL;
@@ -1013,9 +1024,6 @@ static blk_qc_t __submit_bio_noacct_mq(struct bio *bio)
10131024
*/
10141025
blk_qc_t submit_bio_noacct(struct bio *bio)
10151026
{
1016-
if (!submit_bio_checks(bio))
1017-
return BLK_QC_T_NONE;
1018-
10191027
/*
10201028
* We only want one ->submit_bio to be active at a time, else stack
10211029
* usage with stacked devices could be a problem. Use current->bio_list

block/blk-mq.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,11 @@ void blk_mq_freeze_queue(struct request_queue *q)
188188
}
189189
EXPORT_SYMBOL_GPL(blk_mq_freeze_queue);
190190

191-
void blk_mq_unfreeze_queue(struct request_queue *q)
191+
void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic)
192192
{
193193
mutex_lock(&q->mq_freeze_lock);
194+
if (force_atomic)
195+
q->q_usage_counter.data->force_atomic = true;
194196
q->mq_freeze_depth--;
195197
WARN_ON_ONCE(q->mq_freeze_depth < 0);
196198
if (!q->mq_freeze_depth) {
@@ -199,6 +201,11 @@ void blk_mq_unfreeze_queue(struct request_queue *q)
199201
}
200202
mutex_unlock(&q->mq_freeze_lock);
201203
}
204+
205+
void blk_mq_unfreeze_queue(struct request_queue *q)
206+
{
207+
__blk_mq_unfreeze_queue(q, false);
208+
}
202209
EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
203210

204211
/*

block/blk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size,
5151
void blk_free_flush_queue(struct blk_flush_queue *q);
5252

5353
void blk_freeze_queue(struct request_queue *q);
54+
void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic);
55+
void blk_queue_start_drain(struct request_queue *q);
5456

5557
#define BIO_INLINE_VECS 4
5658
struct bio_vec *bvec_alloc(mempool_t *pool, unsigned short *nr_vecs,

block/genhd.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/badblocks.h>
2727

2828
#include "blk.h"
29+
#include "blk-rq-qos.h"
2930

3031
static struct kobject *block_depr;
3132

@@ -559,6 +560,8 @@ EXPORT_SYMBOL(device_add_disk);
559560
*/
560561
void del_gendisk(struct gendisk *disk)
561562
{
563+
struct request_queue *q = disk->queue;
564+
562565
might_sleep();
563566

564567
if (WARN_ON_ONCE(!disk_live(disk) && !(disk->flags & GENHD_FL_HIDDEN)))
@@ -575,8 +578,27 @@ void del_gendisk(struct gendisk *disk)
575578
fsync_bdev(disk->part0);
576579
__invalidate_device(disk->part0, true);
577580

581+
/*
582+
* Fail any new I/O.
583+
*/
584+
set_bit(GD_DEAD, &disk->state);
578585
set_capacity(disk, 0);
579586

587+
/*
588+
* Prevent new I/O from crossing bio_queue_enter().
589+
*/
590+
blk_queue_start_drain(q);
591+
blk_mq_freeze_queue_wait(q);
592+
593+
rq_qos_exit(q);
594+
blk_sync_queue(q);
595+
blk_flush_integrity();
596+
/*
597+
* Allow using passthrough request again after the queue is torn down.
598+
*/
599+
blk_queue_flag_clear(QUEUE_FLAG_INIT_DONE, q);
600+
__blk_mq_unfreeze_queue(q, true);
601+
580602
if (!(disk->flags & GENHD_FL_HIDDEN)) {
581603
sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");
582604

@@ -1056,6 +1078,7 @@ static void disk_release(struct device *dev)
10561078
struct gendisk *disk = dev_to_disk(dev);
10571079

10581080
might_sleep();
1081+
WARN_ON_ONCE(disk_live(disk));
10591082

10601083
disk_release_events(disk);
10611084
kfree(disk->random);

0 commit comments

Comments
 (0)