From nobody Sun Feb 8 21:27:51 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CAEC7FBC1 for ; Tue, 9 Apr 2024 09:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712655320; cv=none; b=YPaEmRXB39qhKrMafWTFGBZw/we7l7RamLPbYFa8WaUgb/j/0NtJOqUJe41awFfL1Hv1iy1hvm3wQzD99jH7jvblWKzjz6RSzOrMQV3HXgsz5K/sdwn/O7VXU2EDCR1d0LXsXgruPd+t8CUfmJkRkNvkYmrRglGrZN0cUJgWeF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712655320; c=relaxed/simple; bh=Vz9brLZSm2ja+zoTUSmNSTB6NbqnXZfl+0tKCUePias=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ad0DtQVIxoP+qo8XANES0uer6vvo9iEptspDR/ZV5GNm2EGxTa0e2MIEMhkEBIbubGc9IuK7b/ULQehRzhpjKZWTaJGhc0YYddzk63Zjewa1g8TAG7AnV3p4m1SHQwdB1wzETOmGFAStZAUkj+pKu6L2iZVt+55ZImTgqAuOki8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fD+SdJZE; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=UW57XE38; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fD+SdJZE; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=UW57XE38; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fD+SdJZE"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="UW57XE38"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fD+SdJZE"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="UW57XE38" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B5AED338F3; Tue, 9 Apr 2024 09:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712655316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XIqRfgEy/L6lYO+lVF7E1EL2Hg3bqx5jfUAwzOfn4PQ=; b=fD+SdJZEQKcGad53sw8FDngnjd+m7WP2kEoYZ6JNVfTKx0zlGPub1V1MXKcns3eBrhBGwR pFS34CCVGYdX0XdjQ4/PuGHFmZzUoXqNZtccm1S9Pg8LUH8Qe26r0EIH3bKUd+u/IhryPD KFFzUMcK+RBtPEc9p1Z3QsqeotIEq4A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712655316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XIqRfgEy/L6lYO+lVF7E1EL2Hg3bqx5jfUAwzOfn4PQ=; b=UW57XE38XurvQQ7LB0UHqmz4VUZ1pZlUXFbfblMHl3JwspHZo7s8loNnnTnSiU71z6WoUq NNQjaF4pFwpWEODQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712655316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XIqRfgEy/L6lYO+lVF7E1EL2Hg3bqx5jfUAwzOfn4PQ=; b=fD+SdJZEQKcGad53sw8FDngnjd+m7WP2kEoYZ6JNVfTKx0zlGPub1V1MXKcns3eBrhBGwR pFS34CCVGYdX0XdjQ4/PuGHFmZzUoXqNZtccm1S9Pg8LUH8Qe26r0EIH3bKUd+u/IhryPD KFFzUMcK+RBtPEc9p1Z3QsqeotIEq4A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712655316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XIqRfgEy/L6lYO+lVF7E1EL2Hg3bqx5jfUAwzOfn4PQ=; b=UW57XE38XurvQQ7LB0UHqmz4VUZ1pZlUXFbfblMHl3JwspHZo7s8loNnnTnSiU71z6WoUq NNQjaF4pFwpWEODQ== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id A39C11332F; Tue, 9 Apr 2024 09:35:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id jpZtJtQLFWarRwAAn2gu4w (envelope-from ); Tue, 09 Apr 2024 09:35:16 +0000 From: Daniel Wagner To: Christoph Hellwig Cc: Keith Busch , Sagi Grimberg , James Smart , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner Subject: [PATCH v5 3/6] nvme-tcp: short-circuit reconnect retries Date: Tue, 9 Apr 2024 11:35:07 +0200 Message-ID: <20240409093510.12321-4-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240409093510.12321-1-dwagner@suse.de> References: <20240409093510.12321-1-dwagner@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap2.dmz-prg2.suse.org:helo,imap2.dmz-prg2.suse.org:rdns]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] Content-Type: text/plain; charset="utf-8" From: Hannes Reinecke Returning an nvme status from nvme_tcp_setup_ctrl() indicates that the association was established and we have received a status from the controller; consequently we should honour the DNR bit. If not any future reconnect attempts will just return the same error, so we can short-circuit the reconnect attempts and fail the connection directly. Signed-off-by: Hannes Reinecke [dwagner: add helper to decide to reconnect] Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig --- drivers/nvme/host/nvme.h | 24 ++++++++++++++++++++++++ drivers/nvme/host/tcp.c | 23 +++++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 9b8904a476b8..dfe103283a3d 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -701,6 +701,30 @@ static inline bool nvme_is_path_error(u16 status) return (status & 0x700) =3D=3D 0x300; } =20 +/* + * Evaluate the status information returned by the LLDD in order to + * decided if a reconnect attempt should be scheduled. + * + * There are two cases where no reconnect attempt should be attempted: + * + * 1) The LLDD reports an negative status. There was an error (e.g. no + * memory) on the host side and thus abort the operation. + * Note, there are exception such as ENOTCONN which is + * not an internal driver error, thus we filter these errors + * out and retry later. + * 2) The DNR bit is set and the specification states no further + * connect attempts with the same set of paramenters should be + * attempted. + */ +static inline bool nvme_ctrl_reconnect(int status) +{ + if (status < 0 && status !=3D -ENOTCONN) + return false; + else if (status > 0 && (status & NVME_SC_DNR)) + return false; + return true; +} + /* * Fill in the status and result information from the CQE, and then figure= out * if blk-mq will need to use IPI magic to complete the request, and if ye= s do diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index fdbcdcedcee9..7e25a96e9870 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -2155,9 +2155,11 @@ static void nvme_tcp_teardown_io_queues(struct nvme_= ctrl *ctrl, nvme_tcp_destroy_io_queues(ctrl, remove); } =20 -static void nvme_tcp_reconnect_or_remove(struct nvme_ctrl *ctrl) +static void nvme_tcp_reconnect_or_remove(struct nvme_ctrl *ctrl, + int status) { enum nvme_ctrl_state state =3D nvme_ctrl_state(ctrl); + bool recon =3D nvme_ctrl_reconnect(status); =20 /* If we are resetting/deleting then do nothing */ if (state !=3D NVME_CTRL_CONNECTING) { @@ -2165,13 +2167,14 @@ static void nvme_tcp_reconnect_or_remove(struct nvm= e_ctrl *ctrl) return; } =20 - if (nvmf_should_reconnect(ctrl)) { + if (recon && nvmf_should_reconnect(ctrl)) { dev_info(ctrl->device, "Reconnecting in %d seconds...\n", ctrl->opts->reconnect_delay); queue_delayed_work(nvme_wq, &to_tcp_ctrl(ctrl)->connect_work, ctrl->opts->reconnect_delay * HZ); } else { - dev_info(ctrl->device, "Removing controller...\n"); + dev_info(ctrl->device, "Removing controller (%d)...\n", + status); nvme_delete_ctrl(ctrl); } } @@ -2252,10 +2255,12 @@ static void nvme_tcp_reconnect_ctrl_work(struct wor= k_struct *work) struct nvme_tcp_ctrl *tcp_ctrl =3D container_of(to_delayed_work(work), struct nvme_tcp_ctrl, connect_work); struct nvme_ctrl *ctrl =3D &tcp_ctrl->ctrl; + int ret; =20 ++ctrl->nr_reconnects; =20 - if (nvme_tcp_setup_ctrl(ctrl, false)) + ret =3D nvme_tcp_setup_ctrl(ctrl, false); + if (ret) goto requeue; =20 dev_info(ctrl->device, "Successfully reconnected (%d attempt)\n", @@ -2268,7 +2273,7 @@ static void nvme_tcp_reconnect_ctrl_work(struct work_= struct *work) requeue: dev_info(ctrl->device, "Failed reconnect attempt %d\n", ctrl->nr_reconnects); - nvme_tcp_reconnect_or_remove(ctrl); + nvme_tcp_reconnect_or_remove(ctrl, ret); } =20 static void nvme_tcp_error_recovery_work(struct work_struct *work) @@ -2295,7 +2300,7 @@ static void nvme_tcp_error_recovery_work(struct work_= struct *work) return; } =20 - nvme_tcp_reconnect_or_remove(ctrl); + nvme_tcp_reconnect_or_remove(ctrl, -ENOTCONN); } =20 static void nvme_tcp_teardown_ctrl(struct nvme_ctrl *ctrl, bool shutdown) @@ -2315,6 +2320,7 @@ static void nvme_reset_ctrl_work(struct work_struct *= work) { struct nvme_ctrl *ctrl =3D container_of(work, struct nvme_ctrl, reset_work); + int ret; =20 nvme_stop_ctrl(ctrl); nvme_tcp_teardown_ctrl(ctrl, false); @@ -2328,14 +2334,15 @@ static void nvme_reset_ctrl_work(struct work_struct= *work) return; } =20 - if (nvme_tcp_setup_ctrl(ctrl, false)) + ret =3D nvme_tcp_setup_ctrl(ctrl, false); + if (ret) goto out_fail; =20 return; =20 out_fail: ++ctrl->nr_reconnects; - nvme_tcp_reconnect_or_remove(ctrl); + nvme_tcp_reconnect_or_remove(ctrl, ret); } =20 static void nvme_tcp_stop_ctrl(struct nvme_ctrl *ctrl) --=20 2.44.0