Skip to content

Commit 75f64f6

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "A selection of fixes/changes that should make it into this series. This contains: - NVMe, two merges, containing: - pci-e, rdma, and fc fixes - Device quirks - Fix for a badblocks leak in null_blk - bcache fix from Rui Hua for a race condition regression where -EINTR was returned to upper layers that didn't expect it. - Regression fix for blktrace for a bug introduced in this series. - blktrace cleanup for cgroup id. - bdi registration error handling. - Small series with cleanups for blk-wbt. - Various little fixes for typos and the like. Nothing earth shattering, most important are the NVMe and bcache fixes" * 'for-linus' of git://git.kernel.dk/linux-block: (34 commits) nvme-pci: fix NULL pointer dereference in nvme_free_host_mem() nvme-rdma: fix memory leak during queue allocation blktrace: fix trace mutex deadlock nvme-rdma: Use mr pool nvme-rdma: Check remotely invalidated rkey matches our expected rkey nvme-rdma: wait for local invalidation before completing a request nvme-rdma: don't complete requests before a send work request has completed nvme-rdma: don't suppress send completions bcache: check return value of register_shrinker bcache: recover data from backing when data is clean bcache: Fix building error on MIPS bcache: add a comment in journal bucket reading nvme-fc: don't use bit masks for set/test_bit() numbers blk-wbt: fix comments typo blk-wbt: move wbt_clear_stat to common place in wbt_done blk-sysfs: remove NULL pointer checking in queue_wb_lat_store blk-wbt: remove duplicated setting in wbt_init nvme-pci: add quirk for delay before CHK RDY for WDC SN200 block: remove useless assignment in bio_split null_blk: fix dev->badblocks leak ...
2 parents df8ba95 + ed56537 commit 75f64f6

File tree

22 files changed

+291
-211
lines changed

22 files changed

+291
-211
lines changed

block/bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ EXPORT_SYMBOL(bio_endio);
18191819
struct bio *bio_split(struct bio *bio, int sectors,
18201820
gfp_t gfp, struct bio_set *bs)
18211821
{
1822-
struct bio *split = NULL;
1822+
struct bio *split;
18231823

18241824
BUG_ON(sectors <= 0);
18251825
BUG_ON(sectors >= bio_sectors(bio));

block/blk-sysfs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,9 @@ static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
450450
ret = wbt_init(q);
451451
if (ret)
452452
return ret;
453-
454-
rwb = q->rq_wb;
455-
if (!rwb)
456-
return -EINVAL;
457453
}
458454

455+
rwb = q->rq_wb;
459456
if (val == -1)
460457
rwb->min_lat_nsec = wbt_default_latency_nsec(q);
461458
else if (val >= 0)

block/blk-wbt.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,11 @@ void wbt_done(struct rq_wb *rwb, struct blk_issue_stat *stat)
178178

179179
if (wbt_is_read(stat))
180180
wb_timestamp(rwb, &rwb->last_comp);
181-
wbt_clear_state(stat);
182181
} else {
183182
WARN_ON_ONCE(stat == rwb->sync_cookie);
184183
__wbt_done(rwb, wbt_stat_to_mask(stat));
185-
wbt_clear_state(stat);
186184
}
185+
wbt_clear_state(stat);
187186
}
188187

189188
/*
@@ -482,7 +481,7 @@ static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw)
482481

483482
/*
484483
* At this point we know it's a buffered write. If this is
485-
* kswapd trying to free memory, or REQ_SYNC is set, set, then
484+
* kswapd trying to free memory, or REQ_SYNC is set, then
486485
* it's WB_SYNC_ALL writeback, and we'll use the max limit for
487486
* that. If the write is marked as a background write, then use
488487
* the idle limit, or go to normal if we haven't had competing
@@ -723,8 +722,6 @@ int wbt_init(struct request_queue *q)
723722
init_waitqueue_head(&rwb->rq_wait[i].wait);
724723
}
725724

726-
rwb->wc = 1;
727-
rwb->queue_depth = RWB_DEF_DEPTH;
728725
rwb->last_comp = rwb->last_issue = jiffies;
729726
rwb->queue = q;
730727
rwb->win_nsec = RWB_WINDOW_NSEC;

block/genhd.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,13 @@ void device_add_disk(struct device *parent, struct gendisk *disk)
671671
disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO;
672672
disk->flags |= GENHD_FL_NO_PART_SCAN;
673673
} else {
674+
int ret;
675+
674676
/* Register BDI before referencing it from bdev */
675677
disk_to_dev(disk)->devt = devt;
676-
bdi_register_owner(disk->queue->backing_dev_info,
677-
disk_to_dev(disk));
678+
ret = bdi_register_owner(disk->queue->backing_dev_info,
679+
disk_to_dev(disk));
680+
WARN_ON(ret);
678681
blk_register_region(disk_devt(disk), disk->minors, NULL,
679682
exact_match, exact_lock, disk);
680683
}
@@ -1389,7 +1392,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
13891392

