Skip to content

Commit 429fba1

Browse files
committed
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
2 parents 3b04689 + 47b1682 commit 429fba1

File tree

11 files changed

+110
-75
lines changed

11 files changed

+110
-75
lines changed

block/bfq-iosched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static bool bfq_symmetric_scenario(struct bfq_data *bfqd)
674674
* at least two nodes.
675675
*/
676676
return !(varied_queue_weights || multiple_classes_busy
677-
#ifdef BFQ_GROUP_IOSCHED_ENABLED
677+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
678678
|| bfqd->num_groups_with_pending_reqs > 0
679679
#endif
680680
);

block/bfq-wf2q.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ static void __bfq_activate_entity(struct bfq_entity *entity,
10121012
entity->on_st = true;
10131013
}
10141014

1015-
#ifdef BFQ_GROUP_IOSCHED_ENABLED
1015+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
10161016
if (!bfq_entity_to_bfqq(entity)) { /* bfq_group */
10171017
struct bfq_group *bfqg =
10181018
container_of(entity, struct bfq_group, entity);

block/blk-core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,6 @@ static int blk_cloned_rq_check_limits(struct request_queue *q,
12451245
*/
12461246
blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *rq)
12471247
{
1248-
blk_qc_t unused;
1249-
12501248
if (blk_cloned_rq_check_limits(q, rq))
12511249
return BLK_STS_IOERR;
12521250

@@ -1262,7 +1260,7 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *
12621260
* bypass a potential scheduler on the bottom device for
12631261
* insert.
12641262
*/
1265-
return blk_mq_try_issue_directly(rq->mq_hctx, rq, &unused, true, true);
1263+
return blk_mq_request_issue_directly(rq, true);
12661264
}
12671265
EXPORT_SYMBOL_GPL(blk_insert_cloned_request);
12681266

block/blk-mq-sched.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,12 @@ void blk_mq_sched_insert_requests(struct blk_mq_hw_ctx *hctx,
423423
* busy in case of 'none' scheduler, and this way may save
424424
* us one extra enqueue & dequeue to sw queue.
425425
*/
426-
if (!hctx->dispatch_busy && !e && !run_queue_async)
426+
if (!hctx->dispatch_busy && !e && !run_queue_async) {
427427
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);
430432
}
431433

432434
blk_mq_run_hw_queue(hctx, run_queue_async);

block/blk-mq.c

Lines changed: 68 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,11 +1711,12 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
17111711
unsigned int depth;
17121712

17131713
list_splice_init(&plug->mq_list, &list);
1714-
plug->rq_count = 0;
17151714

17161715
if (plug->rq_count > 2 && plug->multiple_queues)
17171716
list_sort(NULL, &list, plug_rq_cmp);
17181717

1718+
plug->rq_count = 0;
1719+
17191720
this_q = NULL;
17201721
this_hctx = NULL;
17211722
this_ctx = NULL;
@@ -1800,103 +1801,107 @@ static blk_status_t __blk_mq_issue_directly(struct blk_mq_hw_ctx *hctx,
18001801
return ret;
18011802
}
18021803

1803-
blk_status_t blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
1804+
static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
18041805
struct request *rq,
18051806
blk_qc_t *cookie,
1806-
bool bypass, bool last)
1807+
bool bypass_insert, bool last)
18071808
{
18081809
struct request_queue *q = rq->q;
18091810
bool run_queue = true;
1810-
blk_status_t ret = BLK_STS_RESOURCE;
1811-
int srcu_idx;
1812-
bool force = false;
18131811

1814-
hctx_lock(hctx, &srcu_idx);
18151812
/*
1816-
* hctx_lock is needed before checking quiesced flag.
1813+
* RCU or SRCU read lock is needed before checking quiesced flag.
18171814
*
1818-
* When queue is stopped or quiesced, ignore 'bypass', insert
1819-
* and return BLK_STS_OK to caller, and avoid driver to try to
1820-
* dispatch again.
1815+
* When queue is stopped or quiesced, ignore 'bypass_insert' from
1816+
* blk_mq_request_issue_directly(), and return BLK_STS_OK to caller,
1817+
* and avoid driver to try to dispatch again.
18211818
*/
1822-
if (unlikely(blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(q))) {
1819+
if (blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(q)) {
18231820
run_queue = false;
1824-
bypass = false;
1825-
goto out_unlock;
1821+
bypass_insert = false;
1822+
goto insert;
18261823
}
18271824

1828-
if (unlikely(q->elevator && !bypass))
1829-
goto out_unlock;
1825+
if (q->elevator && !bypass_insert)
1826+
goto insert;
18301827

18311828
if (!blk_mq_get_dispatch_budget(hctx))
1832-
goto out_unlock;
1829+
goto insert;
18331830

18341831
if (!blk_mq_get_driver_tag(rq)) {
18351832
blk_mq_put_dispatch_budget(hctx);
1836-
goto out_unlock;
1833+
goto insert;
18371834
}
18381835

1839-
/*
1840-
* Always add a request that has been through
1841-
*.queue_rq() to the hardware dispatch list.
1842-
*/
1843-
force = true;
1844-
ret = __blk_mq_issue_directly(hctx, rq, cookie, last);
1845-
out_unlock:
1836+
return __blk_mq_issue_directly(hctx, rq, cookie, last);
1837+
insert:
1838+
if (bypass_insert)
1839+
return BLK_STS_RESOURCE;
1840+
1841+
blk_mq_request_bypass_insert(rq, run_queue);
1842+
return BLK_STS_OK;
1843+
}
1844+
1845+
static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
1846+
struct request *rq, blk_qc_t *cookie)
1847+
{
1848+
blk_status_t ret;
1849+
int srcu_idx;
1850+
1851+
might_sleep_if(hctx->flags & BLK_MQ_F_BLOCKING);
1852+
1853+
hctx_lock(hctx, &srcu_idx);
1854+
1855+
ret = __blk_mq_try_issue_directly(hctx, rq, cookie, false, true);
1856+
if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE)
1857+
blk_mq_request_bypass_insert(rq, true);
1858+
else if (ret != BLK_STS_OK)
1859+
blk_mq_end_request(rq, ret);
1860+
1861+
hctx_unlock(hctx, srcu_idx);
1862+
}
1863+
1864+
blk_status_t blk_mq_request_issue_directly(struct request *rq, bool last)
1865+
{
1866+
blk_status_t ret;
1867+
int srcu_idx;
1868+
blk_qc_t unused_cookie;
1869+
struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
1870+
1871+
hctx_lock(hctx, &srcu_idx);
1872+
ret = __blk_mq_try_issue_directly(hctx, rq, &unused_cookie, true, last);
18461873
hctx_unlock(hctx, srcu_idx);
1847-
switch (ret) {
1848-
case BLK_STS_OK:
1849-
break;
1850-
case BLK_STS_DEV_RESOURCE:
1851-
case BLK_STS_RESOURCE:
1852-
if (force) {
1853-
blk_mq_request_bypass_insert(rq, run_queue);
1854-
/*
1855-
* We have to return BLK_STS_OK for the DM
1856-
* to avoid livelock. Otherwise, we return
1857-
* the real result to indicate whether the
1858-
* request is direct-issued successfully.
1859-
*/
1860-
ret = bypass ? BLK_STS_OK : ret;
1861-
} else if (!bypass) {
1862-
blk_mq_sched_insert_request(rq, false,
1863-
run_queue, false);
1864-
}
1865-
break;
1866-
default:
1867-
if (!bypass)
1868-
blk_mq_end_request(rq, ret);
1869-
break;
1870-
}
18711874

18721875
return ret;
18731876
}
18741877

