Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp172025lqo; Tue, 7 May 2024 16:34:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCViAS+bDKwOWa48gtJ1xDp+stOdk314DlFWxFveGyCyTwSYNi2mMqJ3h/waPRhwRsMMcKB+sv42K8YKT6AUhDhaHw7NOVTGpm61zh9lCA== X-Google-Smtp-Source: AGHT+IFpUMITru8iWDbGTUuT27WIywH/TtKcyQH14Mbf1ZZZch7KRnAqbD3bIPam70CPEekYOq1I X-Received: by 2002:a05:6a00:2d04:b0:6ed:41f4:1886 with SMTP id d2e1a72fcca58-6f49bd8a073mr1925193b3a.8.1715124858268; Tue, 07 May 2024 16:34:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715124858; cv=pass; d=google.com; s=arc-20160816; b=k7j4NedJ2trlKQqKNpliKchVxCb2BCsvn96q1XkdT3cPhaGsopARsrJWxmtUZsEj9A gjGvCY5A2a5NmIcdKp1/lfm6R32rVbCaYB4hyrFRMKLDSdopl7rf6K8u/AwrT/cg3UAp SravCC9a/Dp+FH5+Birf6VIToyYDY8YMJkSxBlvbcVIPs+6ODrip61IQQn7C7xIjkGOW Vh5zVmEiZpC3El8X6V1O9QTi7MTYtyOfS+joBl1CzttKd5eyuEnefpc/cIzpOM7WMOhV JhySHrPXHyakOyweeZwi+HHxzSO9eje2tdUegpCqNtgPfctN0VnrFNpDZIE16f4x0eZP yAIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9U0ktc1+PQm+mJDx0oI9czaxqbSHOrfazELOsW+HFSY=; fh=AWfXMv8s/sgDUud0Ezla+JythO99ZZv7yMz/avruiOY=; b=mOhssWIg5Aoeiez9ZPlWy0XM+wb9C27FPsSDK6hENb4UvGAY95gzuIrDSa9KddrkTW vvgZuTuDNDIuqp/qSK6yW4rNWfbYZ64XBgU14fTjCUyvpT4HZtMSY6s75vuQB7V72ej6 8VyGyQ83AR6WTJG3YQcnx62bn/5qR2Vo3neg3KPoZlfPHZrwFWsEAXIhczHouDoBhmUD khwVbH9D/Zvc8Lo6IYVLlbwWj+ofqHQW9aT6bi+rslIa3KekTXb5tNm2ZAbhZESgqjLB eKhge8/VOqW7186uoPRpjT7uTen0JuevgzIdKQqp+cb73cLorh8Yrgl7GOYTSuMGhJUA oNMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C7TrBH1c; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172391-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172391-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cz17-20020aa79311000000b006eab069cdc0si11319709pfb.160.2024.05.07.16.34.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 16:34:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172391-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C7TrBH1c; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172391-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172391-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 13FB4281A3D for ; Tue, 7 May 2024 23:34:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D5A0136679; Tue, 7 May 2024 23:09:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C7TrBH1c" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90ED1146D77; Tue, 7 May 2024 23:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123397; cv=none; b=oE5Z1eXAT32+q5emfJY1Ns5EEDYJSqKz0rg/FUSIYt6zgfElu7YMhR6Jbw7Qh8Ri1pBIOFf4j2mtD0YfLSN8iJ/MdvAS9tlID4VZ18JRQ8uuoymBMwLAZK79XyIkFB099mMpbYfrE7xLHKCcQCryEBSF2ccYcpx++MVYEhphSS0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123397; c=relaxed/simple; bh=fRY0xZl+owN0RJj7s3kJC8X0Ka726n2x8we9v9HqDD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V/Afy0w3TNTmR8l9x2B/CnEqLh/Lod07v9Zf5p+eWMhUpXoYOS2LPP33yU/9TpJd9aJ038fOH5Yn3VgQNEwPJL9yYcaVSN+BBLUsOjeiRQJ93sHioQOogAghWpb547h3QoU1JjpZCXoVlYS8b9eJsKn18hok5EsoN3eZP2klgCc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C7TrBH1c; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 675FEC4AF68; Tue, 7 May 2024 23:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715123397; bh=fRY0xZl+owN0RJj7s3kJC8X0Ka726n2x8we9v9HqDD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C7TrBH1cRl/ZV2/sSLhLMrjeOkM4LbbDBA2oKGJeUH1PQJJ7uEBdPuc1QMyB1V08v kjTR2skzfROhyLaaq9oVHcxLvnycftv/MG+pSFO3hsDCJWuK/unFKM1JI4tD6UlffO BBOb3+2vLvnkNXVJy08cQ1H7fDpSlUh2CiBBfCjhvESPvaTVhEsV1sGT33Ly2ZawaU cXKiOvvvnLIYymNSp7Kr6FItJjUcq22dOj9Iqf2NoV9NeP2g/50sW89stw9wDYdzRC KZbcJEdpxwLq0U5HRDX5VZEsn5SjlJ3y2Cc8V+7JWUEMHUJQfbq6M7PNvh/QtO63ra giH4UpE+cI0Sw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nilay Shroff , Sagi Grimberg , Keith Busch , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.8 48/52] nvme: cancel pending I/O if nvme controller is in terminal state Date: Tue, 7 May 2024 19:07:14 -0400 Message-ID: <20240507230800.392128-48-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240507230800.392128-1-sashal@kernel.org> References: <20240507230800.392128-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.9 Content-Transfer-Encoding: 8bit From: Nilay Shroff [ Upstream commit 25bb3534ee21e39eb9301c4edd7182eb83cb0d07 ] While I/O is running, if the pci bus error occurs then in-flight I/O can not complete. Worst, if at this time, user (logically) hot-unplug the nvme disk then the nvme_remove() code path can't forward progress until in-flight I/O is cancelled. So these sequence of events may potentially hang hot-unplug code path indefinitely. This patch helps cancel the pending/in-flight I/O from the nvme request timeout handler in case the nvme controller is in the terminal (DEAD/DELETING/DELETING_NOIO) state and that helps nvme_remove() code path forward progress and finish successfully. Link: https://lore.kernel.org/all/199be893-5dfa-41e5-b6f2-40ac90ebccc4@linux.ibm.com/ Signed-off-by: Nilay Shroff Reviewed-by: Sagi Grimberg Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 21 --------------------- drivers/nvme/host/nvme.h | 21 +++++++++++++++++++++ drivers/nvme/host/pci.c | 8 +++++++- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index fe3627c5bdc99..01702bc1baf1e 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -619,27 +619,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, } EXPORT_SYMBOL_GPL(nvme_change_ctrl_state); -/* - * Returns true for sink states that can't ever transition back to live. - */ -static bool nvme_state_terminal(struct nvme_ctrl *ctrl) -{ - switch (nvme_ctrl_state(ctrl)) { - case NVME_CTRL_NEW: - case NVME_CTRL_LIVE: - case NVME_CTRL_RESETTING: - case NVME_CTRL_CONNECTING: - return false; - case NVME_CTRL_DELETING: - case NVME_CTRL_DELETING_NOIO: - case NVME_CTRL_DEAD: - return true; - default: - WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state); - return true; - } -} - /* * Waits for the controller state to be resetting, or returns false if it is * not possible to ever transition to that state. diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 7b87763e2f8a6..5a09879cb1a5f 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -740,6 +740,27 @@ static inline bool nvme_is_aen_req(u16 qid, __u16 command_id) nvme_tag_from_cid(command_id) >= NVME_AQ_BLK_MQ_DEPTH; } +/* + * Returns true for sink states that can't ever transition back to live. + */ +static inline bool nvme_state_terminal(struct nvme_ctrl *ctrl) +{ + switch (nvme_ctrl_state(ctrl)) { + case NVME_CTRL_NEW: + case NVME_CTRL_LIVE: + case NVME_CTRL_RESETTING: + case NVME_CTRL_CONNECTING: + return false; + case NVME_CTRL_DELETING: + case NVME_CTRL_DELETING_NOIO: + case NVME_CTRL_DEAD: + return true; + default: + WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state); + return true; + } +} + void nvme_complete_rq(struct request *req); void nvme_complete_batch_req(struct request *req); diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 8e0bb9692685d..e393f6947ce49 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1286,6 +1286,9 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req) u32 csts = readl(dev->bar + NVME_REG_CSTS); u8 opcode; + if (nvme_state_terminal(&dev->ctrl)) + goto disable; + /* If PCI error recovery process is happening, we cannot reset or * the recovery mechanism will surely fail. */ @@ -1390,8 +1393,11 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req) return BLK_EH_RESET_TIMER; disable: - if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING)) + if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING)) { + if (nvme_state_terminal(&dev->ctrl)) + nvme_dev_disable(dev, true); return BLK_EH_DONE; + } nvme_dev_disable(dev, false); if (nvme_try_sched_reset(&dev->ctrl)) -- 2.43.0