Received: by 10.223.176.46 with SMTP id f43csp2606032wra; Sun, 21 Jan 2018 23:55:43 -0800 (PST) X-Google-Smtp-Source: AH8x224wUYOlifXF0WInWkNdqITHErJZeVPw/gsVR9kSxI+nUzCqwUCcwqUkdwXuITrQmhmy143r X-Received: by 2002:a17:902:242:: with SMTP id 60-v6mr3068531plc.376.1516607743458; Sun, 21 Jan 2018 23:55:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516607743; cv=none; d=google.com; s=arc-20160816; b=d3x9uJv6Kk94JLOdpDijIAQ1HnpsRQWPIHfMN6yZkqmPbPgyCPEwsgJGM4W926GZcz vZmmMf/gLZs/98tOs64+NulGVmXfMsAfxLXx4G31OER/coDzmL6jmeAMM86/cX6Gt0bn AONyinIrjQ2DH0dLl6uHlNkUBn3uA4X8JhZW62ir7/uWBEdJcLu6U7GQ0rjHX100td/3 EI0uiQsiq9JXYRbAfwJ2je8s74gC0sZ+X/QyA3xgLqNB1fPsFynHfBbTnzoslaY581Uk 2tZS+eUQLfIZ4RcClMLhwyE1+EAMLgv4VhRELOaZlahbz2tnG5xwa+wUR7ckHcqn01O1 1t/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=jySszO2ghohYT3SyUKKSZEawK+YrRyh7Ia92GPLMaTg=; b=nwLCBxV7lFq0uei9CyH2o4EDgOIZMW94BF3p9w5AELQhhorEkrzq3HxYA6pcHPKNsN YsVousHAvSMwPCDYNhGVuOvPUHZEAeHW1Hc5bRHCUb1UGAHJ4bMI7zIB1DHVGo/PCLBC hS+fAtExUM9ujtHu9IPuSBS7L3p7so/cCfE4K0qOq4duUJXGBWuKUxGZyvuwTBeIstkm Tc0tF4A5ptkITP//y60/2KvxeDTAnHLwmeQ/q6soS7MkQWqg/wEoj0wHTSC6wZn8J8vH oQd84PN8vs+6ba8zQRfE1VOuQbhHuTjvZy8OpWJ7l6nJBw5ovmsS99tpuUCJjV8cgCCq 8SCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=WzAnqAQb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si13266935pgr.631.2018.01.21.23.55.29; Sun, 21 Jan 2018 23:55:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=WzAnqAQb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751183AbeAVHyZ (ORCPT + 99 others); Mon, 22 Jan 2018 02:54:25 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:48536 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750942AbeAVHyX (ORCPT ); Mon, 22 Jan 2018 02:54:23 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0M7qw0M101671; Mon, 22 Jan 2018 07:53:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=jySszO2ghohYT3SyUKKSZEawK+YrRyh7Ia92GPLMaTg=; b=WzAnqAQbM1nDzLhl704o/PX8jUeiyBgzyxaVilve3aB4pJbENReZ3KNIPEbx5lICZfrJ pobLldtlF7AltWoJMnBfxUtI2POiKtnIFueKKcDYScffokJfOYfbZ0VeHtLQCj91Q4FV bahmxg+DCdg8NwuMy/X5pr8B3/jVLlNgvJlXrUsEOseBRvEc8ctpf4Fb5D/mYvG5cRX/ xsdw4+QAX5Nws4H6rC9rR2LUwtqFG8UfiVFJFqSxCs1LtQ2/BnJXcQ6Ko9omz0Fasc2r 1ZJz46F4mmG+88pysoH+KGHRiRaVU6BqRL3UTiDdot1YYTXIEc1TitbotFEO/F1nkIYs vQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2fnb62r4mv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jan 2018 07:53:32 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0M7rVQ8009418 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Jan 2018 07:53:31 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0M7rQEW031582; Mon, 22 Jan 2018 07:53:26 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.70.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 21 Jan 2018 23:53:25 -0800 From: Jianchao Wang To: keith.busch@intel.com, axboe@fb.com, hch@lst.de, sagi@grimberg.me, maxg@mellanox.com, james.smart@broadcom.com Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvme-pci: ensure nvme_timeout complete before initializing procedure Date: Mon, 22 Jan 2018 15:53:05 +0800 Message-Id: <1516607585-1525-1-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8781 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801220116 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There could be a nvme_timeout running with nvme_dev_disable in parallel. The requests held by timeout path cannot be canceled by nvme_dev_disable. Consequently, the nvme_timeout maybe still running after nvme_dev_disable completes. Then there could be a race between nvme_dev_disable in nvme_timeout and initializing procedure in nvme_reset_work. nvme_timeout nvme_reset_work if (RESETTING) nvme_dev_disable nvme_dev_disable initializing To fix it, ensure all the q->timeout_work complete before the initializing procedure in nvme_reset_work. At the moment, all the outstanding requests should have been handled by nvme_dev_disable or nvme_timeout. So introduce nvme_sync_queues which invokes blk_sync_queue. In addition to this, add blk_mq_kick_requeue_list into nvme_start_queues and nvme_kill_queues to avoid IO hang in requeue_list, because blk_sync_queue will cancel the requeue_work. Link: https://lkml.org/lkml/2018/1/19/68 Suggested-by: Keith Busch Signed-off-by: Keith Busch Signed-off-by: Jianchao Wang --- drivers/nvme/host/core.c | 20 ++++++++++++++++++-- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/pci.c | 9 ++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 23b3e53..c2ea8adb 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3443,7 +3443,11 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl) revalidate_disk(ns->disk); blk_set_queue_dying(ns->queue); - /* Forcibly unquiesce queues to avoid blocking dispatch */ + /* + * Forcibly kick requeue and unquiesce queues to avoid blocking + * dispatch + */ + blk_mq_kick_requeue_list(ns->queue); blk_mq_unquiesce_queue(ns->queue); } mutex_unlock(&ctrl->namespaces_mutex); @@ -3513,12 +3517,24 @@ void nvme_start_queues(struct nvme_ctrl *ctrl) struct nvme_ns *ns; mutex_lock(&ctrl->namespaces_mutex); - list_for_each_entry(ns, &ctrl->namespaces, list) + list_for_each_entry(ns, &ctrl->namespaces, list) { + blk_mq_kick_requeue_list(ns->queue); blk_mq_unquiesce_queue(ns->queue); + } mutex_unlock(&ctrl->namespaces_mutex); } EXPORT_SYMBOL_GPL(nvme_start_queues); +void nvme_sync_queues(struct nvme_ctrl *ctrl) +{ + struct nvme_ns *ns; + + mutex_lock(&ctrl->namespaces_mutex); + list_for_each_entry(ns, &ctrl->namespaces, list) + blk_sync_queue(ns->queue); + mutex_unlock(&ctrl->namespaces_mutex); +} +EXPORT_SYMBOL_GPL(nvme_sync_queues); int nvme_reinit_tagset(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set) { if (!ctrl->ops->reinit_request) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index a44eeca..01faea6 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -370,6 +370,7 @@ int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len, void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, union nvme_result *res); +void nvme_sync_queues(struct nvme_ctrl *ctrl); void nvme_stop_queues(struct nvme_ctrl *ctrl); void nvme_start_queues(struct nvme_ctrl *ctrl); void nvme_kill_queues(struct nvme_ctrl *ctrl); diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index f5207bc..9ba7e55 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2318,8 +2318,15 @@ static void nvme_reset_work(struct work_struct *work) * If we're called to reset a live controller first shut it down before * moving on. */ - if (dev->ctrl.ctrl_config & NVME_CC_ENABLE) + if (dev->ctrl.ctrl_config & NVME_CC_ENABLE) { nvme_dev_disable(dev, false); + /* nvme_timeout could run in parallel, consequently, + * nvme_dev_disable invoked by nvme_timeout could race with + * following initializing procedure. So add nvme_sync_queues + * here to ensure nvme_timeout to be completed. + */ + nvme_sync_queues(&dev->ctrl); + } /* * Introduce RECONNECTING state from nvme-fc/rdma transports to mark the -- 2.7.4