18751878
void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
18761879
struct list_head *list)
18771880
{
1878-
blk_qc_t unused;
1879-
blk_status_t ret = BLK_STS_OK;
1880-
18811881
while (!list_empty(list)) {
1882+
blk_status_t ret;
18821883
struct request *rq = list_first_entry(list, struct request,
18831884
queuelist);
18841885

18851886
list_del_init(&rq->queuelist);
1886-
if (ret == BLK_STS_OK)
1887-
ret = blk_mq_try_issue_directly(hctx, rq, &unused,
1888-
false,
1887+
ret = blk_mq_request_issue_directly(rq, list_empty(list));
1888+
if (ret != BLK_STS_OK) {
1889+
if (ret == BLK_STS_RESOURCE ||
1890+
ret == BLK_STS_DEV_RESOURCE) {
1891+
blk_mq_request_bypass_insert(rq,
18891892
list_empty(list));
1890-
else
1891-
blk_mq_sched_insert_request(rq, false, true, false);
1893+
break;
1894+
}
1895+
blk_mq_end_request(rq, ret);
1896+
}
18921897
}
18931898

18941899
/*
18951900
* If we didn't flush the entire list, we could have told
18961901
* the driver there was more coming, but that turned out to
18971902
* be a lie.
18981903
*/
1899-
if (ret != BLK_STS_OK && hctx->queue->mq_ops->commit_rqs)
1904+
if (!list_empty(list) && hctx->queue->mq_ops->commit_rqs)
19001905
hctx->queue->mq_ops->commit_rqs(hctx);
19011906
}
19021907

@@ -2003,19 +2008,21 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
20032008
plug->rq_count--;
20042009
}
20052010
blk_add_rq_to_plug(plug, rq);
2011+
trace_block_plug(q);
20062012

20072013
blk_mq_put_ctx(data.ctx);
20082014

