diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-03 14:36:57 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-03 14:36:57 -0500 |
| commit | 0f98c38d725f88d6452af46eed96a3a6791b230a (patch) | |
| tree | 340517dd380752cb6e3ba4a84fb8c0138ca3c1ca | |
| parent | 0dc17d142c8d52cbcc829c09b433cbad20325998 (diff) | |
| parent | e09aae7edec1d20824c60a6f0ca4589f99ada17b (diff) | |
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull final block layer fixes from Jens Axboe:
"Unfortunately the hctx/ctx lifetime fix from last pull had some
issues. This pull request contains a revert of the problematic
commit, and a proper rewrite of it.
The rewrite has been tested by the users complaining about the
regression, and it works fine now. Additionally, I've run testing on
all the blk-mq use cases for it and it passes. So we should
definitely get this into 3.19, to avoid regression for some cases"
* 'for-linus' of git://git.kernel.dk/linux-block:
blk-mq: release mq's kobjects in blk_release_queue()
Revert "blk-mq: fix hctx/ctx kobject use-after-free"
| -rw-r--r-- | block/blk-mq-sysfs.c | 25 | ||||
| -rw-r--r-- | block/blk-mq.c | 23 | ||||
| -rw-r--r-- | block/blk-mq.h | 2 | ||||
| -rw-r--r-- | block/blk-sysfs.c | 2 |
4 files changed, 27 insertions, 25 deletions
diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 6774a0e69867..1630a20d5dcf 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c | |||
| @@ -15,26 +15,6 @@ | |||
| 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); | ||
| 38 | } | 18 | } |
| 39 | 19 | ||
| 40 | struct blk_mq_ctx_sysfs_entry { | 20 | struct blk_mq_ctx_sysfs_entry { |
| @@ -338,13 +318,13 @@ static struct kobj_type blk_mq_ktype = { | |||
| 338 | static struct kobj_type blk_mq_ctx_ktype = { | 318 | static struct kobj_type blk_mq_ctx_ktype = { |
| 339 | .sysfs_ops = &blk_mq_sysfs_ops, | 319 | .sysfs_ops = &blk_mq_sysfs_ops, |
| 340 | .default_attrs = default_ctx_attrs, | 320 | .default_attrs = default_ctx_attrs, |
| 341 | .release = blk_mq_ctx_release, | 321 | .release = blk_mq_sysfs_release, |
| 342 | }; | 322 | }; |
| 343 | 323 | ||
| 344 | static struct kobj_type blk_mq_hw_ktype = { | 324 | static struct kobj_type blk_mq_hw_ktype = { |
| 345 | .sysfs_ops = &blk_mq_hw_sysfs_ops, | 325 | .sysfs_ops = &blk_mq_hw_sysfs_ops, |
| 346 | .default_attrs = default_hw_ctx_attrs, | 326 | .default_attrs = default_hw_ctx_attrs, |
| 347 | .release = blk_mq_hctx_release, | 327 | .release = blk_mq_sysfs_release, |
| 348 | }; | 328 | }; |
| 349 | 329 | ||
| 350 | static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) | 330 | static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) |
| @@ -375,7 +355,6 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) | |||
| 375 | return ret; | 355 | return ret; |
| 376 | 356 | ||
| 377 | hctx_for_each_ctx(hctx, ctx, i) { | 357 | hctx_for_each_ctx(hctx, ctx, i) { |
| 378 | kobject_get(&q->mq_kobj); | ||
| 379 | ret = kobject_add(&ctx->kobj, &hctx->kobj, "cpu%u", ctx->cpu); | 358 | ret = kobject_add(&ctx->kobj, &hctx->kobj, "cpu%u", ctx->cpu); |
| 380 | if (ret) | 359 | if (ret) |
| 381 | break; | 360 | break; |
diff --git a/block/blk-mq.c b/block/blk-mq.c index 9ee3b87c4498..2390c5541e71 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c | |||
| @@ -1867,6 +1867,27 @@ static void blk_mq_add_queue_tag_set(struct blk_mq_tag_set *set, | |||
| 1867 | mutex_unlock(&set->tag_list_lock); | 1867 | mutex_unlock(&set->tag_list_lock); |
| 1868 | } | 1868 | } |
| 1869 | 1869 | ||
| 1870 | /* | ||
| 1871 | * It is the actual release handler for mq, but we do it from | ||
| 1872 | * request queue's release handler for avoiding use-after-free | ||
| 1873 | * and headache because q->mq_kobj shouldn't have been introduced, | ||
| 1874 | * but we can't group ctx/kctx kobj without it. | ||
| 1875 | */ | ||
| 1876 | void blk_mq_release(struct request_queue *q) | ||
| 1877 | { | ||
| 1878 | struct blk_mq_hw_ctx *hctx; | ||
| 1879 | unsigned int i; | ||
| 1880 | |||
| 1881 | /* hctx kobj stays in hctx */ | ||
| 1882 | queue_for_each_hw_ctx(q, hctx, i) | ||
| 1883 | kfree(hctx); | ||
| 1884 | |||
| 1885 | kfree(q->queue_hw_ctx); | ||
| 1886 | |||
| 1887 | /* ctx kobj stays in queue_ctx */ | ||
| 1888 | free_percpu(q->queue_ctx); | ||
| 1889 | } | ||
| 1890 | |||
| 1870 | struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set) | 1891 | struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set) |
| 1871 | { | 1892 | { |
| 1872 | struct blk_mq_hw_ctx **hctxs; | 1893 | struct blk_mq_hw_ctx **hctxs; |
| @@ -2000,10 +2021,8 @@ void blk_mq_free_queue(struct request_queue *q) | |||
| 2000 | 2021 | ||
| 2001 | percpu_ref_exit(&q->mq_usage_counter); | 2022 | percpu_ref_exit(&q->mq_usage_counter); |
| 2002 | 2023 | ||
| 2003 | kfree(q->queue_hw_ctx); | ||
| 2004 | kfree(q->mq_map); | 2024 | kfree(q->mq_map); |
| 2005 | 2025 | ||
| 2006 | q->queue_hw_ctx = NULL; | ||
| 2007 | q->mq_map = NULL; | 2026 | q->mq_map = NULL; |
| 2008 | 2027 | ||
| 2009 | mutex_lock(&all_q_mutex); | 2028 | mutex_lock(&all_q_mutex); |
diff --git a/block/blk-mq.h b/block/blk-mq.h index 4f4f943c22c3..6a48c4c0d8a2 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h | |||
| @@ -62,6 +62,8 @@ extern void blk_mq_sysfs_unregister(struct request_queue *q); | |||
| 62 | 62 | ||
| 63 | extern void blk_mq_rq_timed_out(struct request *req, bool reserved); | 63 | extern void blk_mq_rq_timed_out(struct request *req, bool reserved); |
| 64 | 64 | ||
| 65 | void blk_mq_release(struct request_queue *q); | ||
| 66 | |||
| 65 | /* | 67 | /* |
| 66 | * Basic implementation of sparser bitmap, allowing the user to spread | 68 | * Basic implementation of sparser bitmap, allowing the user to spread |
| 67 | * the bits over more cachelines. | 69 | * the bits over more cachelines. |
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 935ea2aa0730..faaf36ade7eb 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c | |||
| @@ -517,6 +517,8 @@ static void blk_release_queue(struct kobject *kobj) | |||
| 517 | 517 | ||
| 518 | if (!q->mq_ops) | 518 | if (!q->mq_ops) |
| 519 | blk_free_flush_queue(q->fq); | 519 | blk_free_flush_queue(q->fq); |
| 520 | else | ||
| 521 | blk_mq_release(q); | ||
| 520 | 522 | ||
| 521 | blk_trace_shutdown(q); | 523 | blk_trace_shutdown(q); |
| 522 | 524 | ||
