diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-01-25 20:23:34 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-01-25 20:23:34 -0500 |
commit | 8e908e990438173f44819bff3dcef8eba496ed97 (patch) | |
tree | 6c84e48d699397ab66e0e839a45db120a18d951b | |
parent | 440e996095586967c39adb623e8428c435d59fa0 (diff) | |
parent | 76d697d10769048e5721510100bf3a9413a56385 (diff) |
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull two block layer fixes from Jens Axboe:
"Two small patches that should make it into 3.19:
- a fixup from me for NVMe, making the cq_vector a signed variable.
Otherwise our -1 comparison fails, and commit 2b25d981790b doesn't
do what it was supposed to.
- a fixup for the hotplug handling for blk-mq from Ming Lei, using
the proper kobject referencing to ensure we release resources at
the right time"
* 'for-linus' of git://git.kernel.dk/linux-block:
blk-mq: fix hctx/ctx kobject use-after-free
NVMe: cq_vector should be signed
-rw-r--r-- | block/blk-mq-sysfs.c | 25 | ||||
-rw-r--r-- | block/blk-mq.c | 6 | ||||
-rw-r--r-- | drivers/block/nvme-core.c | 2 |
3 files changed, 25 insertions, 8 deletions
diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 1630a20d5dcf..6774a0e69867 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c | |||
@@ -15,6 +15,26 @@ | |||
15 | 15 | ||
16 | static void blk_mq_sysfs_release(struct kobject *kobj) | 16 | static void blk_mq_sysfs_release(struct kobject *kobj) |
17 | { | 17 | { |
18 | struct request_queue *q; | ||
19 | |||
20 | q = container_of(kobj, struct request_queue, mq_kobj); | ||
21 | free_percpu(q->queue_ctx); | ||
22 | } | ||
23 | |||
24 | static void blk_mq_ctx_release(struct kobject *kobj) | ||
25 | { | ||
26 | struct blk_mq_ctx *ctx; | ||
27 | |||
28 | ctx = container_of(kobj, struct blk_mq_ctx, kobj); | ||
29 | kobject_put(&ctx->queue->mq_kobj); | ||
30 | } | ||
31 | |||
32 | static void blk_mq_hctx_release(struct kobject *kobj) | ||
33 | { | ||
34 | struct blk_mq_hw_ctx *hctx; | ||
35 | |||
36 | hctx = container_of(kobj, struct blk_mq_hw_ctx, kobj); | ||
37 | kfree(hctx); | ||
18 | } | 38 | } |
19 | 39 | ||
20 | struct blk_mq_ctx_sysfs_entry { | 40 | struct blk_mq_ctx_sysfs_entry { |
@@ -318,13 +338,13 @@ static struct kobj_type blk_mq_ktype = { | |||
318 | static struct kobj_type blk_mq_ctx_ktype = { | 338 | static struct kobj_type blk_mq_ctx_ktype = { |
319 | .sysfs_ops = &blk_mq_sysfs_ops, | 339 | .sysfs_ops = &blk_mq_sysfs_ops, |
320 | .default_attrs = default_ctx_attrs, | 340 | .default_attrs = default_ctx_attrs, |
321 | .release = blk_mq_sysfs_release, | 341 | .release = blk_mq_ctx_release, |
322 | }; | 342 | }; |
323 | 343 | ||
324 | static struct kobj_type blk_mq_hw_ktype = { | 344 | static struct kobj_type blk_mq_hw_ktype = { |
325 | .sysfs_ops = &blk_mq_hw_sysfs_ops, | 345 | .sysfs_ops = &blk_mq_hw_sysfs_ops, |
326 | .default_attrs = default_hw_ctx_attrs, | 346 | .default_attrs = default_hw_ctx_attrs, |
327 | .release = blk_mq_sysfs_release, | 347 | .release = blk_mq_hctx_release, |
328 | }; | 348 | }; |
329 | 349 | ||
330 | static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) | 350 | static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) |
@@ -355,6 +375,7 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) | |||
355 | return ret; | 375 | return ret; |
356 | 376 | ||
357 | hctx_for_each_ctx(hctx, ctx, i) { | 377 | hctx_for_each_ctx(hctx, ctx, i) { |
378 | kobject_get(&q->mq_kobj); | ||
358 | ret = kobject_add(&ctx->kobj, &hctx->kobj, "cpu%u", ctx->cpu); | 379 | ret = kobject_add(&ctx->kobj, &hctx->kobj, "cpu%u", ctx->cpu); |
359 | if (ret) | 380 | if (ret) |
360 | break; | 381 | break; |
diff --git a/block/blk-mq.c b/block/blk-mq.c index 2f95747c287e..9ee3b87c4498 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c | |||
@@ -1641,10 +1641,8 @@ static void blk_mq_free_hw_queues(struct request_queue *q, | |||
1641 | struct blk_mq_hw_ctx *hctx; | 1641 | struct blk_mq_hw_ctx *hctx; |
1642 | unsigned int i; | 1642 | unsigned int i; |
1643 | 1643 | ||
1644 | queue_for_each_hw_ctx(q, hctx, i) { | 1644 | queue_for_each_hw_ctx(q, hctx, i) |
1645 | free_cpumask_var(hctx->cpumask); | 1645 | free_cpumask_var(hctx->cpumask); |
1646 | kfree(hctx); | ||
1647 | } | ||
1648 | } | 1646 | } |
1649 | 1647 | ||
1650 | static int blk_mq_init_hctx(struct request_queue *q, | 1648 | static int blk_mq_init_hctx(struct request_queue *q, |
@@ -2002,11 +2000,9 @@ void blk_mq_free_queue(struct request_queue *q) | |||
2002 | 2000 | ||
2003 | percpu_ref_exit(&q->mq_usage_counter); | 2001 | percpu_ref_exit(&q->mq_usage_counter); |
2004 | 2002 | ||
2005 | free_percpu(q->queue_ctx); | ||
2006 | kfree(q->queue_hw_ctx); | 2003 | kfree(q->queue_hw_ctx); |
2007 | kfree(q->mq_map); | 2004 | kfree(q->mq_map); |
2008 | 2005 | ||
2009 | q->queue_ctx = NULL; | ||
2010 | q->queue_hw_ctx = NULL; | 2006 | q->queue_hw_ctx = NULL; |
2011 | q->mq_map = NULL; | 2007 | q->mq_map = NULL; |
2012 | 2008 | ||
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c index cb529e9a82dd..d826bf3e62c8 100644 --- a/drivers/block/nvme-core.c +++ b/drivers/block/nvme-core.c | |||
@@ -106,7 +106,7 @@ struct nvme_queue { | |||
106 | dma_addr_t cq_dma_addr; | 106 | dma_addr_t cq_dma_addr; |
107 | u32 __iomem *q_db; | 107 | u32 __iomem *q_db; |
108 | u16 q_depth; | 108 | u16 q_depth; |
109 | u16 cq_vector; | 109 | s16 cq_vector; |
110 | u16 sq_head; | 110 | u16 sq_head; |
111 | u16 sq_tail; | 111 | u16 sq_tail; |
112 | u16 cq_head; | 112 | u16 cq_head; |