Merge tag 'for-linus-20190407' of git://git.kernel.dk/linux-block

Pull block fixes from Jens Axboe:

- Fixups for the pf/pcd queue handling (YueHaibing)

- Revert of the three direct issue changes as they have been proven to
cause an issue with dm-mpath (Bart)

- Plug rq_count reset fix (Dongli)

- io_uring double free in fileset registration error handling (me)

- Make null_blk handle bad numa node passed in (John)

- BFQ ifdef fix (Konstantin)

- Flush queue leak fix (Shenghui)

- Plug trace fix (Yufen)

* tag 'for-linus-20190407' of git://git.kernel.dk/linux-block:
xsysace: Fix error handling in ace_setup
null_blk: prevent crash from bad home_node value
block: Revert v5.0 blk_mq_request_issue_directly() changes
paride/pcd: Fix potential NULL pointer dereference and mem leak
blk-mq: do not reset plug->rq_count before the list is sorted
paride/pf: Fix potential NULL pointer dereference
io_uring: fix double free in case of fileset regitration failure
blk-mq: add trace block plug and unplug for multiple queues
block: use blk_free_flush_queue() to free hctx->fq in blk_mq_init_hctx
block/bfq: fix ifdef for CONFIG_BFQ_GROUP_IOSCHED=y

