Skip to content

Commit 9035a89

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "It's been a few weeks, so here's a small collection of fixes that should go into the current series. This contains: - NVMe pull request from Christoph, with a few important fixes. - kyber hang fix from Omar. - A blk-throttl fix from Shaohua, fixing a case where we double charge a bio. - Two call_single_data alignment fixes from me, fixing up some unfortunate changes that went into 4.14 without being properly reviewed on the block side (since nobody was CC'ed on the patch...). - A bounce buffer fix in two parts, one from me and one from Ming. - Revert bdi debug error handling patch. It's causing boot issues for some folks, and a week down the line, we're still no closer to a fix. Revert this patch for now until it's figured out, then we can retry for 4.16" * 'for-linus' of git://git.kernel.dk/linux-block: Revert "bdi: add error handle for bdi_debug_register" null_blk: unalign call_single_data block: unalign call_single_data in struct request block-throttle: avoid double charge block: fix blk_rq_append_bio block: don't let passthrough IO go into .make_request_fn() nvme: setup streams after initializing namespace head nvme: check hw sectors before setting chunk sectors nvme: call blk_integrity_unregister after queue is cleaned up nvme-fc: remove double put reference if admin connect fails nvme: set discard_alignment to zero kyber: fix another domain token wait queue hang
2 parents 409232a + 6d0e482 commit 9035a89

File tree

14 files changed

+94
-62
lines changed

14 files changed

+94
-62
lines changed

block/bio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
599599
bio->bi_disk = bio_src->bi_disk;
600600
bio->bi_partno = bio_src->bi_partno;
601601
bio_set_flag(bio, BIO_CLONED);
602+
if (bio_flagged(bio_src, BIO_THROTTLED))
603+
bio_set_flag(bio, BIO_THROTTLED);
602604
bio->bi_opf = bio_src->bi_opf;
603605
bio->bi_write_hint = bio_src->bi_write_hint;
604606
bio->bi_iter = bio_src->bi_iter;

block/blk-map.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,29 @@
1212
#include "blk.h"
1313

