aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-04-13 18:15:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-13 18:15:15 -0400
commitedda415314804c29fa07e538938fa07947012d8f (patch)
tree0428db94253f73bb0744f52d26645c33830756f3
parent3e565a351ed3e94352bfbe0be06c659fc8fafb19 (diff)
parentbb06ec31452fb2da1594f88035c2ecea4e0652f4 (diff)
Merge tag 'for-linus-20180413' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "Followup fixes for this merge window. This contains: - Series from Ming, fixing corner cases in our CPU <-> queue mapping. This triggered repeated warnings on especially s390, but I also hit it in cpu hot plug/unplug testing while doing IO on NVMe on x86-64. - Another fix from Ming, ensuring that we always order budget and driver tag identically, avoiding a deadlock on QD=1 devices. - Loop locking regression fix from this merge window, from Omar. - Another loop locking fix, this time missing an unlock, from Tetsuo Handa. - Fix for racing IO submission with device removal from Bart. - sr reference fix from me, fixing a case where disk change or getevents can race with device removal. - Set of nvme fixes by way of Keith, from various contributors" * tag 'for-linus-20180413' of git://git.kernel.dk/linux-block: (28 commits) nvme: expand nvmf_check_if_ready checks nvme: Use admin command effects for admin commands nvmet: fix space padding in serial number nvme: check return value of init_srcu_struct function nvmet: Fix nvmet_execute_write_zeroes sector count nvme-pci: Separate IO and admin queue IRQ vectors nvme-pci: Remove unused queue parameter nvme-pci: Skip queue deletion if there are no queues nvme: target: fix buffer overflow nvme: don't send keep-alives to the discovery controller nvme: unexport nvme_start_keep_alive nvme-loop: fix kernel oops in case of unhandled command nvme: enforce 64bit offset for nvme_get_log_ext fn sr: get/drop reference to device in revalidate and check_events blk-mq: Revert "blk-mq: reimplement blk_mq_hw_queue_mapped" blk-mq: Avoid that submitting a bio concurrently with device removal triggers a crash backing: silence compiler warning using __printf blk-mq: remove code for dealing with remapping queue blk-mq: reimplement blk_mq_hw_queue_mapped blk-mq: don't check queue mapped in __blk_mq_delay_run_hw_queue() ...
-rw-r--r--block/blk-core.c35
-rw-r--r--block/blk-mq-cpumap.c5
-rw-r--r--block/blk-mq-debugfs.c1
-rw-r--r--block/blk-mq.c122
-rw-r--r--drivers/block/loop.c45
-rw-r--r--drivers/nvme/host/core.c33
-rw-r--r--drivers/nvme/host/fabrics.c83
-rw-r--r--drivers/nvme/host/fabrics.h33
-rw-r--r--drivers/nvme/host/fc.c12
-rw-r--r--drivers/nvme/host/nvme.h4
-rw-r--r--drivers/nvme/host/pci.c35
-rw-r--r--drivers/nvme/host/rdma.c14
-rw-r--r--drivers/nvme/target/admin-cmd.c1
-rw-r--r--drivers/nvme/target/discovery.c2
-rw-r--r--drivers/nvme/target/io-cmd.c4
-rw-r--r--drivers/nvme/target/loop.c20
-rw-r--r--drivers/scsi/sr.c19
-rw-r--r--include/linux/backing-dev.h1
-rw-r--r--include/linux/blk-mq.h2
19 files changed, 245 insertions, 226 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index abcb8684ba67..806ce2442819 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -2385,8 +2385,20 @@ blk_qc_t generic_make_request(struct bio *bio)
2385 * yet. 2385 * yet.
2386 */ 2386 */
2387 struct bio_list bio_list_on_stack[2]; 2387 struct bio_list bio_list_on_stack[2];
2388 blk_mq_req_flags_t flags = 0;
2389 struct request_queue *q = bio->bi_disk->queue;
2388 blk_qc_t ret = BLK_QC_T_NONE; 2390 blk_qc_t ret = BLK_QC_T_NONE;
2389 2391
2392 if (bio->bi_opf & REQ_NOWAIT)
2393 flags = BLK_MQ_REQ_NOWAIT;
2394 if (blk_queue_enter(q, flags) < 0) {
2395 if (!blk_queue_dying(q) && (bio->bi_opf & REQ_NOWAIT))
2396 bio_wouldblock_error(bio);
2397 else
2398 bio_io_error(bio);
2399 return ret;
2400 }
2401
2390 if (!generic_make_request_checks(bio)) 2402 if (!generic_make_request_checks(bio))
2391 goto out; 2403 goto out;
2392 2404
@@ -2423,11 +2435,22 @@ blk_qc_t generic_make_request(struct bio *bio)
2423 bio_list_init(&bio_list_on_stack[0]); 2435 bio_list_init(&bio_list_on_stack[0]);
2424 current->bio_list = bio_list_on_stack; 2436 current->bio_list = bio_list_on_stack;
2425 do { 2437 do {
2426 struct request_queue *q = bio->bi_disk->queue; 2438 bool enter_succeeded = true;
2427 blk_mq_req_flags_t flags = bio->bi_opf & REQ_NOWAIT ? 2439
2428 BLK_MQ_REQ_NOWAIT : 0; 2440 if (unlikely(q != bio->bi_disk->queue)) {
2441 if (q)
2442 blk_queue_exit(q);
2443 q = bio->bi_disk->queue;
2444 flags = 0;
2445 if (bio->bi_opf & REQ_NOWAIT)
2446 flags = BLK_MQ_REQ_NOWAIT;
2447 if (blk_queue_enter(q, flags) < 0) {
2448 enter_succeeded = false;
2449 q = NULL;
2450 }
2451 }
2429 2452
2430 if (likely(blk_queue_enter(q, flags) == 0)) { 2453 if (enter_succeeded) {
2431 struct bio_list lower, same; 2454 struct bio_list lower, same;
2432 2455
2433 /* Create a fresh bio_list for all subordinate requests */ 2456 /* Create a fresh bio_list for all subordinate requests */
@@ -2435,8 +2458,6 @@ blk_qc_t generic_make_request(struct bio *bio)
2435 bio_list_init(&bio_list_on_stack[0]); 2458 bio_list_init(&bio_list_on_stack[0]);
2436 ret = q->make_request_fn(q, bio); 2459 ret = q->make_request_fn(q, bio);
2437 2460
2438 blk_queue_exit(q);
2439
2440 /* sort new bios into those for a lower level 2461 /* sort new bios into those for a lower level
2441 * and those for the same level 2462 * and those for the same level
2442 */ 2463 */
@@ -2463,6 +2484,8 @@ blk_qc_t generic_make_request(struct bio *bio)
2463 current->bio_list = NULL; /* deactivate */ 2484 current->bio_list = NULL; /* deactivate */
2464 2485
2465out: 2486out:
2487 if (q)
2488 blk_queue_exit(q);
2466 return ret; 2489 return ret;
2467} 2490}
2468EXPORT_SYMBOL(generic_make_request); 2491EXPORT_SYMBOL(generic_make_request);
diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 9f8cffc8a701..3eb169f15842 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -16,11 +16,6 @@
16 16
17static int cpu_to_queue_index(unsigned int nr_queues, const int cpu) 17static int cpu_to_queue_index(unsigned int nr_queues, const int cpu)
18{ 18{
19 /*
20 * Non present CPU will be mapped to queue index 0.
21 */
22 if (!cpu_present(cpu))
23 return 0;
24 return cpu % nr_queues; 19 return cpu % nr_queues;
25} 20}
26 21
diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index 58b3b79cbe83..3080e18cb859 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -235,7 +235,6 @@ static const char *const hctx_state_name[] = {
235 HCTX_STATE_NAME(STOPPED), 235 HCTX_STATE_NAME(STOPPED),
236 HCTX_STATE_NAME(TAG_ACTIVE), 236 HCTX_STATE_NAME(TAG_ACTIVE),
237 HCTX_STATE_NAME(SCHED_RESTART), 237 HCTX_STATE_NAME(SCHED_RESTART),
238 HCTX_STATE_NAME(START_ON_RUN),
239}; 238};
240#undef HCTX_STATE_NAME 239#undef HCTX_STATE_NAME
241 240
diff --git a/block/blk-mq.c b/block/blk-mq.c
index f5c7dbcb954f..0dc9e341c2a7 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1180,7 +1180,12 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
1180 struct blk_mq_queue_data bd; 1180 struct blk_mq_queue_data bd;
1181 1181
1182 rq = list_first_entry(list, struct request, queuelist); 1182 rq = list_first_entry(list, struct request, queuelist);
1183 if (!blk_mq_get_driver_tag(rq, &hctx, false)) { 1183
1184 hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu);
1185 if (!got_budget && !blk_mq_get_dispatch_budget(hctx))
1186 break;
1187
1188 if (!blk_mq_get_driver_tag(rq, NULL, false)) {
1184 /* 1189 /*
1185 * The initial allocation attempt failed, so we need to 1190 * The initial allocation attempt failed, so we need to
1186 * rerun the hardware queue when a tag is freed. The 1191 * rerun the hardware queue when a tag is freed. The
@@ -1189,8 +1194,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
1189 * we'll re-run it below. 1194 * we'll re-run it below.
1190 */ 1195 */
1191 if (!blk_mq_mark_tag_wait(&hctx, rq)) { 1196 if (!blk_mq_mark_tag_wait(&hctx, rq)) {
1192 if (got_budget) 1197 blk_mq_put_dispatch_budget(hctx);
1193 blk_mq_put_dispatch_budget(hctx);
1194 /* 1198 /*
1195 * For non-shared tags, the RESTART check 1199 * For non-shared tags, the RESTART check
1196 * will suffice. 1200 * will suffice.
@@ -1201,11 +1205,6 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
1201 } 1205 }
1202 } 1206 }
1203 1207
1204 if (!got_budget && !blk_mq_get_dispatch_budget(hctx)) {
1205 blk_mq_put_driver_tag(rq);
1206 break;
1207 }
1208
1209 list_del_init(&rq->queuelist); 1208 list_del_init(&rq->queuelist);
1210 1209
1211 bd.rq = rq; 1210 bd.rq = rq;
@@ -1336,6 +1335,15 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
1336 hctx_unlock(hctx, srcu_idx); 1335 hctx_unlock(hctx, srcu_idx);
1337} 1336}
1338 1337
1338static inline int blk_mq_first_mapped_cpu(struct blk_mq_hw_ctx *hctx)
1339{
1340 int cpu = cpumask_first_and(hctx->cpumask, cpu_online_mask);
1341
1342 if (cpu >= nr_cpu_ids)
1343 cpu = cpumask_first(hctx->cpumask);
1344 return cpu;
1345}
1346
1339/* 1347/*
1340 * It'd be great if the workqueue API had a way to pass 1348 * It'd be great if the workqueue API had a way to pass
1341 * in a mask and had some smarts for more clever placement. 1349 * in a mask and had some smarts for more clever placement.
@@ -1345,26 +1353,17 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
1345static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx) 1353static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
1346{ 1354{
1347 bool tried = false; 1355 bool tried = false;
1356 int next_cpu = hctx->next_cpu;
1348 1357
1349 if (hctx->queue->nr_hw_queues == 1) 1358 if (hctx->queue->nr_hw_queues == 1)
1350 return WORK_CPU_UNBOUND; 1359 return WORK_CPU_UNBOUND;
1351 1360
1352 if (--hctx->next_cpu_batch <= 0) { 1361 if (--hctx->next_cpu_batch <= 0) {
1353 int next_cpu;
1354select_cpu: 1362select_cpu:
1355 next_cpu = cpumask_next_and(hctx->next_cpu, hctx->cpumask, 1363 next_cpu = cpumask_next_and(next_cpu, hctx->cpumask,
1356 cpu_online_mask); 1364 cpu_online_mask);
1357 if (next_cpu >= nr_cpu_ids) 1365 if (next_cpu >= nr_cpu_ids)
1358 next_cpu = cpumask_first_and(hctx->cpumask,cpu_online_mask); 1366 next_cpu = blk_mq_first_mapped_cpu(hctx);
1359
1360 /*
1361 * No online CPU is found, so have to make sure hctx->next_cpu
1362 * is set correctly for not breaking workqueue.
1363 */
1364 if (next_cpu >= nr_cpu_ids)
1365 hctx->next_cpu = cpumask_first(hctx->cpumask);
1366 else
1367 hctx->next_cpu = next_cpu;
1368 hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; 1367 hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
1369 } 1368 }
1370 1369
@@ -1372,7 +1371,7 @@ select_cpu:
1372 * Do unbound schedule if we can't find a online CPU for this hctx, 1371 * Do unbound schedule if we can't find a online CPU for this hctx,
1373 * and it should only happen in the path of handling CPU DEAD. 1372 * and it should only happen in the path of handling CPU DEAD.
1374 */ 1373 */
1375 if (!cpu_online(hctx->next_cpu)) { 1374 if (!cpu_online(next_cpu)) {
1376 if (!tried) { 1375 if (!tried) {
1377 tried = true; 1376 tried = true;
1378 goto select_cpu; 1377 goto select_cpu;
@@ -1382,18 +1381,18 @@ select_cpu:
1382 * Make sure to re-select CPU next time once after CPUs 1381 * Make sure to re-select CPU next time once after CPUs
1383 * in hctx->cpumask become online again. 1382 * in hctx->cpumask become online again.
1384 */ 1383 */
1384 hctx->next_cpu = next_cpu;
1385 hctx->next_cpu_batch = 1; 1385 hctx->next_cpu_batch = 1;
1386 return WORK_CPU_UNBOUND; 1386 return WORK_CPU_UNBOUND;
1387 } 1387 }
1388 return hctx->next_cpu; 1388
1389 hctx->next_cpu = next_cpu;
1390 return next_cpu;
1389} 1391}
1390 1392
1391static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async, 1393static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async,
1392 unsigned long msecs) 1394 unsigned long msecs)
1393{ 1395{
1394 if (WARN_ON_ONCE(!blk_mq_hw_queue_mapped(hctx)))
1395 return;
1396
1397 if (unlikely(blk_mq_hctx_stopped(hctx))) 1396 if (unlikely(blk_mq_hctx_stopped(hctx)))
1398 return; 1397 return;
1399 1398
@@ -1560,40 +1559,14 @@ static void blk_mq_run_work_fn(struct work_struct *work)
1560 hctx = container_of(work, struct blk_mq_hw_ctx, run_work.work); 1559 hctx = container_of(work, struct blk_mq_hw_ctx, run_work.work);
1561 1560
1562 /* 1561 /*
1563 * If we are stopped, don't run the queue. The exception is if 1562 * If we are stopped, don't run the queue.
1564 * BLK_MQ_S_START_ON_RUN is set. For that case, we auto-clear
1565 * the STOPPED bit and run it.
1566 */ 1563 */
1567 if (test_bit(BLK_MQ_S_STOPPED, &hctx->state)) { 1564 if (test_bit(BLK_MQ_S_STOPPED, &hctx->state))
1568 if (!test_bit(BLK_MQ_S_START_ON_RUN, &hctx->state))
1569 return;
1570
1571 clear_bit(BLK_MQ_S_START_ON_RUN, &hctx->state);
1572 clear_bit(BLK_MQ_S_STOPPED, &hctx->state); 1565 clear_bit(BLK_MQ_S_STOPPED, &hctx->state);
1573 }
1574 1566
1575 __blk_mq_run_hw_queue(hctx); 1567 __blk_mq_run_hw_queue(hctx);
1576} 1568}
1577 1569
1578
1579void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs)
1580{
1581 if (WARN_ON_ONCE(!blk_mq_hw_queue_mapped(hctx)))
1582 return;
1583
1584 /*
1585 * Stop the hw queue, then modify currently delayed work.
1586 * This should prevent us from running the queue prematurely.
1587 * Mark the queue as auto-clearing STOPPED when it runs.
1588 */
1589 blk_mq_stop_hw_queue(hctx);
1590 set_bit(BLK_MQ_S_START_ON_RUN, &hctx->state);
1591 kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
1592 &hctx->run_work,
1593 msecs_to_jiffies(msecs));
1594}
1595EXPORT_SYMBOL(blk_mq_delay_queue);
1596
1597static inline void __blk_mq_insert_req_list(struct blk_mq_hw_ctx *hctx, 1570static inline void __blk_mq_insert_req_list(struct blk_mq_hw_ctx *hctx,
1598 struct request *rq, 1571 struct request *rq,
1599 bool at_head) 1572 bool at_head)
@@ -1804,11 +1777,11 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
1804 if (q->elevator && !bypass_insert) 1777 if (q->elevator && !bypass_insert)
1805 goto insert; 1778 goto insert;
1806 1779
1807 if (!blk_mq_get_driver_tag(rq, NULL, false)) 1780 if (!blk_mq_get_dispatch_budget(hctx))
1808 goto insert; 1781 goto insert;
1809 1782
1810 if (!blk_mq_get_dispatch_budget(hctx)) { 1783 if (!blk_mq_get_driver_tag(rq, NULL, false)) {
1811 blk_mq_put_driver_tag(rq); 1784 blk_mq_put_dispatch_budget(hctx);
1812 goto insert; 1785 goto insert;
1813 } 1786 }
1814 1787
@@ -2356,7 +2329,7 @@ static void blk_mq_free_map_and_requests(struct blk_mq_tag_set *set,
2356 2329
2357static void blk_mq_map_swqueue(struct request_queue *q) 2330static void blk_mq_map_swqueue(struct request_queue *q)
2358{ 2331{
2359 unsigned int i, hctx_idx; 2332 unsigned int i;
2360 struct blk_mq_hw_ctx *hctx; 2333 struct blk_mq_hw_ctx *hctx;
2361 struct blk_mq_ctx *ctx; 2334 struct blk_mq_ctx *ctx;
2362 struct blk_mq_tag_set *set = q->tag_set; 2335 struct blk_mq_tag_set *set = q->tag_set;
@@ -2373,23 +2346,8 @@ static void blk_mq_map_swqueue(struct request_queue *q)
2373 2346
2374 /* 2347 /*
2375 * Map software to hardware queues. 2348 * Map software to hardware queues.
2376 *
2377 * If the cpu isn't present, the cpu is mapped to first hctx.
2378 */ 2349 */
2379 for_each_possible_cpu(i) { 2350 for_each_possible_cpu(i) {
2380 hctx_idx = q->mq_map[i];
2381 /* unmapped hw queue can be remapped after CPU topo changed */
2382 if (!set->tags[hctx_idx] &&
2383 !__blk_mq_alloc_rq_map(set, hctx_idx)) {
2384 /*
2385 * If tags initialization fail for some hctx,
2386 * that hctx won't be brought online. In this
2387 * case, remap the current ctx to hctx[0] which
2388 * is guaranteed to always have tags allocated
2389 */
2390 q->mq_map[i] = 0;
2391 }
2392
2393 ctx = per_cpu_ptr(q->queue_ctx, i); 2351 ctx = per_cpu_ptr(q->queue_ctx, i);
2394 hctx = blk_mq_map_queue(q, i); 2352 hctx = blk_mq_map_queue(q, i);
2395 2353
@@ -2401,21 +2359,8 @@ static void blk_mq_map_swqueue(struct request_queue *q)
2401 mutex_unlock(&q->sysfs_lock); 2359 mutex_unlock(&q->sysfs_lock);
2402 2360
2403 queue_for_each_hw_ctx(q, hctx, i) { 2361 queue_for_each_hw_ctx(q, hctx, i) {
2404 /* 2362 /* every hctx should get mapped by at least one CPU */
2405 * If no software queues are mapped to this hardware queue, 2363 WARN_ON(!hctx->nr_ctx);
2406 * disable it and free the request entries.
2407 */
2408 if (!hctx->nr_ctx) {
2409 /* Never unmap queue 0. We need it as a
2410 * fallback in case of a new remap fails
2411 * allocation
2412 */
2413 if (i && set->tags[i])
2414 blk_mq_free_map_and_requests(set, i);
2415
2416 hctx->tags = NULL;
2417 continue;
2418 }
2419 2364
2420 hctx->tags = set->tags[i]; 2365 hctx->tags = set->tags[i];
2421 WARN_ON(!hctx->tags); 2366 WARN_ON(!hctx->tags);
@@ -2430,8 +2375,7 @@ static void blk_mq_map_swqueue(struct request_queue *q)
2430 /* 2375 /*
2431 * Initialize batch roundrobin counts 2376 * Initialize batch roundrobin counts
2432 */ 2377 */
2433 hctx->next_cpu = cpumask_first_and(hctx->cpumask, 2378 hctx->next_cpu = blk_mq_first_mapped_cpu(hctx);
2434 cpu_online_mask);
2435 hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; 2379 hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
2436 } 2380 }
2437} 2381}
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 264abaaff662..c9d04497a415 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1103,11 +1103,15 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
1103 if (info->lo_encrypt_type) { 1103 if (info->lo_encrypt_type) {
1104 unsigned int type = info->lo_encrypt_type; 1104 unsigned int type = info->lo_encrypt_type;
1105 1105
1106 if (type >= MAX_LO_CRYPT) 1106 if (type >= MAX_LO_CRYPT) {
1107 return -EINVAL; 1107 err = -EINVAL;
1108 goto exit;
1109 }
1108 xfer = xfer_funcs[type]; 1110 xfer = xfer_funcs[type];
1109 if (xfer == NULL) 1111 if (xfer == NULL) {
1110 return -EINVAL; 1112 err = -EINVAL;
1113 goto exit;
1114 }
1111 } else 1115 } else
1112 xfer = NULL; 1116 xfer = NULL;
1113 1117
@@ -1283,12 +1287,13 @@ static int
1283loop_get_status_old(struct loop_device *lo, struct loop_info __user *arg) { 1287loop_get_status_old(struct loop_device *lo, struct loop_info __user *arg) {
1284 struct loop_info info; 1288 struct loop_info info;
1285 struct loop_info64 info64; 1289 struct loop_info64 info64;
1286 int err = 0; 1290 int err;
1287 1291
1288 if (!arg) 1292 if (!arg) {
1289 err = -EINVAL; 1293 mutex_unlock(&lo->lo_ctl_mutex);
1290 if (!err) 1294 return -EINVAL;
1291 err = loop_get_status(lo, &info64); 1295 }
1296 err = loop_get_status(lo, &info64);
1292 if (!err) 1297 if (!err)
1293 err = loop_info64_to_old(&info64, &info); 1298 err = loop_info64_to_old(&info64, &info);
1294 if (!err && copy_to_user(arg, &info, sizeof(info))) 1299 if (!err && copy_to_user(arg, &info, sizeof(info)))
@@ -1300,12 +1305,13 @@ loop_get_status_old(struct loop_device *lo, struct loop_info __user *arg) {
1300static int 1305static int
1301loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) { 1306loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) {
1302 struct loop_info64 info64; 1307 struct loop_info64 info64;
1303 int err = 0; 1308 int err;
1304 1309
1305 if (!arg) 1310 if (!arg) {
1306 err = -EINVAL; 1311 mutex_unlock(&lo->lo_ctl_mutex);
1307 if (!err) 1312 return -EINVAL;
1308 err = loop_get_status(lo, &info64); 1313 }
1314 err = loop_get_status(lo, &info64);
1309 if (!err && copy_to_user(arg, &info64, sizeof(info64))) 1315 if (!err && copy_to_user(arg, &info64, sizeof(info64)))
1310 err = -EFAULT; 1316 err = -EFAULT;
1311 1317
@@ -1529,12 +1535,13 @@ loop_get_status_compat(struct loop_device *lo,
1529 struct compat_loop_info __user *arg) 1535 struct compat_loop_info __user *arg)
1530{ 1536{
1531 struct loop_info64 info64; 1537 struct loop_info64 info64;
1532 int err = 0; 1538 int err;
1533 1539
1534 if (!arg) 1540 if (!arg) {
1535 err = -EINVAL; 1541 mutex_unlock(&lo->lo_ctl_mutex);
1536 if (!err) 1542 return -EINVAL;
1537 err = loop_get_status(lo, &info64); 1543 }
1544 err = loop_get_status(lo, &info64);
1538 if (!err) 1545 if (!err)
1539 err = loop_info64_to_compat(&info64, arg); 1546 err = loop_info64_to_compat(&info64, arg);
1540 return err; 1547 return err;
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 197a6ba9700f..9df4f71e58ca 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -376,6 +376,15 @@ static void nvme_put_ns(struct nvme_ns *ns)
376 kref_put(&ns->kref, nvme_free_ns); 376 kref_put(&ns->kref, nvme_free_ns);
377} 377}
378 378
379static inline void nvme_clear_nvme_request(struct request *req)
380{
381 if (!(req->rq_flags & RQF_DONTPREP)) {
382 nvme_req(req)->retries = 0;
383 nvme_req(req)->flags = 0;
384 req->rq_flags |= RQF_DONTPREP;
385 }
386}
387
379struct request *nvme_alloc_request(struct request_queue *q, 388struct request *nvme_alloc_request(struct request_queue *q,
380 struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid) 389 struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid)
381{ 390{
@@ -392,6 +401,7 @@ struct request *nvme_alloc_request(struct request_queue *q,
392 return req; 401 return req;
393 402
394 req->cmd_flags |= REQ_FAILFAST_DRIVER; 403 req->cmd_flags |= REQ_FAILFAST_DRIVER;
404 nvme_clear_nvme_request(req);
395 nvme_req(req)->cmd = cmd; 405 nvme_req(req)->cmd = cmd;
396 406
397 return req; 407 return req;
@@ -608,11 +618,7 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
608{ 618{
609 blk_status_t ret = BLK_STS_OK; 619 blk_status_t ret = BLK_STS_OK;
610 620
611 if (!(req->rq_flags & RQF_DONTPREP)) { 621 nvme_clear_nvme_request(req);
612 nvme_req(req)->retries = 0;
613 nvme_req(req)->flags = 0;
614 req->rq_flags |= RQF_DONTPREP;
615 }
616 622
617 switch (req_op(req)) { 623 switch (req_op(req)) {
618 case REQ_OP_DRV_IN: 624 case REQ_OP_DRV_IN:
@@ -742,6 +748,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
742 return PTR_ERR(req); 748 return PTR_ERR(req);
743 749
744 req->timeout = timeout ? timeout : ADMIN_TIMEOUT; 750 req->timeout = timeout ? timeout : ADMIN_TIMEOUT;
751 nvme_req(req)->flags |= NVME_REQ_USERCMD;
745 752
746 if (ubuffer && bufflen) { 753 if (ubuffer && bufflen) {
747 ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen, 754 ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen,
@@ -826,7 +833,7 @@ static void nvme_keep_alive_work(struct work_struct *work)
826 } 833 }
827} 834}
828 835
829void nvme_start_keep_alive(struct nvme_ctrl *ctrl) 836static void nvme_start_keep_alive(struct nvme_ctrl *ctrl)
830{ 837{
831 if (unlikely(ctrl->kato == 0)) 838 if (unlikely(ctrl->kato == 0))
832 return; 839 return;
@@ -836,7 +843,6 @@ void nvme_start_keep_alive(struct nvme_ctrl *ctrl)
836 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; 843 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
837 schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ); 844 schedule_delayed_work(&ctrl->ka_work, ctrl->kato * HZ);
838} 845}
839EXPORT_SYMBOL_GPL(nvme_start_keep_alive);
840 846
841void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) 847void nvme_stop_keep_alive(struct nvme_ctrl *ctrl)
842{ 848{
@@ -1103,7 +1109,7 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
1103 } 1109 }
1104 1110
1105 if (ctrl->effects) 1111 if (ctrl->effects)
1106 effects = le32_to_cpu(ctrl->effects->iocs[opcode]); 1112 effects = le32_to_cpu(ctrl->effects->acs[opcode]);
1107 else 1113 else
1108 effects = nvme_known_admin_effects(opcode); 1114 effects = nvme_known_admin_effects(opcode);
1109 1115
@@ -2220,7 +2226,7 @@ out_unlock:
2220 2226
2221int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns, 2227int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
2222 u8 log_page, void *log, 2228 u8 log_page, void *log,
2223 size_t size, size_t offset) 2229 size_t size, u64 offset)
2224{ 2230{
2225 struct nvme_command c = { }; 2231 struct nvme_command c = { };
2226 unsigned long dwlen = size / 4 - 1; 2232 unsigned long dwlen = size / 4 - 1;
@@ -2235,8 +2241,8 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
2235 c.get_log_page.lid = log_page; 2241 c.get_log_page.lid = log_page;
2236 c.get_log_page.numdl = cpu_to_le16(dwlen & ((1 << 16) - 1)); 2242 c.get_log_page.numdl = cpu_to_le16(dwlen & ((1 << 16) - 1));
2237 c.get_log_page.numdu = cpu_to_le16(dwlen >> 16); 2243 c.get_log_page.numdu = cpu_to_le16(dwlen >> 16);
2238 c.get_log_page.lpol = cpu_to_le32(offset & ((1ULL << 32) - 1)); 2244 c.get_log_page.lpol = cpu_to_le32(lower_32_bits(offset));
2239 c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL); 2245 c.get_log_page.lpou = cpu_to_le32(upper_32_bits(offset));
2240 2246
2241 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); 2247 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size);
2242} 2248}
@@ -2833,7 +2839,9 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
2833 goto out_free_head; 2839 goto out_free_head;
2834 head->instance = ret; 2840 head->instance = ret;
2835 INIT_LIST_HEAD(&head->list); 2841 INIT_LIST_HEAD(&head->list);
2836 init_srcu_struct(&head->srcu); 2842 ret = init_srcu_struct(&head->srcu);
2843 if (ret)
2844 goto out_ida_remove;
2837 head->subsys = ctrl->subsys; 2845 head->subsys = ctrl->subsys;
2838 head->ns_id = nsid; 2846 head->ns_id = nsid;
2839 kref_init(&head->ref); 2847 kref_init(&head->ref);
@@ -2855,6 +2863,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
2855 return head; 2863 return head;
2856out_cleanup_srcu: 2864out_cleanup_srcu:
2857 cleanup_srcu_struct(&head->srcu); 2865 cleanup_srcu_struct(&head->srcu);
2866out_ida_remove:
2858 ida_simple_remove(&ctrl->subsys->ns_ida, head->instance); 2867 ida_simple_remove(&ctrl->subsys->ns_ida, head->instance);
2859out_free_head: 2868out_free_head:
2860 kfree(head); 2869 kfree(head);
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 8f0f34d06d46..124c458806df 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -536,6 +536,85 @@ static struct nvmf_transport_ops *nvmf_lookup_transport(
536 return NULL; 536 return NULL;
537} 537}
538 538
539blk_status_t nvmf_check_if_ready(struct nvme_ctrl *ctrl, struct request *rq,
540 bool queue_live, bool is_connected)
541{
542 struct nvme_command *cmd = nvme_req(rq)->cmd;
543
544 if (likely(ctrl->state == NVME_CTRL_LIVE && is_connected))
545 return BLK_STS_OK;
546
547 switch (ctrl->state) {
548 case NVME_CTRL_DELETING:
549 goto reject_io;
550
551 case NVME_CTRL_NEW:
552 case NVME_CTRL_CONNECTING:
553 if (!is_connected)
554 /*
555 * This is the case of starting a new
556 * association but connectivity was lost
557 * before it was fully created. We need to
558 * error the commands used to initialize the
559 * controller so the reconnect can go into a
560 * retry attempt. The commands should all be
561 * marked REQ_FAILFAST_DRIVER, which will hit
562 * the reject path below. Anything else will
563 * be queued while the state settles.
564 */
565 goto reject_or_queue_io;
566
567 if ((queue_live &&
568 !(nvme_req(rq)->flags & NVME_REQ_USERCMD)) ||
569 (!queue_live && blk_rq_is_passthrough(rq) &&
570 cmd->common.opcode == nvme_fabrics_command &&
571 cmd->fabrics.fctype == nvme_fabrics_type_connect))
572 /*
573 * If queue is live, allow only commands that
574 * are internally generated pass through. These
575 * are commands on the admin queue to initialize
576 * the controller. This will reject any ioctl
577 * admin cmds received while initializing.
578 *
579 * If the queue is not live, allow only a
580 * connect command. This will reject any ioctl
581 * admin cmd as well as initialization commands
582 * if the controller reverted the queue to non-live.
583 */
584 return BLK_STS_OK;
585
586 /*
587 * fall-thru to the reject_or_queue_io clause
588 */
589 break;
590
591 /* these cases fall-thru
592 * case NVME_CTRL_LIVE:
593 * case NVME_CTRL_RESETTING:
594 */
595 default:
596 break;
597 }
598
599reject_or_queue_io:
600 /*
601 * Any other new io is something we're not in a state to send
602 * to the device. Default action is to busy it and retry it
603 * after the controller state is recovered. However, anything
604 * marked for failfast or nvme multipath is immediately failed.
605 * Note: commands used to initialize the controller will be
606 * marked for failfast.
607 * Note: nvme cli/ioctl commands are marked for failfast.
608 */
609 if (!blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH))
610 return BLK_STS_RESOURCE;
611
612reject_io:
613 nvme_req(rq)->status = NVME_SC_ABORT_REQ;
614 return BLK_STS_IOERR;
615}
616EXPORT_SYMBOL_GPL(nvmf_check_if_ready);
617
539static const match_table_t opt_tokens = { 618static const match_table_t opt_tokens = {
540 { NVMF_OPT_TRANSPORT, "transport=%s" }, 619 { NVMF_OPT_TRANSPORT, "transport=%s" },
541 { NVMF_OPT_TRADDR, "traddr=%s" }, 620 { NVMF_OPT_TRADDR, "traddr=%s" },
@@ -608,8 +687,10 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
608 opts->discovery_nqn = 687 opts->discovery_nqn =
609 !(strcmp(opts->subsysnqn, 688 !(strcmp(opts->subsysnqn,
610 NVME_DISC_SUBSYS_NAME)); 689 NVME_DISC_SUBSYS_NAME));
611 if (opts->discovery_nqn) 690 if (opts->discovery_nqn) {
691 opts->kato = 0;
612 opts->nr_io_queues = 0; 692 opts->nr_io_queues = 0;
693 }
613 break; 694 break;
614 case NVMF_OPT_TRADDR: 695 case NVMF_OPT_TRADDR:
615 p = match_strdup(args); 696 p = match_strdup(args);
diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
index a3145d90c1d2..ef46c915b7b5 100644
--- a/drivers/nvme/host/fabrics.h
+++ b/drivers/nvme/host/fabrics.h
@@ -157,36 +157,7 @@ void nvmf_unregister_transport(struct nvmf_transport_ops *ops);
157void nvmf_free_options(struct nvmf_ctrl_options *opts); 157void nvmf_free_options(struct nvmf_ctrl_options *opts);
158int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size); 158int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size);
159bool nvmf_should_reconnect(struct nvme_ctrl *ctrl); 159bool nvmf_should_reconnect(struct nvme_ctrl *ctrl);
160 160blk_status_t nvmf_check_if_ready(struct nvme_ctrl *ctrl,
161static inline blk_status_t nvmf_check_init_req(struct nvme_ctrl *ctrl, 161 struct request *rq, bool queue_live, bool is_connected);
162 struct request *rq)
163{
164 struct nvme_command *cmd = nvme_req(rq)->cmd;
165
166 /*
167 * We cannot accept any other command until the connect command has
168 * completed, so only allow connect to pass.
169 */
170 if (!blk_rq_is_passthrough(rq) ||
171 cmd->common.opcode != nvme_fabrics_command ||
172 cmd->fabrics.fctype != nvme_fabrics_type_connect) {
173 /*
174 * Connecting state means transport disruption or initial
175 * establishment, which can take a long time and even might
176 * fail permanently, fail fast to give upper layers a chance
177 * to failover.
178 * Deleting state means that the ctrl will never accept commands
179 * again, fail it permanently.
180 */
181 if (ctrl->state == NVME_CTRL_CONNECTING ||
182 ctrl->state == NVME_CTRL_DELETING) {
183 nvme_req(rq)->status = NVME_SC_ABORT_REQ;
184 return BLK_STS_IOERR;
185 }
186 return BLK_STS_RESOURCE; /* try again later */
187 }
188
189 return BLK_STS_OK;
190}
191 162
192#endif /* _NVME_FABRICS_H */ 163#endif /* _NVME_FABRICS_H */
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index c6e719b2f3ca..6cb26bcf6ec0 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -2277,14 +2277,6 @@ nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
2277 return BLK_STS_OK; 2277 return BLK_STS_OK;
2278} 2278}
2279 2279
2280static inline blk_status_t nvme_fc_is_ready(struct nvme_fc_queue *queue,
2281 struct request *rq)
2282{
2283 if (unlikely(!test_bit(NVME_FC_Q_LIVE, &queue->flags)))
2284 return nvmf_check_init_req(&queue->ctrl->ctrl, rq);
2285 return BLK_STS_OK;
2286}
2287
2288static blk_status_t 2280static blk_status_t
2289nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx, 2281nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
2290 const struct blk_mq_queue_data *bd) 2282 const struct blk_mq_queue_data *bd)
@@ -2300,7 +2292,9 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
2300 u32 data_len; 2292 u32 data_len;
2301 blk_status_t ret; 2293 blk_status_t ret;
2302 2294
2303 ret = nvme_fc_is_ready(queue, rq); 2295 ret = nvmf_check_if_ready(&queue->ctrl->ctrl, rq,
2296 test_bit(NVME_FC_Q_LIVE, &queue->flags),
2297 ctrl->rport->remoteport.port_state == FC_OBJSTATE_ONLINE);
2304 if (unlikely(ret)) 2298 if (unlikely(ret))
2305 return ret; 2299 return ret;
2306 2300
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index cf93690b3ffc..061fecfd44f5 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -105,6 +105,7 @@ struct nvme_request {
105 105
106enum { 106enum {
107 NVME_REQ_CANCELLED = (1 << 0), 107 NVME_REQ_CANCELLED = (1 << 0),
108 NVME_REQ_USERCMD = (1 << 1),
108}; 109};
109 110
110static inline struct nvme_request *nvme_req(struct request *req) 111static inline struct nvme_request *nvme_req(struct request *req)
@@ -422,7 +423,6 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
422 unsigned timeout, int qid, int at_head, 423 unsigned timeout, int qid, int at_head,
423 blk_mq_req_flags_t flags); 424 blk_mq_req_flags_t flags);
424int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count); 425int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);
425void nvme_start_keep_alive(struct nvme_ctrl *ctrl);
426void nvme_stop_keep_alive(struct nvme_ctrl *ctrl); 426void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
427int nvme_reset_ctrl(struct nvme_ctrl *ctrl); 427int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
428int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl); 428int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl);
@@ -430,7 +430,7 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
430int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl); 430int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
431 431
432int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns, 432int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
433 u8 log_page, void *log, size_t size, size_t offset); 433 u8 log_page, void *log, size_t size, u64 offset);
434 434
435extern const struct attribute_group nvme_ns_id_attr_group; 435extern const struct attribute_group nvme_ns_id_attr_group;
436extern const struct block_device_operations nvme_ns_head_ops; 436extern const struct block_device_operations nvme_ns_head_ops;
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 295fbec1e5f2..fbc71fac6f1e 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -84,6 +84,7 @@ struct nvme_dev {
84 struct dma_pool *prp_small_pool; 84 struct dma_pool *prp_small_pool;
85 unsigned online_queues; 85 unsigned online_queues;
86 unsigned max_qid; 86 unsigned max_qid;
87 unsigned int num_vecs;
87 int q_depth; 88 int q_depth;
88 u32 db_stride; 89 u32 db_stride;
89 void __iomem *bar; 90 void __iomem *bar;
@@ -414,7 +415,8 @@ static int nvme_pci_map_queues(struct blk_mq_tag_set *set)
414{ 415{
415 struct nvme_dev *dev = set->driver_data; 416 struct nvme_dev *dev = set->driver_data;
416 417
417 return blk_mq_pci_map_queues(set, to_pci_dev(dev->dev), 0); 418 return blk_mq_pci_map_queues(set, to_pci_dev(dev->dev),
419 dev->num_vecs > 1 ? 1 /* admin queue */ : 0);
418} 420}
419 421
420/** 422/**
@@ -1380,8 +1382,7 @@ static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct nvme_queue *nvmeq,
1380 return 0; 1382 return 0;
1381} 1383}
1382 1384
1383static int nvme_alloc_queue(struct nvme_dev *dev, int qid, 1385static int nvme_alloc_queue(struct nvme_dev *dev, int qid, int depth)
1384 int depth, int node)
1385{ 1386{
1386 struct nvme_queue *nvmeq = &dev->queues[qid]; 1387 struct nvme_queue *nvmeq = &dev->queues[qid];
1387 1388
@@ -1457,7 +1458,11 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
1457 nvmeq->sq_cmds_io = dev->cmb + offset; 1458 nvmeq->sq_cmds_io = dev->cmb + offset;
1458 } 1459 }
1459 1460
1460 nvmeq->cq_vector = qid - 1; 1461 /*
1462 * A queue's vector matches the queue identifier unless the controller
1463 * has only one vector available.
1464 */
1465 nvmeq->cq_vector = dev->num_vecs == 1 ? 0 : qid;
1461 result = adapter_alloc_cq(dev, qid, nvmeq); 1466 result = adapter_alloc_cq(dev, qid, nvmeq);
1462 if (result < 0) 1467 if (result < 0)
1463 goto release_vector; 1468 goto release_vector;
@@ -1596,8 +1601,7 @@ static int nvme_pci_configure_admin_queue(struct nvme_dev *dev)
1596 if (result < 0) 1601 if (result < 0)
1597 return result; 1602 return result;
1598 1603
1599 result = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH, 1604 result = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH);
1600 dev_to_node(dev->dev));
1601 if (result) 1605 if (result)
1602 return result; 1606 return result;
1603 1607
@@ -1630,9 +1634,7 @@ static int nvme_create_io_queues(struct nvme_dev *dev)
1630 int ret = 0; 1634 int ret = 0;
1631 1635
1632 for (i = dev->ctrl.queue_count; i <= dev->max_qid; i++) { 1636 for (i = dev->ctrl.queue_count; i <= dev->max_qid; i++) {
1633 /* vector == qid - 1, match nvme_create_queue */ 1637 if (nvme_alloc_queue(dev, i, dev->q_depth)) {
1634 if (nvme_alloc_queue(dev, i, dev->q_depth,
1635 pci_irq_get_node(to_pci_dev(dev->dev), i - 1))) {
1636 ret = -ENOMEM; 1638 ret = -ENOMEM;
1637 break; 1639 break;
1638 } 1640 }
@@ -1914,6 +1916,10 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1914 int result, nr_io_queues; 1916 int result, nr_io_queues;
1915 unsigned long size; 1917 unsigned long size;
1916 1918
1919 struct irq_affinity affd = {
1920 .pre_vectors = 1
1921 };
1922
1917 nr_io_queues = num_possible_cpus(); 1923 nr_io_queues = num_possible_cpus();
1918 result = nvme_set_queue_count(&dev->ctrl, &nr_io_queues); 1924 result = nvme_set_queue_count(&dev->ctrl, &nr_io_queues);
1919 if (result < 0) 1925 if (result < 0)
@@ -1949,11 +1955,12 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1949 * setting up the full range we need. 1955 * setting up the full range we need.
1950 */ 1956 */
1951 pci_free_irq_vectors(pdev); 1957 pci_free_irq_vectors(pdev);
1952 nr_io_queues = pci_alloc_irq_vectors(pdev, 1, nr_io_queues, 1958 result = pci_alloc_irq_vectors_affinity(pdev, 1, nr_io_queues + 1,
1953 PCI_IRQ_ALL_TYPES | PCI_IRQ_AFFINITY); 1959 PCI_IRQ_ALL_TYPES | PCI_IRQ_AFFINITY, &affd);
1954 if (nr_io_queues <= 0) 1960 if (result <= 0)
1955 return -EIO; 1961 return -EIO;
1956 dev->max_qid = nr_io_queues; 1962 dev->num_vecs = result;
1963 dev->max_qid = max(result - 1, 1);
1957 1964
1958 /* 1965 /*
1959 * Should investigate if there's a performance win from allocating 1966 * Should investigate if there's a performance win from allocating
@@ -2201,7 +2208,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
2201 2208
2202 nvme_stop_queues(&dev->ctrl); 2209 nvme_stop_queues(&dev->ctrl);
2203 2210
2204 if (!dead) { 2211 if (!dead && dev->ctrl.queue_count > 0) {
2205 /* 2212 /*
2206 * If the controller is still alive tell it to stop using the 2213 * If the controller is still alive tell it to stop using the
2207 * host memory buffer. In theory the shutdown / reset should 2214 * host memory buffer. In theory the shutdown / reset should
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 758537e9ba07..1eb4438a8763 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -1601,17 +1601,6 @@ nvme_rdma_timeout(struct request *rq, bool reserved)
1601 return BLK_EH_HANDLED; 1601 return BLK_EH_HANDLED;
1602} 1602}
1603 1603
1604/*
1605 * We cannot accept any other command until the Connect command has completed.
1606 */
1607static inline blk_status_t
1608nvme_rdma_is_ready(struct nvme_rdma_queue *queue, struct request *rq)
1609{
1610 if (unlikely(!test_bit(NVME_RDMA_Q_LIVE, &queue->flags)))
1611 return nvmf_check_init_req(&queue->ctrl->ctrl, rq);
1612 return BLK_STS_OK;
1613}
1614
1615static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx, 1604static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
1616 const struct blk_mq_queue_data *bd) 1605 const struct blk_mq_queue_data *bd)
1617{ 1606{
@@ -1627,7 +1616,8 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
1627 1616
1628 WARN_ON_ONCE(rq->tag < 0); 1617 WARN_ON_ONCE(rq->tag < 0);
1629 1618
1630 ret = nvme_rdma_is_ready(queue, rq); 1619 ret = nvmf_check_if_ready(&queue->ctrl->ctrl, rq,
1620 test_bit(NVME_RDMA_Q_LIVE, &queue->flags), true);
1631 if (unlikely(ret)) 1621 if (unlikely(ret))
1632 return ret; 1622 return ret;
1633 1623
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 90dcdc40ac71..5e0e9fcc0d4d 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -178,6 +178,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
178 id->vid = 0; 178 id->vid = 0;
179 id->ssvid = 0; 179 id->ssvid = 0;
180 180
181 memset(id->sn, ' ', sizeof(id->sn));
181 bin2hex(id->sn, &ctrl->subsys->serial, 182 bin2hex(id->sn, &ctrl->subsys->serial,
182 min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2)); 183 min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2));
183 memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' '); 184 memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' ');
diff --git a/drivers/nvme/target/discovery.c b/drivers/nvme/target/discovery.c
index a72425d8bce0..231e04e0a496 100644
--- a/drivers/nvme/target/discovery.c
+++ b/drivers/nvme/target/discovery.c
@@ -59,7 +59,7 @@ static void nvmet_format_discovery_entry(struct nvmf_disc_rsp_page_hdr *hdr,
59 memcpy(e->trsvcid, port->disc_addr.trsvcid, NVMF_TRSVCID_SIZE); 59 memcpy(e->trsvcid, port->disc_addr.trsvcid, NVMF_TRSVCID_SIZE);
60 memcpy(e->traddr, traddr, NVMF_TRADDR_SIZE); 60 memcpy(e->traddr, traddr, NVMF_TRADDR_SIZE);
61 memcpy(e->tsas.common, port->disc_addr.tsas.common, NVMF_TSAS_SIZE); 61 memcpy(e->tsas.common, port->disc_addr.tsas.common, NVMF_TSAS_SIZE);
62 memcpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE); 62 strncpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE);
63} 63}
64 64
65/* 65/*
diff --git a/drivers/nvme/target/io-cmd.c b/drivers/nvme/target/io-cmd.c
index 28bbdff4a88b..cd2344179673 100644
--- a/drivers/nvme/target/io-cmd.c
+++ b/drivers/nvme/target/io-cmd.c
@@ -173,8 +173,8 @@ static void nvmet_execute_write_zeroes(struct nvmet_req *req)
173 173
174 sector = le64_to_cpu(write_zeroes->slba) << 174 sector = le64_to_cpu(write_zeroes->slba) <<
175 (req->ns->blksize_shift - 9); 175 (req->ns->blksize_shift - 9);
176 nr_sector = (((sector_t)le16_to_cpu(write_zeroes->length)) << 176 nr_sector = (((sector_t)le16_to_cpu(write_zeroes->length) + 1) <<
177 (req->ns->blksize_shift - 9)) + 1; 177 (req->ns->blksize_shift - 9));
178 178
179 if (__blkdev_issue_zeroout(req->ns->bdev, sector, nr_sector, 179 if (__blkdev_issue_zeroout(req->ns->bdev, sector, nr_sector,
180 GFP_KERNEL, &bio, 0)) 180 GFP_KERNEL, &bio, 0))
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c
index a350765d2d5c..31fdfba556a8 100644
--- a/drivers/nvme/target/loop.c
+++ b/drivers/nvme/target/loop.c
@@ -149,14 +149,6 @@ nvme_loop_timeout(struct request *rq, bool reserved)
149 return BLK_EH_HANDLED; 149 return BLK_EH_HANDLED;
150} 150}
151 151
152static inline blk_status_t nvme_loop_is_ready(struct nvme_loop_queue *queue,
153 struct request *rq)
154{
155 if (unlikely(!test_bit(NVME_LOOP_Q_LIVE, &queue->flags)))
156 return nvmf_check_init_req(&queue->ctrl->ctrl, rq);
157 return BLK_STS_OK;
158}
159
160static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx, 152static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
161 const struct blk_mq_queue_data *bd) 153 const struct blk_mq_queue_data *bd)
162{ 154{
@@ -166,7 +158,8 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
166 struct nvme_loop_iod *iod = blk_mq_rq_to_pdu(req); 158 struct nvme_loop_iod *iod = blk_mq_rq_to_pdu(req);
167 blk_status_t ret; 159 blk_status_t ret;
168 160
169 ret = nvme_loop_is_ready(queue, req); 161 ret = nvmf_check_if_ready(&queue->ctrl->ctrl, req,
162 test_bit(NVME_LOOP_Q_LIVE, &queue->flags), true);
170 if (unlikely(ret)) 163 if (unlikely(ret))
171 return ret; 164 return ret;
172 165
@@ -174,15 +167,12 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
174 if (ret) 167 if (ret)
175 return ret; 168 return ret;
176 169
170 blk_mq_start_request(req);
177 iod->cmd.common.flags |= NVME_CMD_SGL_METABUF; 171 iod->cmd.common.flags |= NVME_CMD_SGL_METABUF;
178 iod->req.port = nvmet_loop_port; 172 iod->req.port = nvmet_loop_port;
179 if (!nvmet_req_init(&iod->req, &queue->nvme_cq, 173 if (!nvmet_req_init(&iod->req, &queue->nvme_cq,
180 &queue->nvme_sq, &nvme_loop_ops)) { 174 &queue->nvme_sq, &nvme_loop_ops))
181 nvme_cleanup_cmd(req);
182 blk_mq_start_request(req);
183 nvme_loop_queue_response(&iod->req);
184 return BLK_STS_OK; 175 return BLK_STS_OK;
185 }
186 176
187 if (blk_rq_payload_bytes(req)) { 177 if (blk_rq_payload_bytes(req)) {
188 iod->sg_table.sgl = iod->first_sgl; 178 iod->sg_table.sgl = iod->first_sgl;
@@ -196,8 +186,6 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
196 iod->req.transfer_len = blk_rq_payload_bytes(req); 186 iod->req.transfer_len = blk_rq_payload_bytes(req);
197 } 187 }
198 188
199 blk_mq_start_request(req);
200
201 schedule_work(&iod->work); 189 schedule_work(&iod->work);
202 return BLK_STS_OK; 190 return BLK_STS_OK;
203} 191}
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 0cf25d789d05..3f3cb72e0c0c 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -587,18 +587,28 @@ out:
587static unsigned int sr_block_check_events(struct gendisk *disk, 587static unsigned int sr_block_check_events(struct gendisk *disk,
588 unsigned int clearing) 588 unsigned int clearing)
589{ 589{
590 struct scsi_cd *cd = scsi_cd(disk); 590 unsigned int ret = 0;
591 struct scsi_cd *cd;
591 592
592 if (atomic_read(&cd->device->disk_events_disable_depth)) 593 cd = scsi_cd_get(disk);
594 if (!cd)
593 return 0; 595 return 0;
594 596
595 return cdrom_check_events(&cd->cdi, clearing); 597 if (!atomic_read(&cd->device->disk_events_disable_depth))
598 ret = cdrom_check_events(&cd->cdi, clearing);
599
600 scsi_cd_put(cd);
601 return ret;
596} 602}
597 603
598static int sr_block_revalidate_disk(struct gendisk *disk) 604static int sr_block_revalidate_disk(struct gendisk *disk)
599{ 605{
600 struct scsi_cd *cd = scsi_cd(disk);
601 struct scsi_sense_hdr sshdr; 606 struct scsi_sense_hdr sshdr;
607 struct scsi_cd *cd;
608
609 cd = scsi_cd_get(disk);
610 if (!cd)
611 return -ENXIO;
602 612
603 /* if the unit is not ready, nothing more to do */ 613 /* if the unit is not ready, nothing more to do */
604 if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr)) 614 if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
@@ -607,6 +617,7 @@ static int sr_block_revalidate_disk(struct gendisk *disk)
607 sr_cd_check(&cd->cdi); 617 sr_cd_check(&cd->cdi);
608 get_sectorsize(cd); 618 get_sectorsize(cd);
609out: 619out:
620 scsi_cd_put(cd);
610 return 0; 621 return 0;
611} 622}
612 623
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index 09da0f124699..f6be4b0b6c18 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -28,6 +28,7 @@ void bdi_put(struct backing_dev_info *bdi);
28 28
29__printf(2, 3) 29__printf(2, 3)
30int bdi_register(struct backing_dev_info *bdi, const char *fmt, ...); 30int bdi_register(struct backing_dev_info *bdi, const char *fmt, ...);
31__printf(2, 0)
31int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, 32int bdi_register_va(struct backing_dev_info *bdi, const char *fmt,
32 va_list args); 33 va_list args);
33int bdi_register_owner(struct backing_dev_info *bdi, struct device *owner); 34int bdi_register_owner(struct backing_dev_info *bdi, struct device *owner);
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 8efcf49796a3..e3986f4b3461 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -183,7 +183,6 @@ enum {
183 BLK_MQ_S_STOPPED = 0, 183 BLK_MQ_S_STOPPED = 0,
184 BLK_MQ_S_TAG_ACTIVE = 1, 184 BLK_MQ_S_TAG_ACTIVE = 1,
185 BLK_MQ_S_SCHED_RESTART = 2, 185 BLK_MQ_S_SCHED_RESTART = 2,
186 BLK_MQ_S_START_ON_RUN = 3,
187 186
188 BLK_MQ_MAX_DEPTH = 10240, 187 BLK_MQ_MAX_DEPTH = 10240,
189 188
@@ -270,7 +269,6 @@ void blk_mq_unquiesce_queue(struct request_queue *q);
270void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs); 269void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs);
271bool blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async); 270bool blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
272void blk_mq_run_hw_queues(struct request_queue *q, bool async); 271void blk_mq_run_hw_queues(struct request_queue *q, bool async);
273void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs);
274void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset, 272void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
275 busy_tag_iter_fn *fn, void *priv); 273 busy_tag_iter_fn *fn, void *priv);
276void blk_mq_freeze_queue(struct request_queue *q); 274void blk_mq_freeze_queue(struct request_queue *q);