Skip to content

Commit fff648d

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "Here's the second round of block updates for this merge window. It's a mix of fixes for changes that went in previously in this round, and fixes in general. This pull request contains: - Fixes for loop from Christoph - A bdi vs gendisk lifetime fix from Dan, worth two cookies. - A blk-mq timeout fix, when on frozen queues. From Gabriel. - Writeback fix from Jan, ensuring that __writeback_single_inode() does the right thing. - Fix for bio->bi_rw usage in f2fs from me. - Error path deadlock fix in blk-mq sysfs registration from me. - Floppy O_ACCMODE fix from Jiri. - Fix to the new bio op methods from Mike. One more followup will be coming here, ensuring that we don't propagate the block types outside of block. That, and a rename of bio->bi_rw is coming right after -rc1 is cut. - Various little fixes" * 'for-linus' of git://git.kernel.dk/linux-block: mm/block: convert rw_page users to bio op use loop: make do_req_filebacked more robust loop: don't try to use AIO for discards blk-mq: fix deadlock in blk_mq_register_disk() error path Include: blkdev: Removed duplicate 'struct request;' declaration. Fixup direct bi_rw modifiers block: fix bdi vs gendisk lifetime mismatch blk-mq: Allow timeouts to run while queue is freezing nbd: fix race in ioctl block: fix use-after-free in seq file f2fs: drop bio->bi_rw manual assignment block: add missing group association in bio-cloning functions blkcg: kill unused field nr_undestroyed_grps writeback: Write dirty times for WB_SYNC_ALL writeback floppy: fix open(O_ACCMODE) for ioctl-only open
2 parents 62e6e9b + abf5454 commit fff648d

26 files changed

+168
-136
lines changed

block/bio.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
583583
bio->bi_rw = bio_src->bi_rw;
584584
bio->bi_iter = bio_src->bi_iter;
585585
bio->bi_io_vec = bio_src->bi_io_vec;
586+
587+
bio_clone_blkcg_association(bio, bio_src);
586588
}
587589
EXPORT_SYMBOL(__bio_clone_fast);
588590

@@ -687,6 +689,8 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,
687689
}
688690
}
689691

692+
bio_clone_blkcg_association(bio, bio_src);
693+
690694
return bio;
691695
}
692696
EXPORT_SYMBOL(bio_clone_bioset);
@@ -2004,6 +2008,17 @@ void bio_disassociate_task(struct bio *bio)
20042008
}
20052009
}
20062010

2011+
/**
2012+
* bio_clone_blkcg_association - clone blkcg association from src to dst bio
2013+
* @dst: destination bio
2014+
* @src: source bio
2015+
*/
2016+
void bio_clone_blkcg_association(struct bio *dst, struct bio *src)
2017+
{
2018+
if (src->bi_css)
2019+
WARN_ON(bio_associate_blkcg(dst, src->bi_css));
2020+
}
2021+
20072022
#endif /* CONFIG_BLK_CGROUP */
20082023

20092024
static void __init biovec_init_slabs(void)

block/blk-mq-sysfs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,13 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
380380
return ret;
381381
}
382382

383-
void blk_mq_unregister_disk(struct gendisk *disk)
383+
static void __blk_mq_unregister_disk(struct gendisk *disk)
384384
{
385385
struct request_queue *q = disk->queue;
386386
struct blk_mq_hw_ctx *hctx;
387387
struct blk_mq_ctx *ctx;
388388
int i, j;
389389

390-
blk_mq_disable_hotplug();
391-
392390
queue_for_each_hw_ctx(q, hctx, i) {
393391
blk_mq_unregister_hctx(hctx);
394392

@@ -405,6 +403,12 @@ void blk_mq_unregister_disk(struct gendisk *disk)
405403
kobject_put(&disk_to_dev(disk)->kobj);
406404

407405
q->mq_sysfs_init_done = false;
406+
}
407+
408+
void blk_mq_unregister_disk(struct gendisk *disk)
409+
{
410+
blk_mq_disable_hotplug();
411+
__blk_mq_unregister_disk(disk);
408412
blk_mq_enable_hotplug();
409413
}
410414

@@ -450,7 +454,7 @@ int blk_mq_register_disk(struct gendisk *disk)
450454
}
451455

452456
if (ret)
453-
blk_mq_unregister_disk(disk);
457+
__blk_mq_unregister_disk(disk);
454458
else
455459
q->mq_sysfs_init_done = true;
456460
out:

block/blk-mq.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,20 @@ static void blk_mq_timeout_work(struct work_struct *work)
672672
};
673673
int i;
674674

675-
if (blk_queue_enter(q, true))
675+
/* A deadlock might occur if a request is stuck requiring a
676+
* timeout at the same time a queue freeze is waiting
677+
* completion, since the timeout code would not be able to
678+
* acquire the queue reference here.
679+
*
680+
* That's why we don't use blk_queue_enter here; instead, we use
681+
* percpu_ref_tryget directly, because we need to be able to
682+
* obtain a reference even in the short window between the queue
683+
* starting to freeze, by dropping the first reference in
684+
* blk_mq_freeze_queue_start, and the moment the last request is
685+
* consumed, marked by the instant q_usage_counter reaches
686+
* zero.
687+
*/
688+
if (!percpu_ref_tryget(&q->q_usage_counter))
676689
return;
677690

