Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp45505pxk; Tue, 15 Sep 2020 17:19:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrYMUJiO2NWraL8Ne8B7liCP/ZljhGd+Xxi7LqjbUwFPN2zxAJBM+uE9DFYePfsuOe4pFM X-Received: by 2002:aa7:d959:: with SMTP id l25mr24562008eds.383.1600215541554; Tue, 15 Sep 2020 17:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600215541; cv=none; d=google.com; s=arc-20160816; b=SUWDN6ryskdZj/DCD6tjfiv0J+SXxu9FISJBajxy8DWvzBjVV/7GSW+sd08urolLYf JsyxaeArc5ntE+3xbMMpYzQXtNgZ9BkIiUs54TxEgz0qd0dX/8RfPI0E9wjiugPyOjcg J6f+hybuKjdg3HMMbICMGGtc8qUyHMUABgy367JL0CdV9Owunbh+wUZcWTBsFC8cNgKn zsAM/INGiqTvELgoKvfkmrtOVFJA8j5vpu26txcOFFavpcpnJKk30aOwBN2YJaIBcV7o jYab0sHF35+8U6+cavnAWeCiwW033yanFe/CJbZJ5Ob71hD8FTbY2XXTtCIEOsROoatW wang== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x2rwkhF2Bpu80myfW44xwTG9XH5T8jFS8SG5PHDbAVw=; b=euny9JXDlj8zJFsR/oU/pM+QtNp65wM7z+wP1+DhOkF98fM+J3HZWoS4ZXZxmFZjRM mpm4PmZvorXpZd7Vjb8UITbfWY+4aqhVQV0tKpPRWcXrbgI90ucTolkIV8E8XJCyfUEK o8R6I6+uuQCRu5jIafrvnkjY58OnUpQqXgH5HnkX5ldvpRDnxhK0/0mVn5EB4xCUwH/K glvS35gBLJ5Mh6AwFm77yV+ytsGtVmrd5O64YSS/szJm6P2H50Euy7sBsbiILMo4bSiz +UHH6fipG6xBPkoVNfP1QhPebY08q5VnIy897hhpWW0RuQ9zozuErp4PUJR4pb33T1NG KyIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S0WCa8eC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a21si10760894edr.363.2020.09.15.17.18.39; Tue, 15 Sep 2020 17:19:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S0WCa8eC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbgIPASE (ORCPT + 99 others); Tue, 15 Sep 2020 20:18:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:34582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726886AbgIOOWr (ORCPT ); Tue, 15 Sep 2020 10:22:47 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 99EFA22276; Tue, 15 Sep 2020 14:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600179461; bh=O89Fn4tItlJ7HtW9Wnv3TR96ZERayPNj8C8t8ed4kNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S0WCa8eCjKr6Wf+e7Gw0cuKAk974jT5DzAaseDzqxH+KJnQxh9wSRhxQHnAqhp12/ HpIybTMtTcN/1BW2LcYXPigz6NbQqaR6cI2KQ7y5IFsHeQxl4nIDeSAZQVUWh2Hbxo eaCCNbgTFh5tpYuzEQ/ADZDCFoAZMrC4eAP3Y368= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , James Smart , Sagi Grimberg , Sasha Levin Subject: [PATCH 4.19 29/78] nvme-rdma: serialize controller teardown sequences Date: Tue, 15 Sep 2020 16:12:54 +0200 Message-Id: <20200915140635.042369627@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915140633.552502750@linuxfoundation.org> References: <20200915140633.552502750@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sagi Grimberg [ Upstream commit 5110f40241d08334375eb0495f174b1d2c07657e ] In the timeout handler we may need to complete a request because the request that timed out may be an I/O that is a part of a serial sequence of controller teardown or initialization. In order to complete the request, we need to fence any other context that may compete with us and complete the request that is timing out. In this case, we could have a potential double completion in case a hard-irq or a different competing context triggered error recovery and is running inflight request cancellation concurrently with the timeout handler. Protect using a ctrl teardown_lock to serialize contexts that may complete a cancelled request due to error recovery or a reset. Reviewed-by: Christoph Hellwig Reviewed-by: James Smart Signed-off-by: Sagi Grimberg Signed-off-by: Sasha Levin --- drivers/nvme/host/rdma.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index f393a6193252e..7e2cdb17c26d8 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -118,6 +118,7 @@ struct nvme_rdma_ctrl { struct sockaddr_storage src_addr; struct nvme_ctrl ctrl; + struct mutex teardown_lock; bool use_inline_data; }; @@ -880,6 +881,7 @@ out_free_io_queues: static void nvme_rdma_teardown_admin_queue(struct nvme_rdma_ctrl *ctrl, bool remove) { + mutex_lock(&ctrl->teardown_lock); blk_mq_quiesce_queue(ctrl->ctrl.admin_q); nvme_rdma_stop_queue(&ctrl->queues[0]); if (ctrl->ctrl.admin_tagset) @@ -887,11 +889,13 @@ static void nvme_rdma_teardown_admin_queue(struct nvme_rdma_ctrl *ctrl, nvme_cancel_request, &ctrl->ctrl); blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); nvme_rdma_destroy_admin_queue(ctrl, remove); + mutex_unlock(&ctrl->teardown_lock); } static void nvme_rdma_teardown_io_queues(struct nvme_rdma_ctrl *ctrl, bool remove) { + mutex_lock(&ctrl->teardown_lock); if (ctrl->ctrl.queue_count > 1) { nvme_stop_queues(&ctrl->ctrl); nvme_rdma_stop_io_queues(ctrl); @@ -902,6 +906,7 @@ static void nvme_rdma_teardown_io_queues(struct nvme_rdma_ctrl *ctrl, nvme_start_queues(&ctrl->ctrl); nvme_rdma_destroy_io_queues(ctrl, remove); } + mutex_unlock(&ctrl->teardown_lock); } static void nvme_rdma_stop_ctrl(struct nvme_ctrl *nctrl) @@ -1955,6 +1960,7 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, return ERR_PTR(-ENOMEM); ctrl->ctrl.opts = opts; INIT_LIST_HEAD(&ctrl->list); + mutex_init(&ctrl->teardown_lock); if (opts->mask & NVMF_OPT_TRSVCID) port = opts->trsvcid; -- 2.25.1