20092015
if (same_queue_rq) {
20102016
data.hctx = same_queue_rq->mq_hctx;
2017+
trace_block_unplug(q, 1, true);
20112018
blk_mq_try_issue_directly(data.hctx, same_queue_rq,
2012-
&cookie, false, true);
2019+
&cookie);
20132020
}
20142021
} else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
20152022
!data.hctx->dispatch_busy)) {
20162023
blk_mq_put_ctx(data.ctx);
20172024
blk_mq_bio_to_request(rq, bio);
2018-
blk_mq_try_issue_directly(data.hctx, rq, &cookie, false, true);
2025+
blk_mq_try_issue_directly(data.hctx, rq, &cookie);
20192026
} else {
20202027
blk_mq_put_ctx(data.ctx);
20212028
blk_mq_bio_to_request(rq, bio);
@@ -2332,7 +2339,7 @@ static int blk_mq_init_hctx(struct request_queue *q,
23322339
return 0;
23332340

23342341
free_fq:
2335-
kfree(hctx->fq);
2342+
blk_free_flush_queue(hctx->fq);
23362343
exit_hctx:
23372344
if (set->ops->exit_hctx)
23382345
set->ops->exit_hctx(hctx, hctx_idx);

block/blk-mq.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ void blk_mq_request_bypass_insert(struct request *rq, bool run_queue);
7070
void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
7171
struct list_head *list);
7272

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);
7775
void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
7876
struct list_head *list);
7977

drivers/block/null_blk_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,11 @@ static int __init null_init(void)
17481748
return -EINVAL;
17491749
}
17501750

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+
17511756
if (g_queue_mode == NULL_Q_RQ) {
17521757
pr_err("null_blk: legacy IO path no longer available\n");
17531758
return -EINVAL;

drivers/block/paride/pcd.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static void pcd_init_units(void)
314314
disk->queue = blk_mq_init_sq_queue(&cd->tag_set, &pcd_mq_ops,
315315
1, BLK_MQ_F_SHOULD_MERGE);
316316
if (IS_ERR(disk->queue)) {
317+
put_disk(disk);
317318
disk->queue = NULL;
318319
continue;
319320
}
@@ -750,6 +751,8 @@ static int pcd_detect(void)
750751

751752
printk("%s: No CD-ROM drive found\n", name);
752753
for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
754+
if (!cd->disk)
755+
continue;
753756
blk_cleanup_queue(cd->disk->queue);
754757
cd->disk->queue = NULL;
755758
blk_mq_free_tag_set(&cd->tag_set);
@@ -1010,8 +1013,14 @@ static int __init pcd_init(void)
10101013
pcd_probe_capabilities();
10111014

10121015
if (register_blkdev(major, name)) {
1013-
for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++)
1016+
for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
1017+
if (!cd->disk)
1018+
continue;
1019+
1020+
blk_cleanup_queue(cd->disk->queue);
1021+
blk_mq_free_tag_set(&cd->tag_set);
10141022
put_disk(cd->disk);
1023+
}
10151024
return -EBUSY;
10161025
}
10171026

@@ -1032,6 +1041,9 @@ static void __exit pcd_exit(void)
10321041
int unit;
10331042

10341043
for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
1044+
if (!cd->disk)
1045+
continue;
1046+
10351047
if (cd->present) {
10361048
del_gendisk(cd->disk);
10371049
pi_release(cd->pi);

drivers/block/paride/pf.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static int pf_detect(void)
762762

763763
printk("%s: No ATAPI disk detected\n", name);
764764
for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
765+
if (!pf->disk)
766+
continue;
765767
blk_cleanup_queue(pf->disk->queue);
766768
pf->disk->queue = NULL;
767769
blk_mq_free_tag_set(&pf->tag_set);
@@ -1029,8 +1031,13 @@ static int __init pf_init(void)
10291031
pf_busy = 0;
10301032

10311033
if (register_blkdev(major, name)) {
1032-
for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++)
1034+
for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
1035+
if (!pf->disk)
1036+
continue;
1037+
blk_cleanup_queue(pf->disk->queue);
1038+
blk_mq_free_tag_set(&pf->tag_set);
10331039
put_disk(pf->disk);
1040+
}
10341041
return -EBUSY;
10351042
}
10361043

@@ -1051,6 +1058,9 @@ static void __exit pf_exit(void)
10511058
int unit;
10521059
unregister_blkdev(major, name);
10531060
for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
1061+
if (!pf->disk)
1062+
continue;
1063+
10541064
if (pf->present)
10551065
del_gendisk(pf->disk);
10561066

drivers/block/xsysace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,8 @@ static int ace_setup(struct ace_device *ace)
10901090
return 0;
10911091

10921092
err_read:
1093+
/* prevent double queue cleanup */
1094+
ace->gd->queue = NULL;
10931095
put_disk(ace->gd);
10941096
err_alloc_disk:
10951097
blk_cleanup_queue(ace->queue);

fs/io_uring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
22152215
fput(ctx->user_files[i]);
22162216

22172217
kfree(ctx->user_files);
2218+
ctx->user_files = NULL;
22182219
ctx->nr_user_files = 0;
22192220
return ret;
22202221
}

0 commit comments

Comments
 (0)