13901393
if (minors > DISK_MAX_PARTS) {
13911394
printk(KERN_ERR
1392-
"block: can't allocated more than %d partitions\n",
1395+
"block: can't allocate more than %d partitions\n",
13931396
DISK_MAX_PARTS);
13941397
minors = DISK_MAX_PARTS;
13951398
}

drivers/block/null_blk.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ static void nullb_device_release(struct config_item *item)
471471
{
472472
struct nullb_device *dev = to_nullb_device(item);
473473

474-
badblocks_exit(&dev->badblocks);
475474
null_free_device_storage(dev, false);
476475
null_free_dev(dev);
477476
}
@@ -582,6 +581,10 @@ static struct nullb_device *null_alloc_dev(void)
582581

583582
static void null_free_dev(struct nullb_device *dev)
584583
{
584+
if (!dev)
585+
return;
586+
587+
badblocks_exit(&dev->badblocks);
585588
kfree(dev);
586589
}
587590

drivers/md/bcache/alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned reserve,
490490
if (b == -1)
491491
goto err;
492492

493-
k->ptr[i] = PTR(ca->buckets[b].gen,
493+
k->ptr[i] = MAKE_PTR(ca->buckets[b].gen,
494494
bucket_to_sector(c, b),
495495
ca->sb.nr_this_dev);
496496

drivers/md/bcache/btree.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,10 @@ int bch_btree_cache_alloc(struct cache_set *c)
807807
c->shrink.scan_objects = bch_mca_scan;
808808
c->shrink.seeks = 4;
809809
c->shrink.batch = c->btree_pages * 2;
810-
register_shrinker(&c->shrink);
810+
811+
if (register_shrinker(&c->shrink))
812+
pr_warn("bcache: %s: could not register shrinker",
813+
__func__);
811814

812815
return 0;
813816
}