+1 -1
block/bfq-iosched.c
··· 674 674 * at least two nodes. 675 675 */ 676 676 return !(varied_queue_weights || multiple_classes_busy 677 - #ifdef BFQ_GROUP_IOSCHED_ENABLED 677 + #ifdef CONFIG_BFQ_GROUP_IOSCHED 678 678 || bfqd->num_groups_with_pending_reqs > 0 679 679 #endif 680 680 );
+1 -1
block/bfq-wf2q.c
··· 1012 1012 entity->on_st = true; 1013 1013 } 1014 1014 1015 - #ifdef BFQ_GROUP_IOSCHED_ENABLED 1015 + #ifdef CONFIG_BFQ_GROUP_IOSCHED 1016 1016 if (!bfq_entity_to_bfqq(entity)) { /* bfq_group */ 1017 1017 struct bfq_group *bfqg = 1018 1018 container_of(entity, struct bfq_group, entity);
+1 -3
block/blk-core.c
··· 1245 1245 */ 1246 1246 blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *rq) 1247 1247 { 1248 - blk_qc_t unused; 1249 - 1250 1248 if (blk_cloned_rq_check_limits(q, rq)) 1251 1249 return BLK_STS_IOERR; 1252 1250 ··· 1260 1262 * bypass a potential scheduler on the bottom device for 1261 1263 * insert. 1262 1264 */ 1263 - return blk_mq_try_issue_directly(rq->mq_hctx, rq, &unused, true, true); 1265 + return blk_mq_request_issue_directly(rq, true); 1264 1266 } 1265 1267 EXPORT_SYMBOL_GPL(blk_insert_cloned_request); 1266 1268
+5 -3
block/blk-mq-sched.c
··· 423 423 * busy in case of 'none' scheduler, and this way may save 424 424 * us one extra enqueue & dequeue to sw queue. 425 425 */ 426 - if (!hctx->dispatch_busy && !e && !run_queue_async) 426 + if (!hctx->dispatch_busy && !e && !run_queue_async) { 427 427 blk_mq_try_issue_list_directly(hctx, list); 428 - else 429 - blk_mq_insert_requests(hctx, ctx, list); 428 + if (list_empty(list)) 429 + return; 430 + } 431 + blk_mq_insert_requests(hctx, ctx, list); 430 432 } 431 433 432 434 blk_mq_run_hw_queue(hctx, run_queue_async);
+68 -61
block/blk-mq.c
··· 1711 1711 unsigned int depth; 1712 1712 1713 1713 list_splice_init(&plug->mq_list, &list); 1714 - plug->rq_count = 0; 1715 1714 1716 1715 if (plug->rq_count > 2 && plug->multiple_queues) 1717 1716 list_sort(NULL, &list, plug_rq_cmp); 1717 + 1718 + plug->rq_count = 0; 1718 1719 1719 1720 this_q = NULL; 1720 1721 this_hctx = NULL; ··· 1801 1800 return ret; 1802 1801 } 1803 1802 1804 - blk_status_t blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, 1803 + static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, 1805 1804 struct request *rq, 1806 1805 blk_qc_t *cookie, 1807 - bool bypass, bool last) 1806 + bool bypass_insert, bool last) 1808 1807 { 1809 1808 struct request_queue *q = rq->q; 1810 1809 bool run_queue = true; 1811 - blk_status_t ret = BLK_STS_RESOURCE; 1812 - int srcu_idx; 1813 - bool force = false; 1814 1810 1815 - hctx_lock(hctx, &srcu_idx); 1816 1811 /* 1817 - * hctx_lock is needed before checking quiesced flag. 1812 + * RCU or SRCU read lock is needed before checking quiesced flag. 1818 1813 * 1819 - * When queue is stopped or quiesced, ignore 'bypass', insert 1820 - * and return BLK_STS_OK to caller, and avoid driver to try to 1821 - * dispatch again. 1814 + * When queue is stopped or quiesced, ignore 'bypass_insert' from 1815 + * blk_mq_request_issue_directly(), and return BLK_STS_OK to caller, 1816 + * and avoid driver to try to dispatch again. 1822 1817 */ 1823 - if (unlikely(blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(q))) { 1818 + if (blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(q)) { 1824 1819 run_queue = false; 1825 - bypass = false; 1826 - goto out_unlock; 1820 + bypass_insert = false; 1821 + goto insert; 1827 1822 } 1828 1823 1829 - if (unlikely(q->elevator && !bypass)) 1830 - goto out_unlock; 1824 + if (q->elevator && !bypass_insert) 1825 + goto insert; 1831 1826 1832 1827 if (!blk_mq_get_dispatch_budget(hctx)) 1833 - goto out_unlock; 1828 + goto insert; 1834 1829 1835 1830 if (!blk_mq_get_driver_tag(rq)) { 1836 1831 blk_mq_put_dispatch_budget(hctx); 1837 - goto out_unlock; 1832 + goto insert; 1838 1833 } 1839 1834 1840 - /* 1841 - * Always add a request that has been through 1842 - *.queue_rq() to the hardware dispatch list. 1843 - */ 1844 - force = true; 1845 - ret = __blk_mq_issue_directly(hctx, rq, cookie, last); 1846 - out_unlock: 1835 + return __blk_mq_issue_directly(hctx, rq, cookie, last); 1836 + insert: 1837 + if (bypass_insert) 1838 + return BLK_STS_RESOURCE; 1839 + 1840 + blk_mq_request_bypass_insert(rq, run_queue); 1841 + return BLK_STS_OK; 1842 + } 1843 + 1844 + static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, 1845 + struct request *rq, blk_qc_t *cookie) 1846 + { 1847 + blk_status_t ret; 1848 + int srcu_idx; 1849 + 1850 + might_sleep_if(hctx->flags & BLK_MQ_F_BLOCKING); 1851 + 1852 + hctx_lock(hctx, &srcu_idx); 1853 + 1854 + ret = __blk_mq_try_issue_directly(hctx, rq, cookie, false, true); 1855 + if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE) 1856 + blk_mq_request_bypass_insert(rq, true); 1857 + else if (ret != BLK_STS_OK) 1858 + blk_mq_end_request(rq, ret); 1859 + 1847 1860 hctx_unlock(hctx, srcu_idx); 1848 - switch (ret) { 1849 - case BLK_STS_OK: 1850 - break; 1851 - case BLK_STS_DEV_RESOURCE: 1852 - case BLK_STS_RESOURCE: 1853 - if (force) { 1854 - blk_mq_request_bypass_insert(rq, run_queue); 1855 - /* 1856 - * We have to return BLK_STS_OK for the DM 1857 - * to avoid livelock. Otherwise, we return 1858 - * the real result to indicate whether the 1859 - * request is direct-issued successfully. 1860 - */ 1861 - ret = bypass ? BLK_STS_OK : ret; 1862 - } else if (!bypass) { 1863 - blk_mq_sched_insert_request(rq, false, 1864 - run_queue, false); 1865 - } 1866 - break; 1867 - default: 1868 - if (!bypass) 1869 - blk_mq_end_request(rq, ret); 1870 - break; 1871 - } 1861 + } 1862 + 1863 + blk_status_t blk_mq_request_issue_directly(struct request *rq, bool last) 1864 + { 1865 + blk_status_t ret; 1866 + int srcu_idx; 1867 + blk_qc_t unused_cookie; 1868 + struct blk_mq_hw_ctx *hctx = rq->mq_hctx; 1869 + 1870 + hctx_lock(hctx, &srcu_idx); 1871 + ret = __blk_mq_try_issue_directly(hctx, rq, &unused_cookie, true, last); 1872 + hctx_unlock(hctx, srcu_idx); 1872 1873 1873 1874 return ret; 1874 1875 } ··· 1878 1875 void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, 1879 1876 struct list_head *list) 1880 1877 { 1881 - blk_qc_t unused; 1882 - blk_status_t ret = BLK_STS_OK; 1883 - 1884 1878 while (!list_empty(list)) { 1879 + blk_status_t ret; 1885 1880 struct request *rq = list_first_entry(list, struct request, 1886 1881 queuelist); 1887 1882 1888 1883 list_del_init(&rq->queuelist); 1889 - if (ret == BLK_STS_OK) 1890 - ret = blk_mq_try_issue_directly(hctx, rq, &unused, 1891 - false, 1884 + ret = blk_mq_request_issue_directly(rq, list_empty(list)); 1885 + if (ret != BLK_STS_OK) { 1886 + if (ret == BLK_STS_RESOURCE || 1887 + ret == BLK_STS_DEV_RESOURCE) { 1888 + blk_mq_request_bypass_insert(rq, 1892 1889 list_empty(list)); 1893 - else 1894 - blk_mq_sched_insert_request(rq, false, true, false); 1890 + break; 1891 + } 1892 + blk_mq_end_request(rq, ret); 1893 + } 1895 1894 } 1896 1895 1897 1896 /* ··· 1901 1896 * the driver there was more coming, but that turned out to 1902 1897 * be a lie. 1903 1898 */ 1904 - if (ret != BLK_STS_OK && hctx->queue->mq_ops->commit_rqs) 1899 + if (!list_empty(list) && hctx->queue->mq_ops->commit_rqs) 1905 1900 hctx->queue->mq_ops->commit_rqs(hctx); 1906 1901 } 1907 1902 ··· 2008 2003 plug->rq_count--; 2009 2004 } 2010 2005 blk_add_rq_to_plug(plug, rq); 2006 + trace_block_plug(q); 2011 2007 2012 2008 blk_mq_put_ctx(data.ctx); 2013 2009 2014 2010 if (same_queue_rq) { 2015 2011 data.hctx = same_queue_rq->mq_hctx; 2012 + trace_block_unplug(q, 1, true); 2016 2013 blk_mq_try_issue_directly(data.hctx, same_queue_rq, 2017 - &cookie, false, true); 2014 + &cookie); 2018 2015 } 2019 2016 } else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator && 2020 2017 !data.hctx->dispatch_busy)) { 2021 2018 blk_mq_put_ctx(data.ctx); 2022 2019 blk_mq_bio_to_request(rq, bio); 2023 - blk_mq_try_issue_directly(data.hctx, rq, &cookie, false, true); 2020 + blk_mq_try_issue_directly(data.hctx, rq, &cookie); 2024 2021 } else { 2025 2022 blk_mq_put_ctx(data.ctx); 2026 2023 blk_mq_bio_to_request(rq, bio); ··· 2339 2332 return 0; 2340 2333 2341 2334 free_fq: 2342 - kfree(hctx->fq); 2335 + blk_free_flush_queue(hctx->fq); 2343 2336 exit_hctx: 2344 2337 if (set->ops->exit_hctx) 2345 2338 set->ops->exit_hctx(hctx, hctx_idx);
+2 -4
block/blk-mq.h
··· 70 70 void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx, 71 71 struct list_head *list); 72 72 73 - blk_status_t blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, 74 - struct request *rq, 75 - blk_qc_t *cookie, 76 - bool bypass, bool last); 73 + /* Used by blk_insert_cloned_request() to issue request directly */ 74 + blk_status_t blk_mq_request_issue_directly(struct request *rq, bool last); 77 75 void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, 78 76 struct list_head *list); 79 77
+5
drivers/block/null_blk_main.c
··· 1748 1748 return -EINVAL; 1749 1749 } 1750 1750 1751 + if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) { 1752 + pr_err("null_blk: invalid home_node value\n"); 1753 + g_home_node = NUMA_NO_NODE; 1754 + } 1755 + 1751 1756 if (g_queue_mode == NULL_Q_RQ) { 1752 1757 pr_err("null_blk: legacy IO path no longer available\n"); 1753 1758 return -EINVAL;
+13 -1
drivers/block/paride/pcd.c
··· 314 314 disk->queue = blk_mq_init_sq_queue(&cd->tag_set, &pcd_mq_ops, 315 315 1, BLK_MQ_F_SHOULD_MERGE); 316 316 if (IS_ERR(disk->queue)) { 317 + put_disk(disk); 317 318 disk->queue = NULL; 318 319 continue; 319 320 } ··· 751 750 752 751 printk("%s: No CD-ROM drive found\n", name); 753 752 for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) { 753 + if (!cd->disk) 754 + continue; 754 755 blk_cleanup_queue(cd->disk->queue); 755 756 cd->disk->queue = NULL; 756 757 blk_mq_free_tag_set(&cd->tag_set); ··· 1013 1010 pcd_probe_capabilities(); 1014 1011 1015 1012 if (register_blkdev(major, name)) { 1016 - for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) 1013 + for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) { 1014 + if (!cd->disk) 1015 + continue; 1016 + 1017 + blk_cleanup_queue(cd->disk->queue); 1018 + blk_mq_free_tag_set(&cd->tag_set); 1017 1019 put_disk(cd->disk); 1020 + } 1018 1021 return -EBUSY; 1019 1022 } 1020 1023 ··· 1041 1032 int unit; 1042 1033 1043 1034 for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) { 1035 + if (!cd->disk) 1036 + continue; 1037 + 1044 1038 if (cd->present) { 1045 1039 del_gendisk(cd->disk); 1046 1040 pi_release(cd->pi);
+11 -1
drivers/block/paride/pf.c
··· 762 762 763 763 printk("%s: No ATAPI disk detected\n", name); 764 764 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { 765 + if (!pf->disk) 766 + continue; 765 767 blk_cleanup_queue(pf->disk->queue); 766 768 pf->disk->queue = NULL; 767 769 blk_mq_free_tag_set(&pf->tag_set); ··· 1031 1029 pf_busy = 0; 1032 1030 1033 1031 if (register_blkdev(major, name)) { 1034 - for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) 1032 + for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { 1033 + if (!pf->disk) 1034 + continue; 1035 + blk_cleanup_queue(pf->disk->queue); 1036 + blk_mq_free_tag_set(&pf->tag_set); 1035 1037 put_disk(pf->disk); 1038 + } 1036 1039 return -EBUSY; 1037 1040 } 1038 1041 ··· 1058 1051 int unit; 1059 1052 unregister_blkdev(major, name); 1060 1053 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { 1054 + if (!pf->disk) 1055 + continue; 1056 + 1061 1057 if (pf->present) 1062 1058 del_gendisk(pf->disk); 1063 1059
+2
drivers/block/xsysace.c
··· 1090 1090 return 0; 1091 1091 1092 1092 err_read: 1093 + /* prevent double queue cleanup */ 1094 + ace->gd->queue = NULL; 1093 1095 put_disk(ace->gd); 1094 1096 err_alloc_disk: 1095 1097 blk_cleanup_queue(ace->queue);
+1
fs/io_uring.c
··· 2215 2215 fput(ctx->user_files[i]); 2216 2216 2217 2217 kfree(ctx->user_files); 2218 + ctx->user_files = NULL; 2218 2219 ctx->nr_user_files = 0; 2219 2220 return ret; 2220 2221 }