1414
/*
15-
* Append a bio to a passthrough request. Only works can be merged into
16-
* the request based on the driver constraints.
15+
* Append a bio to a passthrough request. Only works if the bio can be merged
16+
* into the request based on the driver constraints.
1717
*/
18-
int blk_rq_append_bio(struct request *rq, struct bio *bio)
18+
int blk_rq_append_bio(struct request *rq, struct bio **bio)
1919
{
20-
blk_queue_bounce(rq->q, &bio);
20+
struct bio *orig_bio = *bio;
21+
22+
blk_queue_bounce(rq->q, bio);
2123

2224
if (!rq->bio) {
23-
blk_rq_bio_prep(rq->q, rq, bio);
25+
blk_rq_bio_prep(rq->q, rq, *bio);
2426
} else {
25-
if (!ll_back_merge_fn(rq->q, rq, bio))
27+
if (!ll_back_merge_fn(rq->q, rq, *bio)) {
28+
if (orig_bio != *bio) {
29+
bio_put(*bio);
30+
*bio = orig_bio;
31+
}
2632
return -EINVAL;
33+
}
2734

28-
rq->biotail->bi_next = bio;
29-
rq->biotail = bio;
30-
rq->__data_len += bio->bi_iter.bi_size;
35+
rq->biotail->bi_next = *bio;
36+
rq->biotail = *bio;
37+
rq->__data_len += (*bio)->bi_iter.bi_size;
3138
}
3239

3340
return 0;
@@ -73,14 +80,12 @@ static int __blk_rq_map_user_iov(struct request *rq,
7380
* We link the bounce buffer in and could have to traverse it
7481
* later so we have to get a ref to prevent it from being freed
7582
*/
76-
ret = blk_rq_append_bio(rq, bio);
77-
bio_get(bio);
83+
ret = blk_rq_append_bio(rq, &bio);
7884
if (ret) {
79-
bio_endio(bio);
8085
__blk_rq_unmap_user(orig_bio);
81-
bio_put(bio);
8286
return ret;
8387
}
88+
bio_get(bio);
8489

8590
return 0;
8691
}
@@ -213,7 +218,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
213218
int reading = rq_data_dir(rq) == READ;
214219
unsigned long addr = (unsigned long) kbuf;
215220
int do_copy = 0;
216-
struct bio *bio;
221+
struct bio *bio, *orig_bio;
217222
int ret;
218223

219224
if (len > (queue_max_hw_sectors(q) << 9))
@@ -236,10 +241,11 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
236241
if (do_copy)
237242
rq->rq_flags |= RQF_COPY_USER;
238243

239-
ret = blk_rq_append_bio(rq, bio);
244+
orig_bio = bio;
245+
ret = blk_rq_append_bio(rq, &bio);
240246
if (unlikely(ret)) {
241247
/* request is too big */
242-
bio_put(bio);
248+
bio_put(orig_bio);
243249
return ret;
244250
}
245251

block/blk-throttle.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,13 +2226,7 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
22262226
out_unlock:
22272227
spin_unlock_irq(q->queue_lock);
22282228
out:
2229-
/*
2230-
* As multiple blk-throtls may stack in the same issue path, we
2231-
* don't want bios to leave with the flag set. Clear the flag if
2232-
* being issued.
2233-
*/
2234-
if (!throttled)
2235-
bio_clear_flag(bio, BIO_THROTTLED);
2229+
bio_set_flag(bio, BIO_THROTTLED);
22362230

22372231
#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
22382232
if (throttled || !td->track_bio_latency)

block/bounce.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
200200
unsigned i = 0;
201201
bool bounce = false;
202202
int sectors = 0;
203+
bool passthrough = bio_is_passthrough(*bio_orig);
203204

204205
bio_for_each_segment(from, *bio_orig, iter) {
205206
if (i++ < BIO_MAX_PAGES)
@@ -210,13 +211,14 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
210211
if (!bounce)
211212
return;
212213

213-
if (sectors < bio_sectors(*bio_orig)) {
214+
if (!passthrough && sectors < bio_sectors(*bio_orig)) {
214215
bio = bio_split(*bio_orig, sectors, GFP_NOIO, bounce_bio_split);
215216
bio_chain(bio, *bio_orig);
216217
generic_make_request(*bio_orig);
217218
*bio_orig = bio;
218219
}
219-
bio = bio_clone_bioset(*bio_orig, GFP_NOIO, bounce_bio_set);
220+
bio = bio_clone_bioset(*bio_orig, GFP_NOIO, passthrough ? NULL :
221+
bounce_bio_set);
220222

221223
bio_for_each_segment_all(to, bio, i) {
222224
struct page *page = to->bv_page;

block/kyber-iosched.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ struct kyber_hctx_data {
100100
unsigned int cur_domain;
101101
unsigned int batching;
102102
wait_queue_entry_t domain_wait[KYBER_NUM_DOMAINS];
103+
struct sbq_wait_state *domain_ws[KYBER_NUM_DOMAINS];
103104
atomic_t wait_index[KYBER_NUM_DOMAINS];
104105
};
105106

107+
static int kyber_domain_wake(wait_queue_entry_t *wait, unsigned mode, int flags,
108+
void *key);
109+
106110
static int rq_sched_domain(const struct request *rq)
107111
{
108112
unsigned int op = rq->cmd_flags;
@@ -385,6 +389,9 @@ static int kyber_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
385389

386390
for (i = 0; i < KYBER_NUM_DOMAINS; i++) {
387391
INIT_LIST_HEAD(&khd->rqs[i]);
392+
init_waitqueue_func_entry(&khd->domain_wait[i],
393+
kyber_domain_wake);
394+
khd->domain_wait[i].private = hctx;
388395
INIT_LIST_HEAD(&khd->domain_wait[i].entry);
389396
atomic_set(&khd->wait_index[i], 0);
390397
}
@@ -524,35 +531,39 @@ static int kyber_get_domain_token(struct kyber_queue_data *kqd,
524531
int nr;
525532

526533
nr = __sbitmap_queue_get(domain_tokens);
527-
if (nr >= 0)
528-
return nr;
529534

530535
/*
531536
* If we failed to get a domain token, make sure the hardware queue is
532537
* run when one becomes available. Note that this is serialized on
533538
* khd->lock, but we still need to be careful about the waker.
534539
*/
535-
if (list_empty_careful(&wait->entry)) {
536-
init_waitqueue_func_entry(wait, kyber_domain_wake);
537-
wait->private = hctx;
540+
if (nr < 0 && list_empty_careful(&wait->entry)) {
538541
ws = sbq_wait_ptr(domain_tokens,
539542
&khd->wait_index[sched_domain]);
543+
khd->domain_ws[sched_domain] = ws;
540544
add_wait_queue(&ws->wait, wait);
541545

542546
/*
543547
* Try again in case a token was freed before we got on the wait
544-
* queue. The waker may have already removed the entry from the
545-
* wait queue, but list_del_init() is okay with that.
548+
* queue.
546549
*/
547550
nr = __sbitmap_queue_get(domain_tokens);
548-
if (nr >= 0) {
549-
unsigned long flags;
551+
}
550552

551-
spin_lock_irqsave(&ws->wait.lock, flags);
552-
list_del_init(&wait->entry);
553-
spin_unlock_irqrestore(&ws->wait.lock, flags);
554-
}
553+
/*
554+
* If we got a token while we were on the wait queue, remove ourselves
555+
* from the wait queue to ensure that all wake ups make forward
556+
* progress. It's possible that the waker already deleted the entry
557+
* between the !list_empty_careful() check and us grabbing the lock, but
558+
* list_del_init() is okay with that.
559+
*/
560+
if (nr >= 0 && !list_empty_careful(&wait->entry)) {
561+
ws = khd->domain_ws[sched_domain];
562+
spin_lock_irq(&ws->wait.lock);
563+
list_del_init(&wait->entry);
564+
spin_unlock_irq(&ws->wait.lock);
555565
}
566+
556567
return nr;
557568
}
558569

drivers/block/null_blk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ static inline u64 mb_per_tick(int mbps)
3535
struct nullb_cmd {
3636
struct list_head list;
3737
struct llist_node ll_list;
38-
call_single_data_t csd;
38+
struct __call_single_data csd;
3939
struct request *rq;
4040
struct bio *bio;
4141
unsigned int tag;
42+
blk_status_t error;
4243
struct nullb_queue *nq;
4344
struct hrtimer timer;
44-
blk_status_t error;
4545
};
4646

4747
struct nullb_queue {

drivers/nvme/host/core.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ static void nvme_config_discard(struct nvme_ctrl *ctrl,
12871287
BUILD_BUG_ON(PAGE_SIZE / sizeof(struct nvme_dsm_range) <
12881288
NVME_DSM_MAX_RANGES);
12891289

1290-
queue->limits.discard_alignment = size;
1290+
queue->limits.discard_alignment = 0;
12911291
queue->limits.discard_granularity = size;
12921292

12931293
blk_queue_max_discard_sectors(queue, UINT_MAX);
@@ -1705,7 +1705,8 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
17051705
blk_queue_max_hw_sectors(q, ctrl->max_hw_sectors);
17061706
blk_queue_max_segments(q, min_t(u32, max_segments, USHRT_MAX));
17071707
}
1708-
if (ctrl->quirks & NVME_QUIRK_STRIPE_SIZE)
1708+
if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) &&
1709+
is_power_of_2(ctrl->max_hw_sectors))
17091710
blk_queue_chunk_sectors(q, ctrl->max_hw_sectors);
17101711
blk_queue_virt_boundary(q, ctrl->page_size - 1);
17111712
if (ctrl->vwc & NVME_CTRL_VWC_PRESENT)
@@ -2869,7 +2870,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
28692870

28702871
blk_queue_logical_block_size(ns->queue, 1 << ns->lba_shift);
28712872
nvme_set_queue_limits(ctrl, ns->queue);
2872-
nvme_setup_streams_ns(ctrl, ns);
28732873

28742874
id = nvme_identify_ns(ctrl, nsid);
28752875
if (!id)
@@ -2880,6 +2880,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
28802880

28812881
if (nvme_init_ns_head(ns, nsid, id, &new))
28822882
goto out_free_id;
2883+
nvme_setup_streams_ns(ctrl, ns);
28832884

28842885
#ifdef CONFIG_NVME_MULTIPATH
28852886
/*
@@ -2965,15 +2966,15 @@ static void nvme_ns_remove(struct nvme_ns *ns)
29652966
return;
29662967

29672968
if (ns->disk && ns->disk->flags & GENHD_FL_UP) {
2968-
if (blk_get_integrity(ns->disk))
2969-
blk_integrity_unregister(ns->disk);
29702969
nvme_mpath_remove_disk_links(ns);
29712970
sysfs_remove_group(&disk_to_dev(ns->disk)->kobj,
29722971
&nvme_ns_id_attr_group);
29732972
if (ns->ndev)
29742973
nvme_nvm_unregister_sysfs(ns);
29752974
del_gendisk(ns->disk);
29762975
blk_cleanup_queue(ns->queue);
2976+
if (blk_get_integrity(ns->disk))
2977+
blk_integrity_unregister(ns->disk);
29772978
}
29782979

29792980
mutex_lock(&ns->ctrl->subsys->lock);

drivers/nvme/host/fc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3221,7 +3221,6 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
32213221

32223222
/* initiate nvme ctrl ref counting teardown */
32233223
nvme_uninit_ctrl(&ctrl->ctrl);
3224-
nvme_put_ctrl(&ctrl->ctrl);
32253224

32263225
/* Remove core ctrl ref. */
32273226
nvme_put_ctrl(&ctrl->ctrl);

drivers/scsi/osd/osd_initiator.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,9 @@ static struct request *_make_request(struct request_queue *q, bool has_write,
15761576
return req;
15771577

15781578
for_each_bio(bio) {
1579-
ret = blk_rq_append_bio(req, bio);
1579+
struct bio *bounce_bio = bio;
1580+
1581+
ret = blk_rq_append_bio(req, &bounce_bio);
15801582
if (ret)
15811583
return ERR_PTR(ret);
15821584
}

drivers/target/target_core_pscsi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
920920
" %d i: %d bio: %p, allocating another"
921921
" bio\n", bio->bi_vcnt, i, bio);
922922

923-
rc = blk_rq_append_bio(req, bio);
923+
rc = blk_rq_append_bio(req, &bio);
924924
if (rc) {
925925
pr_err("pSCSI: failed to append bio\n");
926926
goto fail;
@@ -938,7 +938,7 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
938938
}
939939

940940
if (bio) {
941-
rc = blk_rq_append_bio(req, bio);
941+
rc = blk_rq_append_bio(req, &bio);
942942
if (rc) {
943943
pr_err("pSCSI: failed to append bio\n");
944944
goto fail;

include/linux/bio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ extern unsigned int bvec_nr_vecs(unsigned short idx);
492492

493493
#define bio_set_dev(bio, bdev) \
494494
do { \
495+
if ((bio)->bi_disk != (bdev)->bd_disk) \
496+
bio_clear_flag(bio, BIO_THROTTLED);\
495497
(bio)->bi_disk = (bdev)->bd_disk; \
496498
(bio)->bi_partno = (bdev)->bd_partno; \
497499
} while (0)

include/linux/blk_types.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ struct blk_issue_stat {
5050
struct bio {
5151
struct bio *bi_next; /* request queue link */
5252
struct gendisk *bi_disk;
53-
u8 bi_partno;
54-
blk_status_t bi_status;
5553
unsigned int bi_opf; /* bottom bits req flags,
5654
* top bits REQ_OP. Use
5755
* accessors.
5856
*/
5957
unsigned short bi_flags; /* status, etc and bvec pool number */
6058
unsigned short bi_ioprio;
6159
unsigned short bi_write_hint;
62-
63-
struct bvec_iter bi_iter;
60+
blk_status_t bi_status;
61+
u8 bi_partno;
6462

6563
/* Number of segments in this BIO after
6664
* physical address coalescing is performed.
@@ -74,8 +72,9 @@ struct bio {
7472
unsigned int bi_seg_front_size;
7573
unsigned int bi_seg_back_size;
7674

77-
atomic_t __bi_remaining;
75+
struct bvec_iter bi_iter;
7876

77+
atomic_t __bi_remaining;
7978
bio_end_io_t *bi_end_io;
8079

8180
void *bi_private;

0 commit comments

Comments
 (0)