drivers/md/bcache/extents.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ static bool bch_extent_merge(struct btree_keys *bk, struct bkey *l, struct bkey
585585
return false;
586586

587587
for (i = 0; i < KEY_PTRS(l); i++)
588-
if (l->ptr[i] + PTR(0, KEY_SIZE(l), 0) != r->ptr[i] ||
588+
if (l->ptr[i] + MAKE_PTR(0, KEY_SIZE(l), 0) != r->ptr[i] ||
589589
PTR_BUCKET_NR(b->c, l, i) != PTR_BUCKET_NR(b->c, r, i))
590590
return false;
591591

drivers/md/bcache/journal.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ int bch_journal_read(struct cache_set *c, struct list_head *list)
170170
* find a sequence of buckets with valid journal entries
171171
*/
172172
for (i = 0; i < ca->sb.njournal_buckets; i++) {
173+
/*
174+
* We must try the index l with ZERO first for
175+
* correctness due to the scenario that the journal
176+
* bucket is circular buffer which might have wrapped
177+
*/
173178
l = (i * 2654435769U) % ca->sb.njournal_buckets;
174179

175180
if (test_bit(l, bitmap))
@@ -507,7 +512,7 @@ static void journal_reclaim(struct cache_set *c)
507512
continue;
508513

509514
ja->cur_idx = next;
510-
k->ptr[n++] = PTR(0,
515+
k->ptr[n++] = MAKE_PTR(0,
511516
bucket_to_sector(c, ca->sb.d[ja->cur_idx]),
512517
ca->sb.nr_this_dev);
513518
}

drivers/md/bcache/request.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -708,16 +708,15 @@ static void cached_dev_read_error(struct closure *cl)
708708
{
709709
struct search *s = container_of(cl, struct search, cl);
710710
struct bio *bio = &s->bio.bio;
711-
struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
712711

713712
/*
714-
* If cache device is dirty (dc->has_dirty is non-zero), then
715-
* recovery a failed read request from cached device may get a
716-
* stale data back. So read failure recovery is only permitted
717-
* when cache device is clean.
713+
* If read request hit dirty data (s->read_dirty_data is true),
714+
* then recovery a failed read request from cached device may
715+
* get a stale data back. So read failure recovery is only
716+
* permitted when read request hit clean data in cache device,
717+
* or when cache read race happened.
718718
*/
719-
if (s->recoverable &&
720-
(dc && !atomic_read(&dc->has_dirty))) {
719+
if (s->recoverable && !s->read_dirty_data) {
721720
/* Retry from the backing device: */
722721
trace_bcache_read_retry(s->orig_bio);
723722

drivers/nvme/host/core.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,19 +1449,19 @@ static int nvme_pr_command(struct block_device *bdev, u32 cdw10,
14491449
int srcu_idx, ret;
14501450
u8 data[16] = { 0, };
14511451

1452+
ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
1453+
if (unlikely(!ns))
1454+
return -EWOULDBLOCK;
1455+
14521456
put_unaligned_le64(key, &data[0]);
14531457
put_unaligned_le64(sa_key, &data[8]);
14541458

14551459
memset(&c, 0, sizeof(c));
14561460
c.common.opcode = op;
1457-
c.common.nsid = cpu_to_le32(head->ns_id);
1461+
c.common.nsid = cpu_to_le32(ns->head->ns_id);
14581462
c.common.cdw10[0] = cpu_to_le32(cdw10);
14591463

1460-
ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
1461-
if (unlikely(!ns))
1462-
ret = -EWOULDBLOCK;
1463-
else
1464-
ret = nvme_submit_sync_cmd(ns->queue, &c, data, 16);
1464+
ret = nvme_submit_sync_cmd(ns->queue, &c, data, 16);
14651465
nvme_put_ns_from_disk(head, srcu_idx);
14661466
return ret;
14671467
}
@@ -2961,8 +2961,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
29612961

29622962
static void nvme_ns_remove(struct nvme_ns *ns)
29632963
{
2964-
struct nvme_ns_head *head = ns->head;
2965-
29662964
if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
29672965
return;
29682966

@@ -2980,15 +2978,14 @@ static void nvme_ns_remove(struct nvme_ns *ns)
29802978

29812979
mutex_lock(&ns->ctrl->subsys->lock);
29822980
nvme_mpath_clear_current_path(ns);
2983-
if (head)
2984-
list_del_rcu(&ns->siblings);
2981+
list_del_rcu(&ns->siblings);
29852982
mutex_unlock(&ns->ctrl->subsys->lock);
29862983

29872984
mutex_lock(&ns->ctrl->namespaces_mutex);
29882985
list_del_init(&ns->list);
29892986
mutex_unlock(&ns->ctrl->namespaces_mutex);
29902987

2991-
synchronize_srcu(&head->srcu);
2988+
synchronize_srcu(&ns->head->srcu);
29922989
nvme_put_ns(ns);
29932990
}
29942991

drivers/nvme/host/fabrics.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,34 @@ void nvmf_free_options(struct nvmf_ctrl_options *opts);
156156
int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size);
157157
bool nvmf_should_reconnect(struct nvme_ctrl *ctrl);
158158

159+
static inline blk_status_t nvmf_check_init_req(struct nvme_ctrl *ctrl,
160+
struct request *rq)
161+
{
162+
struct nvme_command *cmd = nvme_req(rq)->cmd;
163+
164+
/*
165+
* We cannot accept any other command until the connect command has
166+
* completed, so only allow connect to pass.
167+
*/
168+
if (!blk_rq_is_passthrough(rq) ||
169+
cmd->common.opcode != nvme_fabrics_command ||
170+
cmd->fabrics.fctype != nvme_fabrics_type_connect) {
171+
/*
172+
* Reconnecting state means transport disruption, which can take
173+
* a long time and even might fail permanently, fail fast to
174+
* give upper layers a chance to failover.
175+
* Deleting state means that the ctrl will never accept commands
176+
* again, fail it permanently.
177+
*/
178+
if (ctrl->state == NVME_CTRL_RECONNECTING ||
179+
ctrl->state == NVME_CTRL_DELETING) {
180+
nvme_req(rq)->status = NVME_SC_ABORT_REQ;
181+
return BLK_STS_IOERR;
182+
}
183+
return BLK_STS_RESOURCE; /* try again later */
184+
}
185+
186+
return BLK_STS_OK;
187+
}
188+
159189
#endif /* _NVME_FABRICS_H */

drivers/nvme/host/fc.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232

3333
enum nvme_fc_queue_flags {
34-
NVME_FC_Q_CONNECTED = (1 << 0),
34+
NVME_FC_Q_CONNECTED = 0,
35+
NVME_FC_Q_LIVE,
3536
};
3637

3738
#define NVMEFC_QUEUE_DELAY 3 /* ms units */
@@ -1927,14 +1928,14 @@ nvme_fc_free_queue(struct nvme_fc_queue *queue)
19271928
if (!test_and_clear_bit(NVME_FC_Q_CONNECTED, &queue->flags))
19281929
return;
19291930

1931+
clear_bit(NVME_FC_Q_LIVE, &queue->flags);
19301932
/*
19311933
* Current implementation never disconnects a single queue.
19321934
* It always terminates a whole association. So there is never
19331935
* a disconnect(queue) LS sent to the target.
19341936
*/
19351937

19361938
queue->connection_id = 0;
1937-
clear_bit(NVME_FC_Q_CONNECTED, &queue->flags);
19381939
}
19391940

19401941
static void
@@ -2013,6 +2014,8 @@ nvme_fc_connect_io_queues(struct nvme_fc_ctrl *ctrl, u16 qsize)
20132014
ret = nvmf_connect_io_queue(&ctrl->ctrl, i);
20142015
if (ret)
20152016
break;
2017+
2018+
set_bit(NVME_FC_Q_LIVE, &ctrl->queues[i].flags);
20162019
}
20172020

20182021
return ret;
@@ -2320,6 +2323,14 @@ nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
23202323
return BLK_STS_RESOURCE;
23212324
}
23222325

2326+
static inline blk_status_t nvme_fc_is_ready(struct nvme_fc_queue *queue,
2327+
struct request *rq)
2328+
{
2329+
if (unlikely(!test_bit(NVME_FC_Q_LIVE, &queue->flags)))
2330+
return nvmf_check_init_req(&queue->ctrl->ctrl, rq);
2331+
return BLK_STS_OK;
2332+
}
2333+
23232334
static blk_status_t
23242335
nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
23252336
const struct blk_mq_queue_data *bd)
@@ -2335,6 +2346,10 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
23352346
u32 data_len;
23362347
blk_status_t ret;
23372348

2349+
ret = nvme_fc_is_ready(queue, rq);
2350+
if (unlikely(ret))
2351+
return ret;
2352+
23382353
ret = nvme_setup_cmd(ns, rq, sqe);
23392354
if (ret)
23402355
return ret;
@@ -2727,6 +2742,8 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
27272742
if (ret)
27282743
goto out_disconnect_admin_queue;
27292744

2745+
set_bit(NVME_FC_Q_LIVE, &ctrl->queues[0].flags);
2746+
27302747
/*
27312748
* Check controller capabilities
27322749
*

drivers/nvme/host/multipath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static blk_qc_t nvme_ns_head_make_request(struct request_queue *q,
131131
bio->bi_opf |= REQ_NVME_MPATH;
132132
ret = direct_make_request(bio);
133133
} else if (!list_empty_careful(&head->list)) {
134-
dev_warn_ratelimited(dev, "no path available - requeing I/O\n");
134+
dev_warn_ratelimited(dev, "no path available - requeuing I/O\n");
135135

136136
spin_lock_irq(&head->requeue_lock);
137137
bio_list_add(&head->requeue_list, bio);

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static inline struct nvme_request *nvme_req(struct request *req)
114114
* NVME_QUIRK_DELAY_BEFORE_CHK_RDY quirk enabled. The value (in ms) was
115115
* found empirically.
116116
*/
117-
#define NVME_QUIRK_DELAY_AMOUNT 2000
117+
#define NVME_QUIRK_DELAY_AMOUNT 2300
118118

119119
enum nvme_ctrl_state {
120120
NVME_CTRL_NEW,

0 commit comments

Comments
 (0)