Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp877224pxk; Thu, 17 Sep 2020 20:05:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwc+zFKj8n5M4rtTopRqRHqg0XIp3rXbeoN79mH+BhKoyjsIC72LGvLqEmSqEAb7Mww8gL2 X-Received: by 2002:a17:906:3ca2:: with SMTP id b2mr34792100ejh.460.1600398303442; Thu, 17 Sep 2020 20:05:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398303; cv=none; d=google.com; s=arc-20160816; b=ahAHrAJYOXWXqLtiw2y/XutnUZBzrpz6oyahTOoqP/xqp5eFmhH/kVJm9Y5MeqliVL 9mtRER1IsxI5pcHSQi3wm7kVCLfSkDQ9x0eRmE+DI4kUedoJiFgjtc+HxwG3UYyEG03P RctOnRhRN77QJHB6wgAmfTkh9rVA+qJsv8kWJeDX8FUTQrlQ2JyDKYk9abQDXKR+/yLu FMWKAaoUJkfE7HfQmPbd0do+TLMJS35z0rqRLBGz0uGHnZLkoh8oG+2NBNt3MogNkUa7 60XPNZ9cRwnJCeAdGxzS+HpJEY/h6qWpg4uRD21Id0hYeTSbDic9cgK6dGjzNRh71mRR DQeg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=biRCc9IOBrXJWupx2MiseYEHmZYcbsK9dR/tqv9LaU0=; b=iHB+xUPM2lwrePU04aP9t8ckZY535j4UsCZjEaznmaqmOY6ahzVHbvitet42hKuOR8 qLUVbgIDGzh7lOjEfA55CfK7q5w1h1cU9bns+TvlBMmX6/LuPS6SmKEmYyXI/i1+tA5l 0/EohqfH1/HyAQQ0qThiRrH+e9DS6koV8r3HjQ7azGT3mNMQ2yyYPGjUI5gat08quyff vGG55luPbMQ/I2BmWIYOOtLUdAuM6s4UG9iqjjvPxlcoOpMpPAdipPbnB8VC5l/m/QR8 mOvdurCLTwR2u1CqZvLXFfhY924iAALVCbZXnQiadOTJQwDwsx1hgAhQxsvMmlgCKN0s K96w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1HNIP53D; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id os2si1253972ejb.112.2020.09.17.20.04.40; Thu, 17 Sep 2020 20:05:03 -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=1HNIP53D; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729683AbgIRDCc (ORCPT + 99 others); Thu, 17 Sep 2020 23:02:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:53688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726764AbgIRCFY (ORCPT ); Thu, 17 Sep 2020 22:05:24 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 738D0238D7; Fri, 18 Sep 2020 02:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394724; bh=2eTwmvBvDNezBSEcfRJDbrRY4vXYE3XhnXOu0YA7VQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1HNIP53D9dyINe143Oo1a34m4xLq7mBkHelF/bJgutrgmIY9MV0GrevD1x6kbPRE6 Vc0jodjE6fUB4SQucKaUKElD9mhL3uWNGy2MI1T4ptiZts9iZwE32FqvEojgwEHty3 HohoezimNcsWZ0JMKaOaBR3tpMHa7QjiG+XWEhwk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Israel Rukshin , Max Gurtovoy , Christoph Hellwig , Keith Busch , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 207/330] nvme: Fix controller creation races with teardown flow Date: Thu, 17 Sep 2020 21:59:07 -0400 Message-Id: <20200918020110.2063155-207-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Israel Rukshin [ Upstream commit ce1518139e6976cf19c133b555083354fdb629b8 ] Calling nvme_sysfs_delete() when the controller is in the middle of creation may cause several bugs. If the controller is in NEW state we remove delete_controller file and don't delete the controller. The user will not be able to use nvme disconnect command on that controller again, although the controller may be active. Other bugs may happen if the controller is in the middle of create_ctrl callback and nvme_do_delete_ctrl() starts. For example, freeing I/O tagset at nvme_do_delete_ctrl() before it was allocated at create_ctrl callback. To fix all those races don't allow the user to delete the controller before it was fully created. Signed-off-by: Israel Rukshin Reviewed-by: Max Gurtovoy Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 5 +++++ drivers/nvme/host/nvme.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e51cc83969034..f01fe2d910b54 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3197,6 +3197,10 @@ static ssize_t nvme_sysfs_delete(struct device *dev, { struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + /* Can't delete non-created controllers */ + if (!ctrl->created) + return -EBUSY; + if (device_remove_file_self(dev, attr)) nvme_delete_ctrl_sync(ctrl); return count; @@ -3992,6 +3996,7 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl) nvme_queue_scan(ctrl); nvme_start_queues(ctrl); } + ctrl->created = true; } EXPORT_SYMBOL_GPL(nvme_start_ctrl); diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 80bfffa943ccd..7d57c42a641ca 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -253,6 +253,7 @@ struct nvme_ctrl { struct nvme_command ka_cmd; struct work_struct fw_act_work; unsigned long events; + bool created; #ifdef CONFIG_NVME_MULTIPATH /* asymmetric namespace access: */ -- 2.25.1