Pull block fixes from Jens Axboe: - Further timeout fixes. We aren't quite there yet, so expect another round of fixes for that to completely close some of the IRQ vs completion races. (Christoph/Bart) - Set of NVMe fixes from the usual suspects, mostly error handling - Two off-by-one fixes (Dan) - Another bdi race fix (Jan) - Fix nbd reconfigure with NBD_DISCONNECT_ON_CLOSE (Doron) * tag 'for-linus-20180623' of git://git.kernel.dk/linux-block: blk-mq: Fix timeout handling in case the timeout handler returns BLK_EH_DONE bdi: Fix another oops in wb_workfn() lightnvm: Remove depends on HAS_DMA in case of platform dependency nvme-pci: limit max IO size and segments to avoid high order allocations nvme-pci: move nvme_kill_queues to nvme_remove_dead_ctrl nvme-fc: release io queues to allow fast fail nbd: Add the nbd NBD_DISCONNECT_ON_CLOSE config flag. block: sed-opal: Fix a couple off by one bugs blk-mq-debugfs: Off by one in blk_mq_rq_state_name() nvmet: reset keep alive timer in controller enable nvme-rdma: don't override opts->queue_size nvme-rdma: Fix command completion race at error recovery nvme-rdma: fix possible free of a non-allocated async event buffer nvme-rdma: fix possible double free condition when failing to create a controller Revert "block: Add warning for bi_next not NULL in bio_endio()" block: fix timeout changes for legacy request drivers
Unified · Split
| @@ -1807,9 +1807,6 @@ again: · 1806 unmodified lines | ||
| 1807 | 1807 | if (!bio_integrity_endio(bio)) |
| 1808 | 1808 | return; |
| 1809 | 1809 | |
| 1810 | − if (WARN_ONCE(bio->bi_next, "driver left bi_next not NULL")) | |
| 1811 | − bio->bi_next = NULL; | |
| 1812 | − | |
| 1813 | 1810 | /* |
| 1814 | 1811 | * Need to have a real endio function for chained bios, otherwise |
| 1815 | 1812 | * various corner cases will break (like stacking block devices that |
| @@ -273,10 +273,6 @@ static void req_bio_endio(struct request *rq, struct bio *bio, · 272 unmodified lines | ||
| 273 | 273 | bio_advance(bio, nbytes); |
| 274 | 274 | |
| 275 | 275 | /* don't actually finish bio if it's part of flush sequence */ |
| 276 | − /* | |
| 277 | − * XXX this code looks suspicious - it's not consistent with advancing | |
| 278 | − * req->bio in caller | |
| 279 | − */ | |
| 280 | 276 | if (bio->bi_iter.bi_size == 0 && !(rq->rq_flags & RQF_FLUSH_SEQ)) |
| 281 | 277 | bio_endio(bio); |
| 282 | 278 | } |
| @@ -3081,10 +3077,8 @@ bool blk_update_request(struct request *req, blk_status_t error, · 2798 unmodified lines | ||
| 3081 | 3077 | struct bio *bio = req->bio; |
| 3082 | 3078 | unsigned bio_bytes = min(bio->bi_iter.bi_size, nr_bytes); |
| 3083 | 3079 | |
| 3084 | − if (bio_bytes == bio->bi_iter.bi_size) { | |
| 3080 | + if (bio_bytes == bio->bi_iter.bi_size) | |
| 3085 | 3081 | req->bio = bio->bi_next; |
| 3086 | − bio->bi_next = NULL; | |
| 3087 | − } | |
| 3088 | 3082 | |
| 3089 | 3083 | /* Completion has already been traced */ |
| 3090 | 3084 | bio_clear_flag(bio, BIO_TRACE_COMPLETION); |
| @@ -356,7 +356,7 @@ static const char *const blk_mq_rq_state_name_array[] = { · 355 unmodified lines | ||
| 356 | 356 | |
| 357 | 357 | static const char *blk_mq_rq_state_name(enum mq_rq_state rq_state) |
| 358 | 358 | { |
| 359 | − if (WARN_ON_ONCE((unsigned int)rq_state > | |
| 359 | + if (WARN_ON_ONCE((unsigned int)rq_state >= | |
| 360 | 360 | ARRAY_SIZE(blk_mq_rq_state_name_array))) |
| 361 | 361 | return "(?)"; |
| 362 | 362 | return blk_mq_rq_state_name_array[rq_state]; |
| @@ -781,7 +781,6 @@ static void blk_mq_rq_timed_out(struct request *req, bool reserved) · 780 unmodified lines | ||
| 781 | 781 | WARN_ON_ONCE(ret != BLK_EH_RESET_TIMER); |
| 782 | 782 | } |
| 783 | 783 | |
| 784 | − req->rq_flags &= ~RQF_TIMED_OUT; | |
| 785 | 784 | blk_add_timer(req); |
| 786 | 785 | } |
| 787 | 786 | |
| @@ -144,6 +144,7 @@ do_local: · 143 unmodified lines | ||
| 144 | 144 | |
| 145 | 145 | local_irq_restore(flags); |
| 146 | 146 | } |
| 147 | +EXPORT_SYMBOL(__blk_complete_request); | |
| 147 | 148 | |
| 148 | 149 | /** |
| 149 | 150 | * blk_complete_request - end I/O on a request |
| @@ -210,6 +210,7 @@ void blk_add_timer(struct request *req) · 209 unmodified lines | ||
| 210 | 210 | if (!req->timeout) |
| 211 | 211 | req->timeout = q->rq_timeout; |
| 212 | 212 | |
| 213 | + req->rq_flags &= ~RQF_TIMED_OUT; | |
| 213 | 214 | blk_rq_set_deadline(req, jiffies + req->timeout); |
| 214 | 215 | |
| 215 | 216 | /* |
| @@ -877,7 +877,7 @@ static size_t response_get_string(const struct parsed_resp *resp, int n, · 876 unmodified lines | ||
| 877 | 877 | return 0; |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | − if (n > resp->num) { | |
| 880 | + if (n >= resp->num) { | |
| 881 | 881 | pr_debug("Response has %d tokens. Can't access %d\n", |
| 882 | 882 | resp->num, n); |
| 883 | 883 | return 0; |
| @@ -916,7 +916,7 @@ static u64 response_get_u64(const struct parsed_resp *resp, int n) · 32 unmodified lines | ||
| 916 | 916 | return 0; |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | − if (n > resp->num) { | |
| 919 | + if (n >= resp->num) { | |
| 920 | 920 | pr_debug("Response has %d tokens. Can't access %d\n", |
| 921 | 921 | resp->num, n); |
| 922 | 922 | return 0; |
| @@ -76,6 +76,7 @@ struct link_dead_args { · 75 unmodified lines | ||
| 76 | 76 | #define NBD_HAS_CONFIG_REF 4 |
| 77 | 77 | #define NBD_BOUND 5 |
| 78 | 78 | #define NBD_DESTROY_ON_DISCONNECT 6 |
| 79 | +#define NBD_DISCONNECT_ON_CLOSE 7 | |
| 79 | 80 | |
| 80 | 81 | struct nbd_config { |
| 81 | 82 | u32 flags; |
| @@ -138,6 +139,7 @@ static void nbd_config_put(struct nbd_device *nbd); · 56 unmodified lines | ||
| 138 | 139 | static void nbd_connect_reply(struct genl_info *info, int index); |
| 139 | 140 | static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info); |
| 140 | 141 | static void nbd_dead_link_work(struct work_struct *work); |
| 142 | +static void nbd_disconnect_and_put(struct nbd_device *nbd); | |
| 141 | 143 | |
| 142 | 144 | static inline struct device *nbd_to_dev(struct nbd_device *nbd) |
| 143 | 145 | { |
| @@ -1305,6 +1307,12 @@ out: · 1161 unmodified lines | ||
| 1305 | 1307 | static void nbd_release(struct gendisk *disk, fmode_t mode) |
| 1306 | 1308 | { |
| 1307 | 1309 | struct nbd_device *nbd = disk->private_data; |
| 1310 | + struct block_device *bdev = bdget_disk(disk, 0); | |
| 1311 | + | |
| 1312 | + if (test_bit(NBD_DISCONNECT_ON_CLOSE, &nbd->config->runtime_flags) && | |
| 1313 | + bdev->bd_openers == 0) | |
| 1314 | + nbd_disconnect_and_put(nbd); | |
| 1315 | + | |
| 1308 | 1316 | nbd_config_put(nbd); |
| 1309 | 1317 | nbd_put(nbd); |
| 1310 | 1318 | } |
| @@ -1705,6 +1713,10 @@ again: · 394 unmodified lines | ||
| 1705 | 1713 | &config->runtime_flags); |
| 1706 | 1714 | put_dev = true; |
| 1707 | 1715 | } |
| 1716 | + if (flags & NBD_CFLAG_DISCONNECT_ON_CLOSE) { | |
| 1717 | + set_bit(NBD_DISCONNECT_ON_CLOSE, | |
| 1718 | + &config->runtime_flags); | |
| 1719 | + } | |
| 1708 | 1720 | } |
| 1709 | 1721 | |
| 1710 | 1722 | if (info->attrs[NBD_ATTR_SOCKETS]) { |
| @@ -1749,6 +1761,17 @@ out: · 38 unmodified lines | ||
| 1749 | 1761 | return ret; |
| 1750 | 1762 | } |
| 1751 | 1763 | |
| 1764 | +static void nbd_disconnect_and_put(struct nbd_device *nbd) | |
| 1765 | +{ | |
| 1766 | + mutex_lock(&nbd->config_lock); | |
| 1767 | + nbd_disconnect(nbd); | |
| 1768 | + nbd_clear_sock(nbd); | |
| 1769 | + mutex_unlock(&nbd->config_lock); | |
| 1770 | + if (test_and_clear_bit(NBD_HAS_CONFIG_REF, | |
| 1771 | + &nbd->config->runtime_flags)) | |
| 1772 | + nbd_config_put(nbd); | |
| 1773 | +} | |
| 1774 | + | |
| 1752 | 1775 | static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 1753 | 1776 | { |
| 1754 | 1777 | struct nbd_device *nbd; |
| @@ -1781,13 +1804,7 @@ static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info) · 26 unmodified lines | ||
| 1781 | 1804 | nbd_put(nbd); |
| 1782 | 1805 | return 0; |
| 1783 | 1806 | } |
| 1784 | − mutex_lock(&nbd->config_lock); | |
| 1785 | − nbd_disconnect(nbd); | |
| 1786 | − nbd_clear_sock(nbd); | |
| 1787 | − mutex_unlock(&nbd->config_lock); | |
| 1788 | − if (test_and_clear_bit(NBD_HAS_CONFIG_REF, | |
| 1789 | − &nbd->config->runtime_flags)) | |
| 1790 | − nbd_config_put(nbd); | |
| 1807 | + nbd_disconnect_and_put(nbd); | |
| 1791 | 1808 | nbd_config_put(nbd); |
| 1792 | 1809 | nbd_put(nbd); |
| 1793 | 1810 | return 0; |
| @@ -1798,7 +1815,7 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info) · 4 unmodified lines | ||
| 1798 | 1815 | struct nbd_device *nbd = NULL; |
| 1799 | 1816 | struct nbd_config *config; |
| 1800 | 1817 | int index; |
| 1801 | − int ret = -EINVAL; | |
| 1818 | + int ret = 0; | |
| 1802 | 1819 | bool put_dev = false; |
| 1803 | 1820 | |
| 1804 | 1821 | if (!netlink_capable(skb, CAP_SYS_ADMIN)) |
| @@ -1838,6 +1855,7 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info) · 33 unmodified lines | ||
| 1838 | 1855 | !nbd->task_recv) { |
| 1839 | 1856 | dev_err(nbd_to_dev(nbd), |
| 1840 | 1857 | "not configured, cannot reconfigure\n"); |
| 1858 | + ret = -EINVAL; | |
| 1841 | 1859 | goto out; |
| 1842 | 1860 | } |
| 1843 | 1861 | |
| @@ -1862,6 +1880,14 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info) · 18 unmodified lines | ||
| 1862 | 1880 | &config->runtime_flags)) |
| 1863 | 1881 | refcount_inc(&nbd->refs); |
| 1864 | 1882 | } |
| 1883 | + | |
| 1884 | + if (flags & NBD_CFLAG_DISCONNECT_ON_CLOSE) { | |
| 1885 | + set_bit(NBD_DISCONNECT_ON_CLOSE, | |
| 1886 | + &config->runtime_flags); | |
| 1887 | + } else { | |
| 1888 | + clear_bit(NBD_DISCONNECT_ON_CLOSE, | |
| 1889 | + &config->runtime_flags); | |
| 1890 | + } | |
| 1865 | 1891 | } |
| 1866 | 1892 | |
| 1867 | 1893 | if (info->attrs[NBD_ATTR_SOCKETS]) { |
| @@ -1365,7 +1365,7 @@ static blk_qc_t null_queue_bio(struct request_queue *q, struct bio *bio) · 1364 unmodified lines | ||
| 1365 | 1365 | static enum blk_eh_timer_return null_rq_timed_out_fn(struct request *rq) |
| 1366 | 1366 | { |
| 1367 | 1367 | pr_info("null: rq %p timed out\n", rq); |
| 1368 | − blk_mq_complete_request(rq); | |
| 1368 | + __blk_complete_request(rq); | |
| 1369 | 1369 | return BLK_EH_DONE; |
| 1370 | 1370 | } |
| 1371 | 1371 | |
| @@ -4,7 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | |
| 5 | 5 | menuconfig NVM |
| 6 | 6 | bool "Open-Channel SSD target support" |
| 7 | − depends on BLOCK && HAS_DMA && PCI | |
| 7 | + depends on BLOCK && PCI | |
| 8 | 8 | select BLK_DEV_NVME |
| 9 | 9 | help |
| 10 | 10 | Say Y here to get to enable Open-channel SSDs. |
| @@ -1808,6 +1808,7 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl, · 1807 unmodified lines | ||
| 1808 | 1808 | u32 max_segments = |
| 1809 | 1809 | (ctrl->max_hw_sectors / (ctrl->page_size >> 9)) + 1; |
| 1810 | 1810 | |
| 1811 | + max_segments = min_not_zero(max_segments, ctrl->max_segments); | |
| 1811 | 1812 | blk_queue_max_hw_sectors(q, ctrl->max_hw_sectors); |
| 1812 | 1813 | blk_queue_max_segments(q, min_t(u32, max_segments, USHRT_MAX)); |
| 1813 | 1814 | } |
| @@ -2790,6 +2790,9 @@ nvme_fc_delete_association(struct nvme_fc_ctrl *ctrl) · 2789 unmodified lines | ||
| 2790 | 2790 | /* re-enable the admin_q so anything new can fast fail */ |
| 2791 | 2791 | blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); |
| 2792 | 2792 | |
| 2793 | + /* resume the io queues so that things will fast fail */ | |
| 2794 | + nvme_start_queues(&ctrl->ctrl); | |
| 2795 | + | |
| 2793 | 2796 | nvme_fc_ctlr_inactive_on_rport(ctrl); |
| 2794 | 2797 | } |
| 2795 | 2798 | |
| @@ -2804,9 +2807,6 @@ nvme_fc_delete_ctrl(struct nvme_ctrl *nctrl) · 8 unmodified lines | ||
| 2804 | 2807 | * waiting for io to terminate |
| 2805 | 2808 | */ |
| 2806 | 2809 | nvme_fc_delete_association(ctrl); |
| 2807 | − | |
| 2808 | − /* resume the io queues so that things will fast fail */ | |
| 2809 | − nvme_start_queues(nctrl); | |
| 2810 | 2810 | } |
| 2811 | 2811 | |
| 2812 | 2812 | static void |
| @@ -170,6 +170,7 @@ struct nvme_ctrl { · 169 unmodified lines | ||
| 170 | 170 | u64 cap; |
| 171 | 171 | u32 page_size; |
| 172 | 172 | u32 max_hw_sectors; |
| 173 | + u32 max_segments; | |
| 173 | 174 | u16 oncs; |
| 174 | 175 | u16 oacs; |
| 175 | 176 | u16 nssa; |
| @@ -38,6 +38,13 @@ · 37 unmodified lines | ||
| 38 | 38 | |
| 39 | 39 | #define SGES_PER_PAGE (PAGE_SIZE / sizeof(struct nvme_sgl_desc)) |
| 40 | 40 | |
| 41 | +/* | |
| 42 | + * These can be higher, but we need to ensure that any command doesn't | |
| 43 | + * require an sg allocation that needs more than a page of data. | |
| 44 | + */ | |
| 45 | +#define NVME_MAX_KB_SZ 4096 | |
| 46 | +#define NVME_MAX_SEGS 127 | |
| 47 | + | |
| 41 | 48 | static int use_threaded_interrupts; |
| 42 | 49 | module_param(use_threaded_interrupts, int, 0); |
| 43 | 50 | |
| @@ -100,6 +107,8 @@ struct nvme_dev { · 56 unmodified lines | ||
| 100 | 107 | struct nvme_ctrl ctrl; |
| 101 | 108 | struct completion ioq_wait; |
| 102 | 109 | |
| 110 | + mempool_t *iod_mempool; | |
| 111 | + | |
| 103 | 112 | /* shadow doorbell buffer support: */ |
| 104 | 113 | u32 *dbbuf_dbs; |
| 105 | 114 | dma_addr_t dbbuf_dbs_dma_addr; |
| @@ -477,10 +486,7 @@ static blk_status_t nvme_init_iod(struct request *rq, struct nvme_dev *dev) · 371 unmodified lines | ||
| 477 | 486 | iod->use_sgl = nvme_pci_use_sgls(dev, rq); |
| 478 | 487 | |
| 479 | 488 | if (nseg > NVME_INT_PAGES || size > NVME_INT_BYTES(dev)) { |
| 480 | − size_t alloc_size = nvme_pci_iod_alloc_size(dev, size, nseg, | |
| 481 | − iod->use_sgl); | |
| 482 | − | |
| 483 | − iod->sg = kmalloc(alloc_size, GFP_ATOMIC); | |
| 489 | + iod->sg = mempool_alloc(dev->iod_mempool, GFP_ATOMIC); | |
| 484 | 490 | if (!iod->sg) |
| 485 | 491 | return BLK_STS_RESOURCE; |
| 486 | 492 | } else { |
| @@ -526,7 +532,7 @@ static void nvme_free_iod(struct nvme_dev *dev, struct request *req) · 39 unmodified lines | ||
| 526 | 532 | } |
| 527 | 533 | |
| 528 | 534 | if (iod->sg != iod->inline_sg) |
| 529 | − kfree(iod->sg); | |
| 535 | + mempool_free(iod->sg, dev->iod_mempool); | |
| 530 | 536 | } |
| 531 | 537 | |
| 532 | 538 | #ifdef CONFIG_BLK_DEV_INTEGRITY |
| @@ -2280,6 +2286,7 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl) · 1747 unmodified lines | ||
| 2280 | 2286 | blk_put_queue(dev->ctrl.admin_q); |
| 2281 | 2287 | kfree(dev->queues); |
| 2282 | 2288 | free_opal_dev(dev->ctrl.opal_dev); |
| 2289 | + mempool_destroy(dev->iod_mempool); | |
| 2283 | 2290 | kfree(dev); |
| 2284 | 2291 | } |
| 2285 | 2292 | |
| @@ -2289,6 +2296,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status) · 3 unmodified lines | ||
| 2289 | 2296 | |
| 2290 | 2297 | nvme_get_ctrl(&dev->ctrl); |
| 2291 | 2298 | nvme_dev_disable(dev, false); |
| 2299 | + nvme_kill_queues(&dev->ctrl); | |
| 2292 | 2300 | if (!queue_work(nvme_wq, &dev->remove_work)) |
| 2293 | 2301 | nvme_put_ctrl(&dev->ctrl); |
| 2294 | 2302 | } |
| @@ -2333,6 +2341,13 @@ static void nvme_reset_work(struct work_struct *work) · 38 unmodified lines | ||
| 2333 | 2341 | if (result) |
| 2334 | 2342 | goto out; |
| 2335 | 2343 | |
| 2344 | + /* | |
| 2345 | + * Limit the max command size to prevent iod->sg allocations going | |
| 2346 | + * over a single page. | |
| 2347 | + */ | |
| 2348 | + dev->ctrl.max_hw_sectors = NVME_MAX_KB_SZ << 1; | |
| 2349 | + dev->ctrl.max_segments = NVME_MAX_SEGS; | |
| 2350 | + | |
| 2336 | 2351 | result = nvme_init_identify(&dev->ctrl); |
| 2337 | 2352 | if (result) |
| 2338 | 2353 | goto out; |
| @@ -2405,7 +2420,6 @@ static void nvme_remove_dead_ctrl_work(struct work_struct *work) · 66 unmodified lines | ||
| 2405 | 2420 | struct nvme_dev *dev = container_of(work, struct nvme_dev, remove_work); |
| 2406 | 2421 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
| 2407 | 2422 | |
| 2408 | − nvme_kill_queues(&dev->ctrl); | |
| 2409 | 2423 | if (pci_get_drvdata(pdev)) |
| 2410 | 2424 | device_release_driver(&pdev->dev); |
| 2411 | 2425 | nvme_put_ctrl(&dev->ctrl); |
| @@ -2509,6 +2523,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) · 97 unmodified lines | ||
| 2509 | 2523 | int node, result = -ENOMEM; |
| 2510 | 2524 | struct nvme_dev *dev; |
| 2511 | 2525 | unsigned long quirks = id->driver_data; |
| 2526 | + size_t alloc_size; | |
| 2512 | 2527 | |
| 2513 | 2528 | node = dev_to_node(&pdev->dev); |
| 2514 | 2529 | if (node == NUMA_NO_NODE) |
| @@ -2546,6 +2561,23 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) · 31 unmodified lines | ||
| 2546 | 2561 | if (result) |
| 2547 | 2562 | goto release_pools; |
| 2548 | 2563 | |
| 2564 | + /* | |
| 2565 | + * Double check that our mempool alloc size will cover the biggest | |
| 2566 | + * command we support. | |
| 2567 | + */ | |
| 2568 | + alloc_size = nvme_pci_iod_alloc_size(dev, NVME_MAX_KB_SZ, | |
| 2569 | + NVME_MAX_SEGS, true); | |
| 2570 | + WARN_ON_ONCE(alloc_size > PAGE_SIZE); | |
| 2571 | + | |
| 2572 | + dev->iod_mempool = mempool_create_node(1, mempool_kmalloc, | |
| 2573 | + mempool_kfree, | |
| 2574 | + (void *) alloc_size, | |
| 2575 | + GFP_KERNEL, node); | |
| 2576 | + if (!dev->iod_mempool) { | |
| 2577 | + result = -ENOMEM; | |
| 2578 | + goto release_pools; | |
| 2579 | + } | |
| 2580 | + | |
| 2549 | 2581 | dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev)); |
| 2550 | 2582 | |
| 2551 | 2583 | nvme_get_ctrl(&dev->ctrl); |
| @@ -560,12 +560,6 @@ static void nvme_rdma_free_queue(struct nvme_rdma_queue *queue) · 559 unmodified lines | ||
| 560 | 560 | if (!test_and_clear_bit(NVME_RDMA_Q_ALLOCATED, &queue->flags)) |
| 561 | 561 | return; |
| 562 | 562 | |
| 563 | − if (nvme_rdma_queue_idx(queue) == 0) { | |
| 564 | − nvme_rdma_free_qe(queue->device->dev, | |
| 565 | − &queue->ctrl->async_event_sqe, | |
| 566 | − sizeof(struct nvme_command), DMA_TO_DEVICE); | |
| 567 | − } | |
| 568 | − | |
| 569 | 563 | nvme_rdma_destroy_queue_ib(queue); |
| 570 | 564 | rdma_destroy_id(queue->cm_id); |
| 571 | 565 | } |
| @@ -698,7 +692,7 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl, · 126 unmodified lines | ||
| 698 | 692 | set = &ctrl->tag_set; |
| 699 | 693 | memset(set, 0, sizeof(*set)); |
| 700 | 694 | set->ops = &nvme_rdma_mq_ops; |
| 701 | − set->queue_depth = nctrl->opts->queue_size; | |
| 695 | + set->queue_depth = nctrl->sqsize + 1; | |
| 702 | 696 | set->reserved_tags = 1; /* fabric connect */ |
| 703 | 697 | set->numa_node = NUMA_NO_NODE; |
| 704 | 698 | set->flags = BLK_MQ_F_SHOULD_MERGE; |
| @@ -734,11 +728,12 @@ out: · 29 unmodified lines | ||
| 734 | 728 | static void nvme_rdma_destroy_admin_queue(struct nvme_rdma_ctrl *ctrl, |
| 735 | 729 | bool remove) |
| 736 | 730 | { |
| 737 | − nvme_rdma_stop_queue(&ctrl->queues[0]); | |
| 738 | 731 | if (remove) { |
| 739 | 732 | blk_cleanup_queue(ctrl->ctrl.admin_q); |
| 740 | 733 | nvme_rdma_free_tagset(&ctrl->ctrl, ctrl->ctrl.admin_tagset); |
| 741 | 734 | } |
| 735 | + nvme_rdma_free_qe(ctrl->device->dev, &ctrl->async_event_sqe, | |
| 736 | + sizeof(struct nvme_command), DMA_TO_DEVICE); | |
| 742 | 737 | nvme_rdma_free_queue(&ctrl->queues[0]); |
| 743 | 738 | } |
| 744 | 739 | |
| @@ -755,11 +750,16 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl, · 10 unmodified lines | ||
| 755 | 750 | |
| 756 | 751 | ctrl->max_fr_pages = nvme_rdma_get_max_fr_pages(ctrl->device->dev); |
| 757 | 752 | |
| 753 | + error = nvme_rdma_alloc_qe(ctrl->device->dev, &ctrl->async_event_sqe, | |
| 754 | + sizeof(struct nvme_command), DMA_TO_DEVICE); | |
| 755 | + if (error) | |
| 756 | + goto out_free_queue; | |
| 757 | + | |
| 758 | 758 | if (new) { |
| 759 | 759 | ctrl->ctrl.admin_tagset = nvme_rdma_alloc_tagset(&ctrl->ctrl, true); |
| 760 | 760 | if (IS_ERR(ctrl->ctrl.admin_tagset)) { |
| 761 | 761 | error = PTR_ERR(ctrl->ctrl.admin_tagset); |
| 762 | − goto out_free_queue; | |
| 762 | + goto out_free_async_qe; | |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | ctrl->ctrl.admin_q = blk_mq_init_queue(&ctrl->admin_tag_set); |
| @@ -795,12 +795,6 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl, · 29 unmodified lines | ||
| 795 | 795 | if (error) |
| 796 | 796 | goto out_stop_queue; |
| 797 | 797 | |
| 798 | − error = nvme_rdma_alloc_qe(ctrl->queues[0].device->dev, | |
| 799 | − &ctrl->async_event_sqe, sizeof(struct nvme_command), | |
| 800 | − DMA_TO_DEVICE); | |
| 801 | − if (error) | |
| 802 | − goto out_stop_queue; | |
| 803 | − | |
| 804 | 798 | return 0; |
| 805 | 799 | |
| 806 | 800 | out_stop_queue: |
| @@ -811,6 +805,9 @@ out_cleanup_queue: · 4 unmodified lines | ||
| 811 | 805 | out_free_tagset: |
| 812 | 806 | if (new) |
| 813 | 807 | nvme_rdma_free_tagset(&ctrl->ctrl, ctrl->ctrl.admin_tagset); |
| 808 | +out_free_async_qe: | |
| 809 | + nvme_rdma_free_qe(ctrl->device->dev, &ctrl->async_event_sqe, | |
| 810 | + sizeof(struct nvme_command), DMA_TO_DEVICE); | |
| 814 | 811 | out_free_queue: |
| 815 | 812 | nvme_rdma_free_queue(&ctrl->queues[0]); |
| 816 | 813 | return error; |
| @@ -819,7 +816,6 @@ out_free_queue: · 2 unmodified lines | ||
| 819 | 816 | static void nvme_rdma_destroy_io_queues(struct nvme_rdma_ctrl *ctrl, |
| 820 | 817 | bool remove) |
| 821 | 818 | { |
| 822 | − nvme_rdma_stop_io_queues(ctrl); | |
| 823 | 819 | if (remove) { |
| 824 | 820 | blk_cleanup_queue(ctrl->ctrl.connect_q); |
| 825 | 821 | nvme_rdma_free_tagset(&ctrl->ctrl, ctrl->ctrl.tagset); |
| @@ -888,9 +884,9 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl) · 62 unmodified lines | ||
| 888 | 884 | list_del(&ctrl->list); |
| 889 | 885 | mutex_unlock(&nvme_rdma_ctrl_mutex); |
| 890 | 886 | |
| 891 | − kfree(ctrl->queues); | |
| 892 | 887 | nvmf_free_options(nctrl->opts); |
| 893 | 888 | free_ctrl: |
| 889 | + kfree(ctrl->queues); | |
| 894 | 890 | kfree(ctrl); |
| 895 | 891 | } |
| 896 | 892 | |
| @@ -949,6 +945,7 @@ static void nvme_rdma_reconnect_ctrl_work(struct work_struct *work) · 52 unmodified lines | ||
| 949 | 945 | return; |
| 950 | 946 | |
| 951 | 947 | destroy_admin: |
| 948 | + nvme_rdma_stop_queue(&ctrl->queues[0]); | |
| 952 | 949 | nvme_rdma_destroy_admin_queue(ctrl, false); |
| 953 | 950 | requeue: |
| 954 | 951 | dev_info(ctrl->ctrl.device, "Failed reconnect attempt %d\n", |
| @@ -965,12 +962,14 @@ static void nvme_rdma_error_recovery_work(struct work_struct *work) · 10 unmodified lines | ||
| 965 | 962 | |
| 966 | 963 | if (ctrl->ctrl.queue_count > 1) { |
| 967 | 964 | nvme_stop_queues(&ctrl->ctrl); |
| 965 | + nvme_rdma_stop_io_queues(ctrl); | |
| 968 | 966 | blk_mq_tagset_busy_iter(&ctrl->tag_set, |
| 969 | 967 | nvme_cancel_request, &ctrl->ctrl); |
| 970 | 968 | nvme_rdma_destroy_io_queues(ctrl, false); |
| 971 | 969 | } |
| 972 | 970 | |
| 973 | 971 | blk_mq_quiesce_queue(ctrl->ctrl.admin_q); |
| 972 | + nvme_rdma_stop_queue(&ctrl->queues[0]); | |
| 974 | 973 | blk_mq_tagset_busy_iter(&ctrl->admin_tag_set, |
| 975 | 974 | nvme_cancel_request, &ctrl->ctrl); |
| 976 | 975 | nvme_rdma_destroy_admin_queue(ctrl, false); |
| @@ -1736,6 +1735,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown) · 759 unmodified lines | ||
| 1736 | 1735 | { |
| 1737 | 1736 | if (ctrl->ctrl.queue_count > 1) { |
| 1738 | 1737 | nvme_stop_queues(&ctrl->ctrl); |
| 1738 | + nvme_rdma_stop_io_queues(ctrl); | |
| 1739 | 1739 | blk_mq_tagset_busy_iter(&ctrl->tag_set, |
| 1740 | 1740 | nvme_cancel_request, &ctrl->ctrl); |
| 1741 | 1741 | nvme_rdma_destroy_io_queues(ctrl, shutdown); |
| @@ -1747,6 +1747,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown) · 5 unmodified lines | ||
| 1747 | 1747 | nvme_disable_ctrl(&ctrl->ctrl, ctrl->ctrl.cap); |
| 1748 | 1748 | |
| 1749 | 1749 | blk_mq_quiesce_queue(ctrl->ctrl.admin_q); |
| 1750 | + nvme_rdma_stop_queue(&ctrl->queues[0]); | |
| 1750 | 1751 | blk_mq_tagset_busy_iter(&ctrl->admin_tag_set, |
| 1751 | 1752 | nvme_cancel_request, &ctrl->ctrl); |
| 1752 | 1753 | blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); |
| @@ -1932,11 +1933,6 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, · 179 unmodified lines | ||
| 1932 | 1933 | goto out_free_ctrl; |
| 1933 | 1934 | } |
| 1934 | 1935 | |
| 1935 | − ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, | |
| 1936 | − 0 /* no quirks, we're perfect! */); | |
| 1937 | − if (ret) | |
| 1938 | − goto out_free_ctrl; | |
| 1939 | − | |
| 1940 | 1936 | INIT_DELAYED_WORK(&ctrl->reconnect_work, |
| 1941 | 1937 | nvme_rdma_reconnect_ctrl_work); |
| 1942 | 1938 | INIT_WORK(&ctrl->err_work, nvme_rdma_error_recovery_work); |
| @@ -1950,14 +1946,19 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, · 7 unmodified lines | ||
| 1950 | 1946 | ctrl->queues = kcalloc(ctrl->ctrl.queue_count, sizeof(*ctrl->queues), |
| 1951 | 1947 | GFP_KERNEL); |
| 1952 | 1948 | if (!ctrl->queues) |
| 1953 | − goto out_uninit_ctrl; | |
| 1949 | + goto out_free_ctrl; | |
| 1950 | + | |
| 1951 | + ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, | |
| 1952 | + 0 /* no quirks, we're perfect! */); | |
| 1953 | + if (ret) | |
| 1954 | + goto out_kfree_queues; | |
| 1954 | 1955 | |
| 1955 | 1956 | changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING); |
| 1956 | 1957 | WARN_ON_ONCE(!changed); |
| 1957 | 1958 | |
| 1958 | 1959 | ret = nvme_rdma_configure_admin_queue(ctrl, true); |
| 1959 | 1960 | if (ret) |
| 1960 | − goto out_kfree_queues; | |
| 1961 | + goto out_uninit_ctrl; | |
| 1961 | 1962 | |
| 1962 | 1963 | /* sanity check icdoff */ |
| 1963 | 1964 | if (ctrl->ctrl.icdoff) { |
| @@ -1974,20 +1975,19 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, · 10 unmodified lines | ||
| 1974 | 1975 | goto out_remove_admin_queue; |
| 1975 | 1976 | } |
| 1976 | 1977 | |
| 1977 | − if (opts->queue_size > ctrl->ctrl.maxcmd) { | |
| 1978 | − /* warn if maxcmd is lower than queue_size */ | |
| 1979 | − dev_warn(ctrl->ctrl.device, | |
| 1980 | − "queue_size %zu > ctrl maxcmd %u, clamping down\n", | |
| 1981 | − opts->queue_size, ctrl->ctrl.maxcmd); | |
| 1982 | − opts->queue_size = ctrl->ctrl.maxcmd; | |
| 1983 | − } | |
| 1984 | − | |
| 1978 | + /* only warn if argument is too large here, will clamp later */ | |
| 1985 | 1979 | if (opts->queue_size > ctrl->ctrl.sqsize + 1) { |
| 1986 | − /* warn if sqsize is lower than queue_size */ | |
| 1987 | 1980 | dev_warn(ctrl->ctrl.device, |
| 1988 | 1981 | "queue_size %zu > ctrl sqsize %u, clamping down\n", |
| 1989 | 1982 | opts->queue_size, ctrl->ctrl.sqsize + 1); |
| 1990 | − opts->queue_size = ctrl->ctrl.sqsize + 1; | |
| 1983 | + } | |
| 1984 | + | |
| 1985 | + /* warn if maxcmd is lower than sqsize+1 */ | |
| 1986 | + if (ctrl->ctrl.sqsize + 1 > ctrl->ctrl.maxcmd) { | |
| 1987 | + dev_warn(ctrl->ctrl.device, | |
| 1988 | + "sqsize %u > ctrl maxcmd %u, clamping down\n", | |
| 1989 | + ctrl->ctrl.sqsize + 1, ctrl->ctrl.maxcmd); | |
| 1990 | + ctrl->ctrl.sqsize = ctrl->ctrl.maxcmd - 1; | |
| 1991 | 1991 | } |
| 1992 | 1992 | |
| 1993 | 1993 | if (opts->nr_io_queues) { |
| @@ -2013,15 +2013,16 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, · 19 unmodified lines | ||
| 2013 | 2013 | return &ctrl->ctrl; |
| 2014 | 2014 | |
| 2015 | 2015 | out_remove_admin_queue: |
| 2016 | + nvme_rdma_stop_queue(&ctrl->queues[0]); | |
| 2016 | 2017 | nvme_rdma_destroy_admin_queue(ctrl, true); |
| 2017 | −out_kfree_queues: | |
| 2018 | − kfree(ctrl->queues); | |
| 2019 | 2018 | out_uninit_ctrl: |
| 2020 | 2019 | nvme_uninit_ctrl(&ctrl->ctrl); |
| 2021 | 2020 | nvme_put_ctrl(&ctrl->ctrl); |
| 2022 | 2021 | if (ret > 0) |
| 2023 | 2022 | ret = -EIO; |
| 2024 | 2023 | return ERR_PTR(ret); |
| 2024 | +out_kfree_queues: | |
| 2025 | + kfree(ctrl->queues); | |
| 2025 | 2026 | out_free_ctrl: |
| 2026 | 2027 | kfree(ctrl); |
| 2027 | 2028 | return ERR_PTR(ret); |
| @@ -686,6 +686,14 @@ static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl) · 685 unmodified lines | ||
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | ctrl->csts = NVME_CSTS_RDY; |
| 689 | + | |
| 690 | + /* | |
| 691 | + * Controllers that are not yet enabled should not really enforce the | |
| 692 | + * keep alive timeout, but we still want to track a timeout and cleanup | |
| 693 | + * in case a host died before it enabled the controller. Hence, simply | |
| 694 | + * reset the keep alive timer when the controller is enabled. | |
| 695 | + */ | |
| 696 | + mod_delayed_work(system_wq, &ctrl->ka_work, ctrl->kato * HZ); | |
| 689 | 697 | } |
| 690 | 698 | |
| 691 | 699 | static void nvmet_clear_ctrl(struct nvmet_ctrl *ctrl) |
| @@ -3592,7 +3592,7 @@ fc_bsg_job_timeout(struct request *req) · 3591 unmodified lines | ||
| 3592 | 3592 | |
| 3593 | 3593 | /* the blk_end_sync_io() doesn't check the error */ |
| 3594 | 3594 | if (inflight) |
| 3595 | − blk_mq_complete_request(req); | |
| 3595 | + __blk_complete_request(req); | |
| 3596 | 3596 | return BLK_EH_DONE; |
| 3597 | 3597 | } |
| 3598 | 3598 | |
| @@ -22,7 +22,6 @@ struct dentry; · 21 unmodified lines | ||
| 22 | 22 | */ |
| 23 | 23 | enum wb_state { |
| 24 | 24 | WB_registered, /* bdi_register() was done */ |
| 25 | − WB_shutting_down, /* wb_shutdown() in progress */ | |
| 26 | 25 | WB_writeback_running, /* Writeback is in progress */ |
| 27 | 26 | WB_has_dirty_io, /* Dirty inodes on ->b_{dirty|io|more_io} */ |
| 28 | 27 | WB_start_all, /* nr_pages == 0 (all) work pending */ |
| @@ -189,6 +188,7 @@ struct backing_dev_info { · 160 unmodified lines | ||
| 189 | 188 | #ifdef CONFIG_CGROUP_WRITEBACK |
| 190 | 189 | struct radix_tree_root cgwb_tree; /* radix tree of active cgroup wbs */ |
| 191 | 190 | struct rb_root cgwb_congested_tree; /* their congested states */ |
| 191 | + struct mutex cgwb_release_mutex; /* protect shutdown of wb structs */ | |
| 192 | 192 | #else |
| 193 | 193 | struct bdi_writeback_congested *wb_congested; |
| 194 | 194 | #endif |
| @@ -53,6 +53,9 @@ enum { · 52 unmodified lines | ||
| 53 | 53 | /* These are client behavior specific flags. */ |
| 54 | 54 | #define NBD_CFLAG_DESTROY_ON_DISCONNECT (1 << 0) /* delete the nbd device on |
| 55 | 55 | disconnect. */ |
| 56 | +#define NBD_CFLAG_DISCONNECT_ON_CLOSE (1 << 1) /* disconnect the nbd device on | |
| 57 | + * close by last opener. | |
| 58 | + */ | |
| 56 | 59 | |
| 57 | 60 | /* userspace doesn't need the nbd_device structure */ |
| 58 | 61 | |
| @@ -359,15 +359,8 @@ static void wb_shutdown(struct bdi_writeback *wb) · 358 unmodified lines | ||
| 359 | 359 | spin_lock_bh(&wb->work_lock); |
| 360 | 360 | if (!test_and_clear_bit(WB_registered, &wb->state)) { |
| 361 | 361 | spin_unlock_bh(&wb->work_lock); |
| 362 | − /* | |
| 363 | − * Wait for wb shutdown to finish if someone else is just | |
| 364 | − * running wb_shutdown(). Otherwise we could proceed to wb / | |
| 365 | − * bdi destruction before wb_shutdown() is finished. | |
| 366 | − */ | |
| 367 | − wait_on_bit(&wb->state, WB_shutting_down, TASK_UNINTERRUPTIBLE); | |
| 368 | 362 | return; |
| 369 | 363 | } |
| 370 | − set_bit(WB_shutting_down, &wb->state); | |
| 371 | 364 | spin_unlock_bh(&wb->work_lock); |
| 372 | 365 | |
| 373 | 366 | cgwb_remove_from_bdi_list(wb); |
| @@ -379,12 +372,6 @@ static void wb_shutdown(struct bdi_writeback *wb) · 5 unmodified lines | ||
| 379 | 372 | mod_delayed_work(bdi_wq, &wb->dwork, 0); |
| 380 | 373 | flush_delayed_work(&wb->dwork); |
| 381 | 374 | WARN_ON(!list_empty(&wb->work_list)); |
| 382 | − /* | |
| 383 | − * Make sure bit gets cleared after shutdown is finished. Matches with | |
| 384 | − * the barrier provided by test_and_clear_bit() above. | |
| 385 | − */ | |
| 386 | − smp_wmb(); | |
| 387 | − clear_and_wake_up_bit(WB_shutting_down, &wb->state); | |
| 388 | 375 | } |
| 389 | 376 | |
| 390 | 377 | static void wb_exit(struct bdi_writeback *wb) |
| @@ -508,10 +495,12 @@ static void cgwb_release_workfn(struct work_struct *work) · 117 unmodified lines | ||
| 508 | 495 | struct bdi_writeback *wb = container_of(work, struct bdi_writeback, |
| 509 | 496 | release_work); |
| 510 | 497 | |
| 498 | + mutex_lock(&wb->bdi->cgwb_release_mutex); | |
| 511 | 499 | wb_shutdown(wb); |
| 512 | 500 | |
| 513 | 501 | css_put(wb->memcg_css); |
| 514 | 502 | css_put(wb->blkcg_css); |
| 503 | + mutex_unlock(&wb->bdi->cgwb_release_mutex); | |
| 515 | 504 | |
| 516 | 505 | fprop_local_destroy_percpu(&wb->memcg_completions); |
| 517 | 506 | percpu_ref_exit(&wb->refcnt); |
| @@ -697,6 +686,7 @@ static int cgwb_bdi_init(struct backing_dev_info *bdi) · 179 unmodified lines | ||
| 697 | 686 | |
| 698 | 687 | INIT_RADIX_TREE(&bdi->cgwb_tree, GFP_ATOMIC); |
| 699 | 688 | bdi->cgwb_congested_tree = RB_ROOT; |
| 689 | + mutex_init(&bdi->cgwb_release_mutex); | |
| 700 | 690 | |
| 701 | 691 | ret = wb_init(&bdi->wb, bdi, 1, GFP_KERNEL); |
| 702 | 692 | if (!ret) { |
| @@ -717,7 +707,10 @@ static void cgwb_bdi_unregister(struct backing_dev_info *bdi) · 14 unmodified lines | ||
| 717 | 707 | spin_lock_irq(&cgwb_lock); |
| 718 | 708 | radix_tree_for_each_slot(slot, &bdi->cgwb_tree, &iter, 0) |
| 719 | 709 | cgwb_kill(*slot); |
| 710 | + spin_unlock_irq(&cgwb_lock); | |
| 720 | 711 | |
| 712 | + mutex_lock(&bdi->cgwb_release_mutex); | |
| 713 | + spin_lock_irq(&cgwb_lock); | |
| 721 | 714 | while (!list_empty(&bdi->wb_list)) { |
| 722 | 715 | wb = list_first_entry(&bdi->wb_list, struct bdi_writeback, |
| 723 | 716 | bdi_node); |
| @@ -726,6 +719,7 @@ static void cgwb_bdi_unregister(struct backing_dev_info *bdi) · 2 unmodified lines | ||
| 726 | 719 | spin_lock_irq(&cgwb_lock); |
| 727 | 720 | } |
| 728 | 721 | spin_unlock_irq(&cgwb_lock); |
| 722 | + mutex_unlock(&bdi->cgwb_release_mutex); | |
| 729 | 723 | } |
| 730 | 724 | |
| 731 | 725 | /** |