678691
blk_mq_queue_tag_busy_iter(q, blk_mq_check_expired, &data);

block/blk-throttle.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ struct throtl_data
145145
/* Total Number of queued bios on READ and WRITE lists */
146146
unsigned int nr_queued[2];
147147

148-
/*
149-
* number of total undestroyed groups
150-
*/
151-
unsigned int nr_undestroyed_grps;
152-
153148
/* Work for dispatching throttled bios */
154149
struct work_struct dispatch_work;
155150
};

block/genhd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ void device_add_disk(struct device *parent, struct gendisk *disk)
614614

615615
/* Register BDI before referencing it from bdev */
616616
bdi = &disk->queue->backing_dev_info;
617-
bdi_register_dev(bdi, disk_devt(disk));
617+
bdi_register_owner(bdi, disk_to_dev(disk));
618618

619619
blk_register_region(disk_devt(disk), disk->minors, NULL,
620620
exact_match, exact_lock, disk);
@@ -856,6 +856,7 @@ static void disk_seqf_stop(struct seq_file *seqf, void *v)
856856
if (iter) {
857857
class_dev_iter_exit(iter);
858858
kfree(iter);
859+
seqf->private = NULL;
859860
}
860861
}
861862

drivers/block/brd.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,20 @@ static void copy_from_brd(void *dst, struct brd_device *brd,
300300
* Process a single bvec of a bio.
301301
*/
302302
static int brd_do_bvec(struct brd_device *brd, struct page *page,
303-
unsigned int len, unsigned int off, int rw,
303+
unsigned int len, unsigned int off, int op,
304304
sector_t sector)
305305
{
306306
void *mem;
307307
int err = 0;
308308

309-
if (rw != READ) {
309+
if (op_is_write(op)) {
310310
err = copy_to_brd_setup(brd, sector, len);
311311
if (err)
312312
goto out;
313313
}
314314

315315
mem = kmap_atomic(page);
316-
if (rw == READ) {
316+
if (!op_is_write(op)) {
317317
copy_from_brd(mem + off, brd, sector, len);
318318
flush_dcache_page(page);
319319
} else {
@@ -330,7 +330,6 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
330330
{
331331
struct block_device *bdev = bio->bi_bdev;
332332
struct brd_device *brd = bdev->bd_disk->private_data;
333-
int rw;
334333
struct bio_vec bvec;
335334
sector_t sector;
336335
struct bvec_iter iter;
@@ -347,14 +346,12 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
347346
goto out;
348347
}
349348

350-
rw = bio_data_dir(bio);
351-
352349
bio_for_each_segment(bvec, bio, iter) {
353350
unsigned int len = bvec.bv_len;
354351
int err;
355352

356353
err = brd_do_bvec(brd, bvec.bv_page, len,
357-
bvec.bv_offset, rw, sector);
354+
bvec.bv_offset, bio_op(bio), sector);
358355
if (err)
359356
goto io_error;
360357
sector += len >> SECTOR_SHIFT;
@@ -369,11 +366,11 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
369366
}
370367

371368
static int brd_rw_page(struct block_device *bdev, sector_t sector,
372-
struct page *page, int rw)
369+
struct page *page, int op)
373370
{
374371
struct brd_device *brd = bdev->bd_disk->private_data;
375-
int err = brd_do_bvec(brd, page, PAGE_SIZE, 0, rw, sector);
376-
page_endio(page, rw & WRITE, err);
372+
int err = brd_do_bvec(brd, page, PAGE_SIZE, 0, op, sector);
373+
page_endio(page, op, err);
377374
return err;
378375
}
379376

drivers/block/floppy.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,11 +3663,6 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
36633663

36643664
opened_bdev[drive] = bdev;
36653665

3666-
if (!(mode & (FMODE_READ|FMODE_WRITE))) {
3667-
res = -EINVAL;
3668-
goto out;
3669-
}
3670-
36713666
res = -ENXIO;
36723667

36733668
if (!floppy_track_buffer) {
@@ -3711,13 +3706,15 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
37113706
if (UFDCS->rawcmd == 1)
37123707
UFDCS->rawcmd = 2;
37133708

3714-
UDRS->last_checked = 0;
3715-
clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
3716-
check_disk_change(bdev);
3717-
if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
3718-
goto out;
3719-
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
3720-
goto out;
3709+
if (mode & (FMODE_READ|FMODE_WRITE)) {
3710+
UDRS->last_checked = 0;
3711+
clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
3712+
check_disk_change(bdev);
3713+
if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
3714+
goto out;
3715+
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
3716+
goto out;
3717+
}
37213718

37223719
res = -EROFS;
37233720

drivers/block/loop.c

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
510510
return 0;
511511
}
512512

513-
514-
static inline int lo_rw_simple(struct loop_device *lo,
515-
struct request *rq, loff_t pos, bool rw)
513+
static int do_req_filebacked(struct loop_device *lo, struct request *rq)
516514
{
517515
struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
518-
519-
if (cmd->use_aio)
520-
return lo_rw_aio(lo, cmd, pos, rw);
516+
loff_t pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
521517

522518
/*
523519
* lo_write_simple and lo_read_simple should have been covered
@@ -528,37 +524,30 @@ static inline int lo_rw_simple(struct loop_device *lo,
528524
* of the req at one time. And direct read IO doesn't need to
529525
* run flush_dcache_page().
530526
*/
531-
if (rw == WRITE)
532-
return lo_write_simple(lo, rq, pos);
533-
else
534-
return lo_read_simple(lo, rq, pos);
535-
}
536-
537-
static int do_req_filebacked(struct loop_device *lo, struct request *rq)
538-
{
539-
loff_t pos;
540-
int ret;
541-
542-
pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
543-
544-
if (op_is_write(req_op(rq))) {
545-
if (req_op(rq) == REQ_OP_FLUSH)
546-
ret = lo_req_flush(lo, rq);
547-
else if (req_op(rq) == REQ_OP_DISCARD)
548-
ret = lo_discard(lo, rq, pos);
549-
else if (lo->transfer)
550-
ret = lo_write_transfer(lo, rq, pos);
527+
switch (req_op(rq)) {
528+
case REQ_OP_FLUSH:
529+
return lo_req_flush(lo, rq);
530+
case REQ_OP_DISCARD:
531+
return lo_discard(lo, rq, pos);
532+
case REQ_OP_WRITE:
533+
if (lo->transfer)
534+
return lo_write_transfer(lo, rq, pos);
535+
else if (cmd->use_aio)
536+
return lo_rw_aio(lo, cmd, pos, WRITE);
551537
else
552-
ret = lo_rw_simple(lo, rq, pos, WRITE);
553-
554-
} else {
538+
return lo_write_simple(lo, rq, pos);
539+
case REQ_OP_READ:
555540
if (lo->transfer)
556-
ret = lo_read_transfer(lo, rq, pos);
541+
return lo_read_transfer(lo, rq, pos);
542+
else if (cmd->use_aio)
543+
return lo_rw_aio(lo, cmd, pos, READ);
557544
else
558-
ret = lo_rw_simple(lo, rq, pos, READ);
545+
return lo_read_simple(lo, rq, pos);
546+
default:
547+
WARN_ON_ONCE(1);
548+
return -EIO;
549+
break;
559550
}
560-
561-
return ret;
562551
}
563552

564553
struct switch_request {
@@ -1659,11 +1648,15 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
16591648
if (lo->lo_state != Lo_bound)
16601649
return -EIO;
16611650

1662-
if (lo->use_dio && (req_op(cmd->rq) != REQ_OP_FLUSH ||
1663-
req_op(cmd->rq) == REQ_OP_DISCARD))
1664-
cmd->use_aio = true;
1665-
else
1651+
switch (req_op(cmd->rq)) {
1652+
case REQ_OP_FLUSH:
1653+
case REQ_OP_DISCARD:
16661654
cmd->use_aio = false;
1655+
break;
1656+
default:
1657+
cmd->use_aio = lo->use_dio;
1658+
break;
1659+
}
16671660

16681661
queue_kthread_work(&lo->worker, &cmd->work);
16691662

drivers/block/nbd.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,9 @@ static int nbd_thread_recv(struct nbd_device *nbd, struct block_device *bdev)
451451

452452
sk_set_memalloc(nbd->sock->sk);
453453

454-
nbd->task_recv = current;
455-
456454
ret = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
457455
if (ret) {
458456
dev_err(disk_to_dev(nbd->disk), "device_create_file failed!\n");
459-
460-
nbd->task_recv = NULL;
461-
462457
return ret;
463458
}
464459

@@ -477,9 +472,6 @@ static int nbd_thread_recv(struct nbd_device *nbd, struct block_device *bdev)
477472
nbd_size_clear(nbd, bdev);
478473

479474
device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
480-
481-
nbd->task_recv = NULL;
482-
483475
return ret;
484476
}
485477

@@ -788,6 +780,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
788780
if (!nbd->sock)
789781
return -EINVAL;
790782

783+
/* We have to claim the device under the lock */
784+
nbd->task_recv = current;
791785
mutex_unlock(&nbd->tx_lock);
792786

793787
nbd_parse_flags(nbd, bdev);
@@ -796,6 +790,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
796790
nbd_name(nbd));
797791
if (IS_ERR(thread)) {
798792
mutex_lock(&nbd->tx_lock);
793+
nbd->task_recv = NULL;
799794
return PTR_ERR(thread);
800795
}
801796

@@ -805,6 +800,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
805800
kthread_stop(thread);
806801

807802
mutex_lock(&nbd->tx_lock);
803+
nbd->task_recv = NULL;
808804

809805
sock_shutdown(nbd);
810806
nbd_clear_que(nbd);

0 commit comments

Comments
 (0)