From patchwork Wed Feb 22 10:13:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9586523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BDC0E6020B for ; Wed, 22 Feb 2017 10:14:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B220E288E0 for ; Wed, 22 Feb 2017 10:14:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2861288EA; Wed, 22 Feb 2017 10:14:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D934288FD for ; Wed, 22 Feb 2017 10:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932140AbdBVKOc (ORCPT ); Wed, 22 Feb 2017 05:14:32 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34767 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932080AbdBVKOW (ORCPT ); Wed, 22 Feb 2017 05:14:22 -0500 Received: by mail-pg0-f65.google.com with SMTP id s67so1688703pgb.1; Wed, 22 Feb 2017 02:14:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NfcpaJYRD2iiMa9YiW7viXqdcrZDUpb5ht32yFbMqpI=; b=lR99So2FjgLmnTcBJH3Q0gvqEMFC5SP9eXva9tYeLOCafjU5m0nipJXdxjU+T+MtcZ hhPVgDLx4kmgLnKmWn9AtTEkRsNy2BhzmAtucB6RjRg9iUKB1p1duCwPq0YtBqoDJG4l xER6449T1wz6I5SF/OYeyJFgRpni/DPgAebM2PwaNf6cESnpV5rJAPfcb4BE+j1U1tN+ IiKRJWK72IIna5NoFlZFiBIYJMDALtidP7duSnh43DnxWbCvtMLxYRTJPVI98v4GW1IO bh3YrZ0Yzs3WeJR/bn8+WUvV/7U2qN76iu/9P3n+x8+MjRS/hKorHfd2Ef/DiXCe6h2X Ngsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NfcpaJYRD2iiMa9YiW7viXqdcrZDUpb5ht32yFbMqpI=; b=tGKdy3IrjEduCCWAB9BJsvLoIJRGgn37DEJJ0HjTlQ4zLuCprxCV6KYJE0u2R+JENB ypoH0PlLwfjJWvambo9WoQeEpdvFZNPe4SPD35fuu5CWq6tPvtqiOZfA+1BdzZwGrfRa wF8tv98XNBinPiwVY3O0bFQklTiA84QWYztynEAYxeykKP5hVszxge5e+Aloty7qFLIe rEPpu0ss4s6kSmQ5n2PuHaXUIvsTsu7YKaXYIlKQcBU+8rtiYjWOtXDJRG1qEJ+kjgO2 Qlo7y5j5zsrLjuuAjPkwQBLMPteRFY6XosqZukk11eV4VNREN4kX/01ctwaSAVKskeV7 zv4g== X-Gm-Message-State: AMke39mkxVpFTHhrtX6JjdzPhRU0b82WhWd8qXYL/lkli/cYJhbtzAJw5u/W2nAwDSHQJQ== X-Received: by 10.84.130.65 with SMTP id 59mr47109465plc.170.1487758461513; Wed, 22 Feb 2017 02:14:21 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id 10sm2602773pfs.113.2017.02.22.02.14.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Feb 2017 02:14:20 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig , Omar Sandoval Cc: Ming Lei Subject: [PATCH 1/4] blk-mq: initialize mq kobjects in blk_mq_init_allocated_queue() Date: Wed, 22 Feb 2017 18:13:59 +0800 Message-Id: <1487758442-5855-2-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487758442-5855-1-git-send-email-tom.leiming@gmail.com> References: <1487758442-5855-1-git-send-email-tom.leiming@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both q->mq_kobj and sw queues' kobjects should have been initialized once, instead of doing that each add_disk context. Also this patch removes clearing of ctx in blk_mq_init_cpu_queues() because percpu allocator fills zero to allocated variable. This patch fixes one issue[1] reported from Omar. [1] kernel wearning when doing unbind/bind on one scsi-mq device [ 19.347924] kobject (ffff8800791ea0b8): tried to init an initialized object, something is seriously wrong. [ 19.349781] CPU: 1 PID: 84 Comm: kworker/u8:1 Not tainted 4.10.0-rc7-00210-g53f39eeaa263 #34 [ 19.350686] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.1-20161122_114906-anatol 04/01/2014 [ 19.350920] Workqueue: events_unbound async_run_entry_fn [ 19.350920] Call Trace: [ 19.350920] dump_stack+0x63/0x83 [ 19.350920] kobject_init+0x77/0x90 [ 19.350920] blk_mq_register_dev+0x40/0x130 [ 19.350920] blk_register_queue+0xb6/0x190 [ 19.350920] device_add_disk+0x1ec/0x4b0 [ 19.350920] sd_probe_async+0x10d/0x1c0 [sd_mod] [ 19.350920] async_run_entry_fn+0x48/0x150 [ 19.350920] process_one_work+0x1d0/0x480 [ 19.350920] worker_thread+0x48/0x4e0 [ 19.350920] kthread+0x101/0x140 [ 19.350920] ? process_one_work+0x480/0x480 [ 19.350920] ? kthread_create_on_node+0x60/0x60 [ 19.350920] ret_from_fork+0x2c/0x40 Cc: Omar Sandoval Signed-off-by: Ming Lei --- block/blk-mq-sysfs.c | 4 +--- block/blk-mq.c | 4 +++- block/blk-mq.h | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 295e69670c39..124305407c80 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -277,7 +277,7 @@ void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx) kobject_init(&hctx->kobj, &blk_mq_hw_ktype); } -static void blk_mq_sysfs_init(struct request_queue *q) +void blk_mq_sysfs_init(struct request_queue *q) { struct blk_mq_ctx *ctx; int cpu; @@ -297,8 +297,6 @@ int blk_mq_register_dev(struct device *dev, struct request_queue *q) blk_mq_disable_hotplug(); - blk_mq_sysfs_init(q); - ret = kobject_add(&q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq"); if (ret < 0) goto out; diff --git a/block/blk-mq.c b/block/blk-mq.c index b29e7dc7b309..ade1d7cde37e 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1941,7 +1941,6 @@ static void blk_mq_init_cpu_queues(struct request_queue *q, struct blk_mq_ctx *__ctx = per_cpu_ptr(q->queue_ctx, i); struct blk_mq_hw_ctx *hctx; - memset(__ctx, 0, sizeof(*__ctx)); __ctx->cpu = i; spin_lock_init(&__ctx->lock); INIT_LIST_HEAD(&__ctx->rq_list); @@ -2248,6 +2247,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, if (!q->queue_ctx) goto err_exit; + /* init q->mq_kobj and sw queues' kobjects */ + blk_mq_sysfs_init(q); + q->queue_hw_ctx = kzalloc_node(nr_cpu_ids * sizeof(*(q->queue_hw_ctx)), GFP_KERNEL, set->numa_node); if (!q->queue_hw_ctx) diff --git a/block/blk-mq.h b/block/blk-mq.h index 24b2256186f3..445343425f6d 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -77,6 +77,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q, /* * sysfs helpers */ +extern void blk_mq_sysfs_init(struct request_queue *q); extern int blk_mq_sysfs_register(struct request_queue *q); extern void blk_mq_sysfs_unregister(struct request_queue *q); extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx);