Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3870233pxb; Tue, 17 Nov 2020 05:51:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQpYGLiaeO2e59lKT8HOuCcUaPk8gIW+yQULhgqET+GhHv3bQGWEqvp7XZQPD6K83KxGEf X-Received: by 2002:a50:875d:: with SMTP id 29mr1719495edv.172.1605621094232; Tue, 17 Nov 2020 05:51:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621094; cv=none; d=google.com; s=arc-20160816; b=B6vSIZEl7ccFmIRRuWpIsgVRNLQDUEudwBO27/2a9j0UAk5Mstt8hMQn6Zfb5kUZNQ RrsGHDLrkLwWdClTIj6HRy8Tu39BK+t4lfeS9tFrtmzkdUMutNf3WkL1yytdKB721nOm OtWzuEyAmLQYP708cqD2EwVG2Tpvv72LstTBScaayqc+dU8xI3fXbVU3D6Uwit0VmE7z tYvSTsbJ2tfmYAJvrmo/DhDqQR73/SrNoYKS77rhbVqaZSfm8ef3mWoxxqV7nBmAYonB 0W15/B2zutVP2x/o6+/e+pgQxaAtfue0AYytlyMCeM0Vj2uP46ed+5mRgtQeUv3mkKSS xuRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FpszeN0uDM7dtzkZRwTpRomz5S/frdjYfeBnL3EWCFw=; b=ZTOyZZo2SQy0iAmMBPctRNw7ihvK2FoQgmxZfTItfkNBHPajPEqEigwvrZrhKkuyZO ebbqkfW21GMrIly6Nzw3fXjjTkvzZtlqSkg7eAzmLosOh59wS7dxWovj/og4NRShFMNv ttJuVSrDuCgo7w6RfQQWFd36pPeU92FaoDKbEhs3eaHjpcI/ONNdOyT/08+bedtqHCFd wpubJqHdD42MJ700rHrvgDaHkG3vOjZBS3iqzR2ynK/AGYPa9sYCXmAmcYJ8nzrn3qsg JqY/KlFJTcjZDAoOje6Rpt9wl0OkBRAMt9Vv+de1cpZzCM0zpY1/dwjoeBo8UYXOBmzH DGxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bzxxNB6S; 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 yl23si15489542ejb.441.2020.11.17.05.51.11; Tue, 17 Nov 2020 05:51:34 -0800 (PST) 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=bzxxNB6S; 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 S1733027AbgKQNsU (ORCPT + 99 others); Tue, 17 Nov 2020 08:48:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:45740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731947AbgKQNfE (ORCPT ); Tue, 17 Nov 2020 08:35:04 -0500 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 DEB8824654; Tue, 17 Nov 2020 13:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620104; bh=gsZzhpNhKxZj7xoAP8JfaCFstR1OO7zaXoYOFnYeiGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bzxxNB6SiWUd2qs442V9PjR5ZEVH+Q4LNAwUjTYROn6snw8SVxIDjpr6VVnJfPZQH ILDcdOLGgtORkPhgvIhDhYVPH79OjZUhzOeFVKN0udqbsKZ37smj1BS2925I6aw0Z1 w/FbZpVbOAB567pRPeV8AJDGuNPJoMpNI8a589ds= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Leng , Sagi Grimberg , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.9 108/255] nvme-rdma: avoid race between time out and tear down Date: Tue, 17 Nov 2020 14:04:08 +0100 Message-Id: <20201117122144.211557361@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Leng [ Upstream commit 3017013dcc82a4862bd1e140f8b762cfc594008d ] Now use teardown_lock to serialize for time out and tear down. This may cause abnormal: first cancel all request in tear down, then time out may complete the request again, but the request may already be freed or restarted. To avoid race between time out and tear down, in tear down process, first we quiesce the queue, and then delete the timer and cancel the time out work for the queue. At the same time we need to delete teardown_lock. Signed-off-by: Chao Leng Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/rdma.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 3a598e91e816d..73961cc1e9799 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -122,7 +122,6 @@ struct nvme_rdma_ctrl { struct sockaddr_storage src_addr; struct nvme_ctrl ctrl; - struct mutex teardown_lock; bool use_inline_data; u32 io_queues[HCTX_MAX_TYPES]; }; @@ -1010,8 +1009,8 @@ 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); + blk_sync_queue(ctrl->ctrl.admin_q); nvme_rdma_stop_queue(&ctrl->queues[0]); if (ctrl->ctrl.admin_tagset) { blk_mq_tagset_busy_iter(ctrl->ctrl.admin_tagset, @@ -1021,16 +1020,15 @@ static void nvme_rdma_teardown_admin_queue(struct nvme_rdma_ctrl *ctrl, if (remove) 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_start_freeze(&ctrl->ctrl); nvme_stop_queues(&ctrl->ctrl); + nvme_sync_io_queues(&ctrl->ctrl); nvme_rdma_stop_io_queues(ctrl); if (ctrl->ctrl.tagset) { blk_mq_tagset_busy_iter(ctrl->ctrl.tagset, @@ -1041,7 +1039,6 @@ 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_free_ctrl(struct nvme_ctrl *nctrl) @@ -1975,16 +1972,12 @@ static void nvme_rdma_complete_timed_out(struct request *rq) { struct nvme_rdma_request *req = blk_mq_rq_to_pdu(rq); struct nvme_rdma_queue *queue = req->queue; - struct nvme_rdma_ctrl *ctrl = queue->ctrl; - /* fence other contexts that may complete the command */ - mutex_lock(&ctrl->teardown_lock); nvme_rdma_stop_queue(queue); if (!blk_mq_request_completed(rq)) { nvme_req(rq)->status = NVME_SC_HOST_ABORTED_CMD; blk_mq_complete_request(rq); } - mutex_unlock(&ctrl->teardown_lock); } static enum blk_eh_timer_return @@ -2319,7 +2312,6 @@ 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)) { opts->trsvcid = -- 2.27.0