From patchwork Sun Jun 18 15:22:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 9794907 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 EC542601C8 for ; Sun, 18 Jun 2017 15:22:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF2AD283AF for ; Sun, 18 Jun 2017 15:22:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4097283C0; Sun, 18 Jun 2017 15:22:51 +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=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, URIBL_BLACK 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 7CA23283AF for ; Sun, 18 Jun 2017 15:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753285AbdFRPWv (ORCPT ); Sun, 18 Jun 2017 11:22:51 -0400 Received: from merlin.infradead.org ([205.233.59.134]:52282 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753255AbdFRPWu (ORCPT ); Sun, 18 Jun 2017 11:22:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=b7egBPQevPevPRq65/xYvHyjQvBuqBOHFQIlaBy+3Q8=; b=yMHaHa9bBJottNOicGCQ/cRGb F9PyXp9v69Q/cC/1cCCaBn/bs6J5XI+jXnhn4x/UU8NXmgLOuQRNcjlhfmMG6AW4yMwG7XRtC276h AY4lE21ywQTZFlJaryTklGLBkDEvex2Bj/vxvZolU4MMziLTNsQX/n8DG+VpLG5VBEy9OplqgMcsC apXcMQNg2qwI2ogXUcB1jutf4EofmzcK4w0BCUspwBDPqyNCtNgtJa31Cyav6mYFN4Ms05nveNcO6 B/H9oBmm7fOYxnf94oy5zQaYSctS1c0kb0+Dy8nOWF5+7pMZ5j2e+Cu2dOctl6ttbqScLHPkXs03y d1AQji87Q==; Received: from bzq-82-81-101-184.red.bezeqint.net ([82.81.101.184] helo=bombadil.infradead.org) by merlin.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1dMc2K-0006WN-QM; Sun, 18 Jun 2017 15:22:49 +0000 From: Sagi Grimberg To: linux-nvme@lists.infradead.org Cc: Christoph Hellwig , Keith Busch , linux-block@vger.kernel.org Subject: [PATCH rfc 30/30] nvme: Add queue freeze/unfreeze handling on controller resets Date: Sun, 18 Jun 2017 18:22:04 +0300 Message-Id: <1497799324-19598-31-git-send-email-sagi@grimberg.me> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497799324-19598-1-git-send-email-sagi@grimberg.me> References: <1497799324-19598-1-git-send-email-sagi@grimberg.me> 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 Just copy what we have in nvme-pci. It's a generic flow anyway. Signed-off-by: Sagi Grimberg --- drivers/nvme/host/core.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index f4800b8e47a0..959b6c39f22c 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2901,15 +2901,40 @@ EXPORT_SYMBOL_GPL(nvme_configure_admin_queue); static void nvme_teardown_ctrl(struct nvme_ctrl *ctrl, bool shutdown) { + bool dead = true; + nvme_stop_keep_alive(ctrl); cancel_work_sync(&ctrl->err_work); cancel_delayed_work_sync(&ctrl->reconnect_work); if (ctrl->max_queues > 1) { + u32 csts; + + if (!ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) { + nvme_start_freeze(ctrl); + dead = !!((csts & NVME_CSTS_CFS) || + !(csts & NVME_CSTS_RDY)); + } + + /* + * Give the controller a chance to complete all entered requests + * if doing a safe shutdown. + */ + if (!dead && shutdown) + nvme_wait_freeze_timeout(ctrl, NVME_IO_TIMEOUT); + nvme_stop_queues(ctrl); blk_mq_tagset_busy_iter(ctrl->tagset, nvme_cancel_request, ctrl); nvme_destroy_io_queues(ctrl, shutdown); + + /* + * The driver will not be starting up queues again if shutting + * down so must flush all entered requests to their failed + * completion to avoid deadlocking blk-mq hot-cpu notifier. + */ + if (shutdown) + nvme_start_queues(ctrl); } if (shutdown) @@ -2991,6 +3016,8 @@ static void nvme_reset_ctrl_work(struct work_struct *work) if (ctrl->queue_count > 1) { nvme_start_queues(ctrl); + nvme_wait_freeze(ctrl); + nvme_unfreeze(ctrl); nvme_queue_scan(ctrl); nvme_queue_async_events(ctrl); }