From patchwork Mon Apr 1 21:20:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10880619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D760184E for ; Mon, 1 Apr 2019 21:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A9D285B3 for ; Mon, 1 Apr 2019 21:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D7BF28785; Mon, 1 Apr 2019 21:20:30 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 D68EC285B3 for ; Mon, 1 Apr 2019 21:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726918AbfDAVU2 (ORCPT ); Mon, 1 Apr 2019 17:20:28 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39445 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbfDAVU1 (ORCPT ); Mon, 1 Apr 2019 17:20:27 -0400 Received: by mail-pl1-f193.google.com with SMTP id b65so5103422plb.6; Mon, 01 Apr 2019 14:20:27 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=yuyj9Ia/9eXCnJDm/1aJGDY3orUh57LWX6Hn+U0TvtE=; b=iqLiYuIB6CGCkx990AlIP9X/tzifZVinOEJdEGXwpO8hpcAaNKxEkjkzgutu/aaM9I ppI/eO0vQKEbflqmpWVtg4iXW9Gus4ucGEpt2QFqq0MLsQWL92QXtil9py5gmXIAPUEP aiV8nuPIKWkLZZV4+QULBpCWwSF9e+VmqhWWT670ptUOFYtKFW5uyJXmcWCdIgMlO/Fm kRSt00rz660Ke7I82pMaQrB+GSGJfFZa82mgXU4jJhFLMKDA8LT7y83DGFxiA3X15A7v dACoVRGXV0uex+6bpIj9Yh7J1zIIS+aTMNOfCsLS6HpzVa/0wSPLRYmw/TtUbQVc8C8g 8suw== X-Gm-Message-State: APjAAAXo+vFuX+IzBijMpPUlZu4tB3Axy3SZpvVaocAJqEnP6K4Alhbj xIY5gS94g/mAEKXPc6cMvQ8= X-Google-Smtp-Source: APXvYqwutshXZIqzVkHzccb/O/tNQRTtmvsj5AcaDLsnWYhiM4/klnsP6Bz0JuZQPhlTTfU+rQSrOA== X-Received: by 2002:a17:902:e01:: with SMTP id 1mr67745974plw.128.1554153627234; Mon, 01 Apr 2019 14:20:27 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id z129sm20178813pfz.103.2019.04.01.14.20.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 14:20:26 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , James Smart , Ming Lei , Jianchao Wang , Dongli Zhang , stable@vger.kernel.org Subject: [PATCH 1/4] block: Move the percpu_ref_exit(&q->q_usage_counter) call into __blk_release_queue() Date: Mon, 1 Apr 2019 14:20:11 -0700 Message-Id: <20190401212014.192753-2-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190401212014.192753-1-bvanassche@acm.org> References: <20190401212014.192753-1-bvanassche@acm.org> MIME-Version: 1.0 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 This patch makes it safe to access the queue usage counter from inside blk_mq_run_hw_queues(). Other than deferring q_usage_counter freeing, this patch does not change any functionality. Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: James Smart Cc: Ming Lei Cc: Jianchao Wang Cc: Dongli Zhang Cc: Signed-off-by: Bart Van Assche --- block/blk-core.c | 2 -- block/blk-sysfs.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 4673ebe42255..fdcf6de2243f 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -377,8 +377,6 @@ void blk_cleanup_queue(struct request_queue *q) if (queue_is_mq(q)) blk_mq_free_queue(q); - percpu_ref_exit(&q->q_usage_counter); - /* @q is and will stay empty, shutdown and put */ blk_put_queue(q); } diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 422327089e0f..b8b3d69cd0a5 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -870,6 +870,7 @@ static void __blk_release_queue(struct work_struct *work) bioset_exit(&q->bio_split); + percpu_ref_exit(&q->q_usage_counter); ida_simple_remove(&blk_queue_ida, q->id); call_rcu(&q->rcu_head, blk_free_queue_rcu); } From patchwork Mon Apr 1 21:20:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10880621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B92F51708 for ; Mon, 1 Apr 2019 21:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2A6B286B3 for ; Mon, 1 Apr 2019 21:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 971E82878E; Mon, 1 Apr 2019 21:20:30 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 31297286B3 for ; Mon, 1 Apr 2019 21:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbfDAVU3 (ORCPT ); Mon, 1 Apr 2019 17:20:29 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35576 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbfDAVU3 (ORCPT ); Mon, 1 Apr 2019 17:20:29 -0400 Received: by mail-pf1-f194.google.com with SMTP id t21so5205442pfe.2; Mon, 01 Apr 2019 14:20:28 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=1r8cG5Bbubh44sas3wFc1Pb54IPJJipwe6rI6YSXQrI=; b=dtLNeB+fX1LrNLZ+CKG7O1QkialU8xMky+mDavHjHw35KdgHgRBjeEFIaz+1shPNl3 BpXXHsqocVH/+3SdRspdOJpH+lkki50zCZg161vaoCvpjQPg4rjro9YrX0d9y9PezZK2 diB54lO4h99QCJxR92WHWPNur/kostQ6zfU6E5iaqvUh7qWGvocoqNz090mmQCncFx4W SUwjuk64ZyCXIBC1gmpDWkiK8rsubP4wPuPqZJ9MPw9R/VQdwVio0NE3MH2vNv0ktbXf qQ6FCYFUhPnkGSYV/ElWOQ/KoP/HDls10bK2uyaDphdS81y7wFcZNB1BlR4Pj3ssbcJx STqQ== X-Gm-Message-State: APjAAAVQPZOzhtoGU5sPQUPn21eIcV32iKOGvyu72SkidKnUmJG9vgKp PpnKzMy1+HjMMqHMmzVS8+g= X-Google-Smtp-Source: APXvYqxM5njdiZ4t1OQT4J6UaarAOGmIH+k56Bxlu0vOGTg6xTRQ8NVeXgyCGphkBShvyBHpYKH+Fg== X-Received: by 2002:a65:5189:: with SMTP id h9mr61930466pgq.304.1554153628363; Mon, 01 Apr 2019 14:20:28 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id z129sm20178813pfz.103.2019.04.01.14.20.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 14:20:27 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , James Smart , Ming Lei , Jianchao Wang , Dongli Zhang , stable@vger.kernel.org Subject: [PATCH 2/4] block: Fix a race between request queue freezing and running queues Date: Mon, 1 Apr 2019 14:20:12 -0700 Message-Id: <20190401212014.192753-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190401212014.192753-1-bvanassche@acm.org> References: <20190401212014.192753-1-bvanassche@acm.org> MIME-Version: 1.0 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 Any request queue data structure may change while a queue is frozen. Hence make sure that blk_mq_run_hw_queues() does not access any hw queue while a request queue is frozen. After blk_cleanup_queue() has marked a queue as dead it is no longer safe to access the hardware queue data structures. This patch avoids that blk_mq_run_hw_queues() crashes when called during or after blk_cleanup_queue() has freed the hardware queues. This patch is a variant of a patch posted by Hannes Reinecke ("[PATCH] block: don't call blk_mq_run_hw_queues() for dead or dying queues "). This patch is similar in nature to commit c246e80d8673 ("block: Avoid that request_fn is invoked on a dead queue"; v3.8). An example of a crash that is fixed by this patch: BUG: unable to handle kernel NULL pointer dereference at (null) IP: [] sbitmap_any_bit_set+0xb/0x30 Call Trace: [] blk_mq_run_hw_queues+0x48/0x90 [] blk_mq_requeue_work+0x10c/0x120 [] process_one_work+0x154/0x410 [] worker_thread+0x116/0x4a0 [] kthread+0xc9/0xe0 [] ret_from_fork+0x55/0x80 Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: James Smart Cc: Ming Lei Cc: Jianchao Wang Cc: Dongli Zhang Cc: Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller") # v4.17. Reported-by: James Smart Signed-off-by: Bart Van Assche --- block/blk-mq.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 3ff3d7b49969..652d0c6d5945 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1499,12 +1499,20 @@ void blk_mq_run_hw_queues(struct request_queue *q, bool async) struct blk_mq_hw_ctx *hctx; int i; + /* + * Do not run any hardware queues if the queue is frozen or if a + * concurrent blk_cleanup_queue() call is removing any data + * structures used by this function. + */ + if (!percpu_ref_tryget(&q->q_usage_counter)) + return; queue_for_each_hw_ctx(q, hctx, i) { if (blk_mq_hctx_stopped(hctx)) continue; blk_mq_run_hw_queue(hctx, async); } + percpu_ref_put(&q->q_usage_counter); } EXPORT_SYMBOL(blk_mq_run_hw_queues); From patchwork Mon Apr 1 21:20:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10880623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEFDD184E for ; Mon, 1 Apr 2019 21:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D636F28768 for ; Mon, 1 Apr 2019 21:20:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2AC528796; Mon, 1 Apr 2019 21:20:31 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 5F2FD287A9 for ; Mon, 1 Apr 2019 21:20:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728046AbfDAVUa (ORCPT ); Mon, 1 Apr 2019 17:20:30 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:32776 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbfDAVUa (ORCPT ); Mon, 1 Apr 2019 17:20:30 -0400 Received: by mail-pf1-f195.google.com with SMTP id i19so5203242pfd.0; Mon, 01 Apr 2019 14:20:29 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=eHDjoWZvxansatEzDR84uL7iy57E5jPUMhqN+zE2r4c=; b=OKDZRaw8+vtcijCKZ3BAtlMaFag6pKk1m2YBhnRrk+h6BRg5FCxr5zBB7zrVh8FF62 zlK0F2zvwcQv71Ctp+r2LvSYKtNCWcNOJPKpniLPOGY6QUMbo/z3VKjyx//CfQkd1bij GMupyL60D6W0BITq1ORlmei4YsBtOLGA1dx8xQY12Bp1zkLgtUNohyt6bMgRoaUg8KfC y4wCw5HpNP42Fr//To8j1jDU4aG9GiJfpr5RIUD2I3vXgqMefOjEY11FFIkNWuL785hI DKNjqKxcxsZZ70jl6pTBUksWDYW/nYfVdvVs8DFJtR3Me1DQomf/sxuexwJVd/f/zNW7 bQug== X-Gm-Message-State: APjAAAU/O4VEj1aPypCrTBILNTlg6F4lpVRag+1oKCZpHwpE787giwRl XxVPOh4WM6KptLY/AwTKxlo= X-Google-Smtp-Source: APXvYqzpn4+nna6jiQ3oQGuynVtRfGM3quowNyUe4OEgkPc8eunj0MygGru4IdzxE859Dg0kayxSyg== X-Received: by 2002:a63:d1f:: with SMTP id c31mr38885887pgl.353.1554153629453; Mon, 01 Apr 2019 14:20:29 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id z129sm20178813pfz.103.2019.04.01.14.20.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 14:20:28 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , James Smart , Ming Lei , Jianchao Wang , Dongli Zhang , stable@vger.kernel.org Subject: [PATCH 3/4] block: Fix a comment in blk_cleanup_queue() Date: Mon, 1 Apr 2019 14:20:13 -0700 Message-Id: <20190401212014.192753-4-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190401212014.192753-1-bvanassche@acm.org> References: <20190401212014.192753-1-bvanassche@acm.org> MIME-Version: 1.0 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 Change a reference to the legacy block layer into a reference to blk-mq. Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: James Smart Cc: Ming Lei Cc: Jianchao Wang Cc: Dongli Zhang Cc: Signed-off-by: Bart Van Assche --- block/blk-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-core.c b/block/blk-core.c index fdcf6de2243f..bfdbdbb8ec65 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -339,7 +339,8 @@ void blk_cleanup_queue(struct request_queue *q) /* * Drain all requests queued before DYING marking. Set DEAD flag to - * prevent that q->request_fn() gets invoked after draining finished. + * prevent that blk_mq_run_hw_queues() accesses the hardware queues + * after draining finished. */ blk_freeze_queue(q); From patchwork Mon Apr 1 21:20:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10880625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1AF6184E for ; Mon, 1 Apr 2019 21:20:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEC152878F for ; Mon, 1 Apr 2019 21:20:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD1B0287A0; Mon, 1 Apr 2019 21:20:32 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 59A0728793 for ; Mon, 1 Apr 2019 21:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728192AbfDAVUb (ORCPT ); Mon, 1 Apr 2019 17:20:31 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44597 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbfDAVUb (ORCPT ); Mon, 1 Apr 2019 17:20:31 -0400 Received: by mail-pf1-f195.google.com with SMTP id y13so5185917pfm.11; Mon, 01 Apr 2019 14:20:31 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=lbtL5HDiGSmdongH2mvoJvZmPRCHYZ1en9PeFqokieA=; b=KEd9LNmZu6DRJvr7hPbSiR2/u2ptUL+WZV/Bo79s2FQFSzM93xbHhwst4C4zv80zJ5 GtjNpAa4bTjF8up91EnkcjgYFX1VmLWEOSasjWXvO+in6WUHGo3RoIi/pmg42YC98BzY Q/jXaibvEvRazw7YVJWlGrnZJwrkrag2dgVZrgQJXJ/6EilysmhRDie0D4CsHOVRuQK1 60D1LGGQV8Dvl4gGw6nYtjkhhgWYJeOZgklVPVvDaFHPaFVRrZS2/QwxEh9c7j/+x7uC PoK+XDMkKx+im9554lROcxmYz7JFtIZrRXCX6ajTuwrKp47aEt15rq52pDuCV+EeVBNE mbZA== X-Gm-Message-State: APjAAAXaljUBru9bu0MZm3/298/+9yzRjBNLskrLdbXWnF6Yn8My5Prj W6vOI7O1opTOQAsn+DGD1EI= X-Google-Smtp-Source: APXvYqzH/E/LcqsQUY6rA3LXFaVZDBZeRC1BGguDHjD5AB6URA4MsRZhmpni8HKKJEBf5ECFbf1BJg== X-Received: by 2002:a63:170d:: with SMTP id x13mr59836321pgl.169.1554153630633; Mon, 01 Apr 2019 14:20:30 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id z129sm20178813pfz.103.2019.04.01.14.20.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 14:20:29 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , James Smart , Ming Lei , Jianchao Wang , Dongli Zhang , stable@vger.kernel.org Subject: [PATCH 4/4] block: Make blk_cleanup_queue() faster Date: Mon, 1 Apr 2019 14:20:14 -0700 Message-Id: <20190401212014.192753-5-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190401212014.192753-1-bvanassche@acm.org> References: <20190401212014.192753-1-bvanassche@acm.org> MIME-Version: 1.0 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 Since blk_cleanup_queue() waits until q->q_usage_counter drops to zero before setting the "dead" flag, it is guaranteed that all requests that were in progress when blk_cleanup_queue() was called have finished before the "dead" flag is set. This means it is not possible that any .queue_rq() call is ongoing while the "dead" flag is set. Hence remove the code that waits for ongoing .queue_rq() calls to finish after the "dead" flag has been set. See also commit c2856ae2f315 ("blk-mq: quiesce queue before freeing queue") # v4.16. Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: James Smart Cc: Ming Lei Cc: Jianchao Wang Cc: Dongli Zhang Cc: Signed-off-by: Bart Van Assche --- block/blk-core.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index bfdbdbb8ec65..2921af6f8d33 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -348,18 +348,6 @@ void blk_cleanup_queue(struct request_queue *q) blk_queue_flag_set(QUEUE_FLAG_DEAD, q); - /* - * make sure all in-progress dispatch are completed because - * blk_freeze_queue() can only complete all requests, and - * dispatch may still be in-progress since we dispatch requests - * from more than one contexts. - * - * We rely on driver to deal with the race in case that queue - * initialization isn't done. - */ - if (queue_is_mq(q) && blk_queue_init_done(q)) - blk_mq_quiesce_queue(q); - /* for synchronous bio-based driver finish in-flight integrity i/o */ blk_flush_integrity();