Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp177806lqo; Tue, 7 May 2024 16:51:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKOP+1oeWko6Qh0AOFvJHLgC03K13ijTdN2y7hqnKG8Dty/nLJ0HUafLXX/3aHIZqnLjlVKxeFN0VkBgZ68N0nAEpdhVQmxwqJJaSyAA== X-Google-Smtp-Source: AGHT+IG1dPIx8XZIgGNJiyQTlPvYyWSymhXB2xflwgnK+A7+SJ+5jHloDKtLswbImj6kaK4edrwj X-Received: by 2002:a17:90a:d195:b0:2a2:7a00:f101 with SMTP id 98e67ed59e1d1-2b616be63bbmr990027a91.47.1715125895913; Tue, 07 May 2024 16:51:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715125895; cv=pass; d=google.com; s=arc-20160816; b=0DqWPvn4zFhaB0GCaRudRbUNUgvksusP4VHRZCjYkMdAqP/wQlgV98CUumCiqKPTKs tN5hOR7t68Vbe9YmBlxxLOcHeOtwyLUzzNyG9jx1kK88/Tcg8tdIBB+agPmmZHzYSuEi YNmGbOKIBUWag6uVziLt9AEYt5QR12IwXwR6X7ex0R6/nqcRshjUz/pKQXPnC01w2yOb Sp+cLlkvmPEmh32iiuAS7+ZhUWXAq6gd4mTlC+slYOv+GlB/J5dT3GrxqBMhXTWDqF/8 fgk7h7uRoBZnEoL/0AuPgN/xrRex4fDpz5RiniQTO0syko4o2Mal215thbX3gbh9XPL5 A/Ug== 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=OD3GZZTh5WyIiJ57GlAu10aW0Kp6HKVgZlfLVo7AVts=; fh=FBv2WojUUXQAksnTOip0gVGSSKhSQJUAgpgtRKMpEnM=; b=Suii+dUGnEahI809H0IE+zqPXPuP4J5mS4Z+x3ietbXVkzdf2gZMvjEiCmCbwkFrkZ FPlHmP5LNB7VenPElXb7ecGxNqoJedzHSEGe0tlAAGWWvmiesecqz+5P0iYF9cR3SGvX Mb3YyOnK92MIydw9gTZmkulLtZj7NTFUOjg3bsdtAifCHiu/OVfWsgZCisZQYQW3FA6i 4tCcqTgdtkT49TwiYi4TvpnbV6PpP4b15eg5lWqoyN4XDTrvPPQM4r2+Bencs5Y9gCCF gV4H+TBaTmRAJnHz7ipUe9sLc2AVeI6z0blrYFVTBB3p5fDyWE092UKvZnopDNtmuuR8 Jtaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=khLgtBr1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172463-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 o10-20020a17090aac0a00b002a2412861c8si160166pjq.146.2024.05.07.16.51.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 16:51:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172463-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=khLgtBr1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172463-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 396F32827D1 for ; Tue, 7 May 2024 23:49:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D3351C9EDD; Tue, 7 May 2024 23:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="khLgtBr1" 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 386EB1CB334; Tue, 7 May 2024 23:13:22 +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=1715123603; cv=none; b=Nly4K0lc50z7czZ1URIS7lsxlwPUOWv0hkgN0ayMAWhCq6kN9ibLhw8C//CSCwsIKcrdIkfguK6k67ClaiY/V4+ELQYkE2p85YhZrsdjg30CLhFwIv0SSSnvxbLJYFrHGFCqROvKUacHiv56u/nBUOaX5Qbz3ys+j7F1gZzPvkQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123603; c=relaxed/simple; bh=tgwO8+CtUOQsoly9s6IDZYRIIboOPrGDOnhdcbpSfOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uKvS8yLQociKh243havmgwtUJaoaXzvzNWSbQqmKqTKmZ+YfyHbdbBdgE893LjK14bCaDDT7Bq6fTeOFLDMWHz9QIjWfDqrlwuc5ws1B9/ki+NKt7Y9Aq32jeNQ01k3QF3V5WqoDsz0LxT5nalarUq07HVyNvF/wzSgRbqw3zzk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=khLgtBr1; arc=none smtp.client-ip=10.30.226.201 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> 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.1.90 Content-Transfer-Encoding: 8bit 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