From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0B81C10F1A for ; Tue, 7 May 2024 23:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OD3GZZTh5WyIiJ57GlAu10aW0Kp6HKVgZlfLVo7AVts=; b=fkJJeddSw1/kUg1fhPwOO0Hqkm BlS/Shl55U/xzYQ+x3G16596WKR8kfvgrE0mw3IE+WxJZREbG0Art98FuWga9XlrtcviOVZC6lBrV Nw+n72aW/eVB5A9oc7z8FfAQnr5i9ARwPhQH4odhA9J7fy/affygy04OCD9K3VRTav7n/AfApmLXL k8nByVG/98L+H1Fzl70a+3juwMLWatNqhCIqS69RVnDldcAHYY9NbNxuQ5BUiP3/pDV4HnLGhF/lz gBwVlAGvWmxGoNmbpUebdzniivZibD2y+O2VnyABxQgcRYy9ZA1F7WdQAel43c/2pAI1cN9hQYHGP DUx5XECA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4U0N-0000000DCdW-2BcC; Tue, 07 May 2024 23:13:51 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4U07-0000000DCRi-36Gv for linux-nvme@bombadil.infradead.org; Tue, 07 May 2024 23:13:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=OD3GZZTh5WyIiJ57GlAu10aW0Kp6HKVgZlfLVo7AVts=; b=co4IIzix5nKQ2Zm58zdS5jZ5zI yamWQH3Ue41NGkYM7BiYhpFIn0EVFJqwwqQb5IQfRHjZjplf4NiERJGRPZA+8ERG9nFy6awaq8Pad 8u6M3UbCx9Bcq47J3rNdNnXtWnUBaM513Pns5oUvuqxJFXEez2drDJTxtTneT6Uz86m4SIeEy4Kys OVoP5Fjpp5j5uItesNjz4479YXAHBWQKv5GkBKISNdAYStJgxVu02jNIb82N9hbZQEwT0chexOTnq vpI8IqWtqvhCKXBCD/9whKS/Mo6azG2i1o0MO51Ls2cqfGnpcRlXKi398GO5aPFWn5zepuy6ysLKG Mn1Vdk8w==; Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4Tzy-00000002HFr-3Kqt for linux-nvme@lists.infradead.org; Tue, 07 May 2024 23:13:32 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 306AFCE174F; Tue, 7 May 2024 23:13:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEFDBC4AF67; Tue, 7 May 2024 23:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715123602; bh=tgwO8+CtUOQsoly9s6IDZYRIIboOPrGDOnhdcbpSfOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=khLgtBr1+dRwfQC4gpXJSQFWwlhC6PEW98+HULdVfE4D2d3HmmCOzpvDqNih/ZEwQ ubtC6YSXR5J2z/ROTO6hef3h6t9jWXnKHKCeXbGIyUMcLcfnMb9eC/ybEgxsH2FI4n f01ux4KxOPaG3y4qGoB2kBH7ZC1tMTML6kcyxvOg132qHnDv39o2G1ixvBarrQLJkc llgGNInPSvYVBsNBz3hf8n0xAlBR5Cndhh+UN8BpAv3mF2UD7M9vyx7HXJNkmEMrAU ICyZx3CQL+vUsYu2ik5bnIaoyeFYhxNJ/Sn/a4xxNGAeWmFyTIFR3ebORBgkK1IAQZ 7uB4hzxlF5DAQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sagi Grimberg , Jirong Feng , Christoph Hellwig , Keith Busch , Sasha Levin , kch@nvidia.com, linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.1 24/25] nvmet: fix nvme status code when namespace is disabled Date: Tue, 7 May 2024 19:12:11 -0400 Message-ID: <20240507231231.394219-24-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240507231231.394219-1-sashal@kernel.org> References: <20240507231231.394219-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.90 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240508_001329_302401_57E37CFF X-CRM114-Status: GOOD ( 17.19 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org From: Sagi Grimberg [ Upstream commit 505363957fad35f7aed9a2b0d8dad73451a80fb5 ] If the user disabled a nvmet namespace, it is removed from the subsystem namespaces list. When nvmet processes a command directed to an nsid that was disabled, it cannot differentiate between a nsid that is disabled vs. a non-existent namespace, and resorts to return NVME_SC_INVALID_NS with the dnr bit set. This translates to a non-retryable status for the host, which translates to a user error. We should expect disabled namespaces to not cause an I/O error in a multipath environment. Address this by searching a configfs item for the namespace nvmet failed to find, and if we found one, conclude that the namespace is disabled (perhaps temporarily). Return NVME_SC_INTERNAL_PATH_ERROR in this case and keep DNR bit cleared. Reported-by: Jirong Feng Tested-by: Jirong Feng Signed-off-by: Sagi Grimberg Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/target/configfs.c | 13 +++++++++++++ drivers/nvme/target/core.c | 5 ++++- drivers/nvme/target/nvmet.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 73ae16059a1cb..b1f5fa45bb4ac 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -615,6 +615,19 @@ static struct configfs_attribute *nvmet_ns_attrs[] = { NULL, }; +bool nvmet_subsys_nsid_exists(struct nvmet_subsys *subsys, u32 nsid) +{ + struct config_item *ns_item; + char name[4] = {}; + + if (sprintf(name, "%u", nsid) <= 0) + return false; + mutex_lock(&subsys->namespaces_group.cg_subsys->su_mutex); + ns_item = config_group_find_item(&subsys->namespaces_group, name); + mutex_unlock(&subsys->namespaces_group.cg_subsys->su_mutex); + return ns_item != NULL; +} + static void nvmet_ns_release(struct config_item *item) { struct nvmet_ns *ns = to_nvmet_ns(item); diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 3235baf7cc6b1..7b74926c50f9b 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -423,10 +423,13 @@ void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl) u16 nvmet_req_find_ns(struct nvmet_req *req) { u32 nsid = le32_to_cpu(req->cmd->common.nsid); + struct nvmet_subsys *subsys = nvmet_req_subsys(req); - req->ns = xa_load(&nvmet_req_subsys(req)->namespaces, nsid); + req->ns = xa_load(&subsys->namespaces, nsid); if (unlikely(!req->ns)) { req->error_loc = offsetof(struct nvme_common_command, nsid); + if (nvmet_subsys_nsid_exists(subsys, nsid)) + return NVME_SC_INTERNAL_PATH_ERROR; return NVME_SC_INVALID_NS | NVME_SC_DNR; } diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 273cca49a040f..6aee0ce60a4ba 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -527,6 +527,7 @@ void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys, struct nvmet_host *host); void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, u8 event_info, u8 log_page); +bool nvmet_subsys_nsid_exists(struct nvmet_subsys *subsys, u32 nsid); #define NVMET_QUEUE_SIZE 1024 #define NVMET_NR_QUEUES 128 -- 2.43.0