From patchwork Tue Jun 20 01:33:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13285118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DC67EB64DA for ; Tue, 20 Jun 2023 01:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229454AbjFTBez (ORCPT ); Mon, 19 Jun 2023 21:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229713AbjFTBey (ORCPT ); Mon, 19 Jun 2023 21:34:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED9D21A8 for ; Mon, 19 Jun 2023 18:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687224847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4PYtlICsVrzWVWjpQCthAqGPDOKppaljQKPmtAELYlk=; b=MJHnCpBBB/6LCKMIlg9NKcMqFUFJ4j8KuP6dx3QGkH7sMNNi9tUWKSpEo1GhwDYxcXzehY znFHA+PhDDzmwFHm2zIpk76g1k85Ut05azeCtO28AHXcrAfLmliGruZctj0jOcLvq9kOwJ 8ypdNKpHYuGY5o+CPsgIDf59bDKvCCM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-306-CBByPoeZMSeRTm0lcylh7w-1; Mon, 19 Jun 2023 21:34:03 -0400 X-MC-Unique: CBByPoeZMSeRTm0lcylh7w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6ADC48002BF; Tue, 20 Jun 2023 01:34:03 +0000 (UTC) Received: from localhost (ovpn-8-18.pek2.redhat.com [10.72.8.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D581F112132C; Tue, 20 Jun 2023 01:34:00 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org Cc: Yi Zhang , linux-block@vger.kernel.org, Chunguang Xu , Ming Lei Subject: [PATCH V2 1/4] blk-mq: add API of blk_mq_unfreeze_queue_force Date: Tue, 20 Jun 2023 09:33:46 +0800 Message-Id: <20230620013349.906601-2-ming.lei@redhat.com> In-Reply-To: <20230620013349.906601-1-ming.lei@redhat.com> References: <20230620013349.906601-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org NVMe calls freeze/unfreeze in different contexts, and controller removal may break in-progress error recovery, then leave queues in frozen state. So cause IO hang in del_gendisk() because pending writeback IOs are still waited in bio_queue_enter(). Prepare for fixing this issue by calling the added blk_mq_unfreeze_queue_force when removing device. Signed-off-by: Ming Lei --- block/blk-mq.c | 28 +++++++++++++++++++++++++--- block/blk.h | 3 ++- block/genhd.c | 2 +- include/linux/blk-mq.h | 1 + 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 16c524e37123..4c02c28b4835 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -185,26 +185,48 @@ void blk_mq_freeze_queue(struct request_queue *q) } EXPORT_SYMBOL_GPL(blk_mq_freeze_queue); -void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic) +void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic, + bool force) { mutex_lock(&q->mq_freeze_lock); if (force_atomic) q->q_usage_counter.data->force_atomic = true; - q->mq_freeze_depth--; + if (force) { + if (!q->mq_freeze_depth) + goto unlock; + q->mq_freeze_depth = 0; + } else + q->mq_freeze_depth--; WARN_ON_ONCE(q->mq_freeze_depth < 0); if (!q->mq_freeze_depth) { percpu_ref_resurrect(&q->q_usage_counter); wake_up_all(&q->mq_freeze_wq); } +unlock: mutex_unlock(&q->mq_freeze_lock); } void blk_mq_unfreeze_queue(struct request_queue *q) { - __blk_mq_unfreeze_queue(q, false); + __blk_mq_unfreeze_queue(q, false, false); } EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue); +/* + * Force to unfreeze queue + * + * Be careful: this API should only be used for avoiding IO hang in + * bio_queue_enter() when going to remove disk which needs to drain pending + * writeback IO. + * + * Please don't use it for other cases. + */ +void blk_mq_unfreeze_queue_force(struct request_queue *q) +{ + __blk_mq_unfreeze_queue(q, false, true); +} +EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue_force); + /* * FIXME: replace the scsi_internal_device_*block_nowait() calls in the * mpt3sas driver such that this function can be removed. diff --git a/block/blk.h b/block/blk.h index 608c5dcc516b..6ecabd844e13 100644 --- a/block/blk.h +++ b/block/blk.h @@ -33,7 +33,8 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size, void blk_free_flush_queue(struct blk_flush_queue *q); void blk_freeze_queue(struct request_queue *q); -void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic); +void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic, bool + force); void blk_queue_start_drain(struct request_queue *q); int __bio_queue_enter(struct request_queue *q, struct bio *bio); void submit_bio_noacct_nocheck(struct bio *bio); diff --git a/block/genhd.c b/block/genhd.c index f71f82991434..184aa968b453 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -708,7 +708,7 @@ void del_gendisk(struct gendisk *disk) */ if (!test_bit(GD_OWNS_QUEUE, &disk->state)) { blk_queue_flag_clear(QUEUE_FLAG_INIT_DONE, q); - __blk_mq_unfreeze_queue(q, true); + __blk_mq_unfreeze_queue(q, true, false); } else { if (queue_is_mq(q)) blk_mq_exit_queue(q); diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index f401067ac03a..fa265e85d753 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -890,6 +890,7 @@ void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset, void blk_mq_tagset_wait_completed_request(struct blk_mq_tag_set *tagset); void blk_mq_freeze_queue(struct request_queue *q); void blk_mq_unfreeze_queue(struct request_queue *q); +void blk_mq_unfreeze_queue_force(struct request_queue *q); void blk_freeze_queue_start(struct request_queue *q); void blk_mq_freeze_queue_wait(struct request_queue *q); int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, From patchwork Tue Jun 20 01:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13285119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DF5BEB64DA for ; Tue, 20 Jun 2023 01:35:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjFTBfK (ORCPT ); Mon, 19 Jun 2023 21:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbjFTBfJ (ORCPT ); Mon, 19 Jun 2023 21:35:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03DB8E55 for ; Mon, 19 Jun 2023 18:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687224869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uDCU23Tg71ixu26B1Q5DI34+DtwzuYkE4QTPUCZ8gbM=; b=ZXKxHyRs7haeAx9tv1kKW1X9WtJK1FyAiA3vnN/c8EXLcf4dSntSXxdxc7CFqqVpzuNi38 vYRxlJb3MAW/anr6zUobWeADe7aPAcvGQI2B19ny7GY9911452RfQcDzY3pVHSdpm7M4hc Kx5crqDMWoyNA1iipwq1grC9tML3C5M= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-297-sPBOnxV0Mv6z7FTqZz490Q-1; Mon, 19 Jun 2023 21:34:26 -0400 X-MC-Unique: sPBOnxV0Mv6z7FTqZz490Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 156CC1C08DB8; Tue, 20 Jun 2023 01:34:26 +0000 (UTC) Received: from localhost (ovpn-8-18.pek2.redhat.com [10.72.8.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A402112132C; Tue, 20 Jun 2023 01:34:06 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org Cc: Yi Zhang , linux-block@vger.kernel.org, Chunguang Xu , Ming Lei Subject: [PATCH V2 2/4] nvme: add nvme_unfreeze_force() Date: Tue, 20 Jun 2023 09:33:47 +0800 Message-Id: <20230620013349.906601-3-ming.lei@redhat.com> In-Reply-To: <20230620013349.906601-1-ming.lei@redhat.com> References: <20230620013349.906601-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add nvme_unfreeze_force() for fixing IO hang during removing namespaces from error recovery. Signed-off-by: Ming Lei --- drivers/nvme/host/core.c | 21 ++++++++++++++++++--- drivers/nvme/host/nvme.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 76e8f8b4098e..6b3f12368196 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4579,17 +4579,32 @@ void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl) } EXPORT_SYMBOL_GPL(nvme_mark_namespaces_dead); -void nvme_unfreeze(struct nvme_ctrl *ctrl) +static void __nvme_unfreeze(struct nvme_ctrl *ctrl, bool force) { struct nvme_ns *ns; down_read(&ctrl->namespaces_rwsem); - list_for_each_entry(ns, &ctrl->namespaces, list) - blk_mq_unfreeze_queue(ns->queue); + list_for_each_entry(ns, &ctrl->namespaces, list) { + if (force) + blk_mq_unfreeze_queue_force(ns->queue); + else + blk_mq_unfreeze_queue(ns->queue); + } up_read(&ctrl->namespaces_rwsem); } + +void nvme_unfreeze(struct nvme_ctrl *ctrl) +{ + __nvme_unfreeze(ctrl, false); +} EXPORT_SYMBOL_GPL(nvme_unfreeze); +void nvme_unfreeze_force(struct nvme_ctrl *ctrl) +{ + __nvme_unfreeze(ctrl, true); +} +EXPORT_SYMBOL_GPL(nvme_unfreeze_force); + int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) { struct nvme_ns *ns; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 78308f15e090..b583bab985c3 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -765,6 +765,7 @@ void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl); void nvme_sync_queues(struct nvme_ctrl *ctrl); void nvme_sync_io_queues(struct nvme_ctrl *ctrl); void nvme_unfreeze(struct nvme_ctrl *ctrl); +void nvme_unfreeze_force(struct nvme_ctrl *ctrl); void nvme_wait_freeze(struct nvme_ctrl *ctrl); int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout); void nvme_start_freeze(struct nvme_ctrl *ctrl); From patchwork Tue Jun 20 01:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13285121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16724EB64DB for ; Tue, 20 Jun 2023 01:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbjFTBfX (ORCPT ); Mon, 19 Jun 2023 21:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjFTBfW (ORCPT ); Mon, 19 Jun 2023 21:35:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C40F1B0 for ; Mon, 19 Jun 2023 18:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687224873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ikczhd6nnU0AFQRVGRfBcA4iWBBki9GNxTX/jhJO73E=; b=AWWTC9B7JfRYxNSAYVaAkK9ist8YBrqSXMu8UUAALaAFL+17zlXsWY05G9xsj4Ay//o3Tl w8tS6YgpNbIjTr6w0oTMao/SU81ZpUwlkuYmr66f0RYggu6m9bZjgjzO+H+Bm/awr66Ofv HS5f7E9dE7kOnuRAy2ONeE1APMzxYU0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-241-B72X3qVrOi-g8Skv5OvAiQ-1; Mon, 19 Jun 2023 21:34:30 -0400 X-MC-Unique: B72X3qVrOi-g8Skv5OvAiQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E56CE1C08DA3; Tue, 20 Jun 2023 01:34:29 +0000 (UTC) Received: from localhost (ovpn-8-18.pek2.redhat.com [10.72.8.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 219DB492C1B; Tue, 20 Jun 2023 01:34:28 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org Cc: Yi Zhang , linux-block@vger.kernel.org, Chunguang Xu , Ming Lei Subject: [PATCH V2 3/4] nvme: unfreeze queues before removing namespaces Date: Tue, 20 Jun 2023 09:33:48 +0800 Message-Id: <20230620013349.906601-4-ming.lei@redhat.com> In-Reply-To: <20230620013349.906601-1-ming.lei@redhat.com> References: <20230620013349.906601-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org If removal is from breaking error recovery, queues may be frozen, and there may be pending IOs in bio_queue_enter(), and the following del_gendisk() may wait for these IOs, especially from writeback. Similar IO hang exists in flushing scan work too if there are pending IO in scan work context. Fix the kind of issue by unfreezing queues before removing namespace, so that all pending IOs can be handled. Reported-by: Chunguang Xu https://lore.kernel.org/linux-nvme/cover.1685350577.git.chunguang.xu@shopee.com/ Reported-by: Yi Zhang Signed-off-by: Ming Lei --- drivers/nvme/host/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 6b3f12368196..7d8ff58660ee 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4002,6 +4002,9 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) */ nvme_mpath_clear_ctrl_paths(ctrl); + /* unfreeze queues which may be frozen from error recovery */ + nvme_unfreeze_force(ctrl); + /* prevent racing with ns scanning */ flush_work(&ctrl->scan_work); From patchwork Tue Jun 20 01:33:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13285120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D22FEB64D9 for ; Tue, 20 Jun 2023 01:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbjFTBfW (ORCPT ); Mon, 19 Jun 2023 21:35:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbjFTBfW (ORCPT ); Mon, 19 Jun 2023 21:35:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7AF61AC for ; Mon, 19 Jun 2023 18:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687224877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8nn7UL2W4aoSkEptI3kxMwdGhVnchUthDYAf2sSLtDo=; b=LbzsmJZlP67SIk0Dd+xczb3Ds86PJ6xrCFOEhsnb1XggcktA5bZW3spWYpN+1/VdKRIG97 An5PbGVrp9F+lVpncOX8lDx1ARJC+x/f5VyyIqXvm/0dbRj/o8WjQr3B/xONsx4MKnKlaT T0J/sbqlGJe8Dh/Ll579/paCjrrz3PM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-342-jWmzT-B2Ni23TCAMt4rAxg-1; Mon, 19 Jun 2023 21:34:33 -0400 X-MC-Unique: jWmzT-B2Ni23TCAMt4rAxg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1EF78811E78; Tue, 20 Jun 2023 01:34:33 +0000 (UTC) Received: from localhost (ovpn-8-18.pek2.redhat.com [10.72.8.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4201940C20F5; Tue, 20 Jun 2023 01:34:31 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org Cc: Yi Zhang , linux-block@vger.kernel.org, Chunguang Xu , Ming Lei Subject: [PATCH V2 4/4] nvme: unquiesce io queues when removing namespaces Date: Tue, 20 Jun 2023 09:33:49 +0800 Message-Id: <20230620013349.906601-5-ming.lei@redhat.com> In-Reply-To: <20230620013349.906601-1-ming.lei@redhat.com> References: <20230620013349.906601-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Error recovery can be interrupted by controller removal, then the controller is left as quiesced, and IO hang can be caused. Fix the issue by unquiescing controller unconditionally when removing namespaces. Reported-by: Chunguang Xu Closes: https://lore.kernel.org/linux-nvme/cover.1685350577.git.chunguang.xu@shopee.com/ Signed-off-by: Ming Lei --- drivers/nvme/host/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 7d8ff58660ee..de910badcdfc 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4005,6 +4005,12 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) /* unfreeze queues which may be frozen from error recovery */ nvme_unfreeze_force(ctrl); + /* + * Unquiesce io queues so any pending IO won't hang, especially + * those submitted from scan work + */ + nvme_unquiesce_io_queues(ctrl); + /* prevent racing with ns scanning */ flush_work(&ctrl->scan_work); @@ -4014,10 +4020,8 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) * removing the namespaces' disks; fail all the queues now to avoid * potentially having to clean up the failed sync later. */ - if (ctrl->state == NVME_CTRL_DEAD) { + if (ctrl->state == NVME_CTRL_DEAD) nvme_mark_namespaces_dead(ctrl); - nvme_unquiesce_io_queues(ctrl); - } /* this is a no-op when called from the controller reset handler */ nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO);