From nobody Mon Feb 9 18:59:52 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 A0B33129A78 for ; Thu, 4 Apr 2024 15:45:09 +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=1712245511; cv=none; b=rr1qF3tP5+urvGiH7uc8LzQS6eHkwkY+ECt6FdyBCUGNL5VjzdlSiF8RFcxeExeKd194BVPQupT+mNkTyGnig47LtY4OMKrKDVh+2Hd0QDMdQGhcvgr6i0VWUPZwkQDxuMXuUweWUxwA0R/zFiS6wq/5LIGeu39ZV5Rirv+kCqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245511; c=relaxed/simple; bh=tNlPyQF88QSNX+Tj/k0AVXYxdNBsZxnjN5oUI/u8sZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JTmi+TSK6ymi93VP2W2sbkzH3ZF3YmUbtr9BZwEb+qeeMkS5eRGP+NFLXtaJXzr354EyjuxAM02O6y6+tSxZ4E13IWdcmT8xxpTp3GpnmZ6lKGhBTlpoxMGqporz6l8SM5pzYUOLBwFeDfoX0VR8ulEaYEuVAZ2kg0QG1KbphEw= 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=instcgC+; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=KfOq7kDH; 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="instcgC+"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="KfOq7kDH" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 4F10A37B9A; Thu, 4 Apr 2024 15:45:07 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712245507; 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=yy41hneCF9B6A6GK/jkAhPh1ji1tqfMgrz6ELZgBYN8=; b=instcgC+jCtgKwbASYiv/zOsI5HlOhoSSwtX0h2AQdvRHGayQxIWYaig6/ypK+ZzeM1l5x evOg2085rGHDFrFoa3/9Jq9tv7g/ZZuLg8lEATu3ybLF/kPs8kaDzKW5rgJeBznXjZpRHq xK41eA3U/7C0PnNa/DRJRlElr0Ngefs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712245507; 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=yy41hneCF9B6A6GK/jkAhPh1ji1tqfMgrz6ELZgBYN8=; b=KfOq7kDHKYBAK5B0b4HOysQ6hL7njrNVHXvlnye/2sxFyoyuLdA7w4BnR99nAERNi2XsuX e4ltWU6LbSaPyoDA== 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 3C3F413A91; Thu, 4 Apr 2024 15:45:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id pqlHDQPLDmYEIgAAn2gu4w (envelope-from ); Thu, 04 Apr 2024 15:45:07 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner Subject: [PATCH v4 1/5] nvme: authentication error are always non-retryable Date: Thu, 4 Apr 2024 17:44:56 +0200 Message-ID: <20240404154500.2101-2-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404154500.2101-1-dwagner@suse.de> References: <20240404154500.2101-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-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 4F10A37B9A X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action Content-Type: text/plain; charset="utf-8" From: Hannes Reinecke Any authentication errors which are generated internally are always non-retryable, so set the DNR bit to ensure they are not retried. Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/host/core.c | 6 +++--- drivers/nvme/host/fabrics.c | 29 +++++++++++++++++------------ drivers/nvme/host/nvme.h | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 504dc352c458..66387bcca8ae 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -383,14 +383,14 @@ static inline enum nvme_disposition nvme_decide_dispo= sition(struct request *req) if (likely(nvme_req(req)->status =3D=3D 0)) return COMPLETE; =20 - if ((nvme_req(req)->status & 0x7ff) =3D=3D NVME_SC_AUTH_REQUIRED) - return AUTHENTICATE; - if (blk_noretry_request(req) || (nvme_req(req)->status & NVME_SC_DNR) || nvme_req(req)->retries >=3D nvme_max_retries) return COMPLETE; =20 + if ((nvme_req(req)->status & 0x7ff) =3D=3D NVME_SC_AUTH_REQUIRED) + return AUTHENTICATE; + if (req->cmd_flags & REQ_NVME_MPATH) { if (nvme_is_path_error(nvme_req(req)->status) || blk_queue_dying(req->q)) diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index 1f0ea1f32d22..309a69c24995 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -467,7 +467,7 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) if (result & NVME_CONNECT_AUTHREQ_ASCR) { dev_warn(ctrl->device, "qid 0: secure concatenation is not supported\n"); - ret =3D NVME_SC_AUTH_REQUIRED; + ret =3D NVME_SC_AUTH_REQUIRED | NVME_SC_DNR; goto out_free_data; } /* Authentication required */ @@ -475,14 +475,16 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) if (ret) { dev_warn(ctrl->device, "qid 0: authentication setup failed\n"); - ret =3D NVME_SC_AUTH_REQUIRED; + ret =3D NVME_SC_AUTH_REQUIRED | NVME_SC_DNR; goto out_free_data; } ret =3D nvme_auth_wait(ctrl, 0); - if (ret) + if (ret) { dev_warn(ctrl->device, - "qid 0: authentication failed\n"); - else + "qid 0: authentication failed, error %d\n", + ret); + ret =3D NVME_SC_AUTH_REQUIRED | NVME_SC_DNR; + } else dev_info(ctrl->device, "qid 0: authenticated\n"); } @@ -542,7 +544,7 @@ int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 q= id) if (result & NVME_CONNECT_AUTHREQ_ASCR) { dev_warn(ctrl->device, "qid 0: secure concatenation is not supported\n"); - ret =3D NVME_SC_AUTH_REQUIRED; + ret =3D NVME_SC_AUTH_REQUIRED | NVME_SC_DNR; goto out_free_data; } /* Authentication required */ @@ -550,12 +552,15 @@ int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16= qid) if (ret) { dev_warn(ctrl->device, "qid %d: authentication setup failed\n", qid); - ret =3D NVME_SC_AUTH_REQUIRED; - } else { - ret =3D nvme_auth_wait(ctrl, qid); - if (ret) - dev_warn(ctrl->device, - "qid %u: authentication failed\n", qid); + ret =3D NVME_SC_AUTH_REQUIRED | NVME_SC_DNR; + goto out_free_data; + } + ret =3D nvme_auth_wait(ctrl, qid); + if (ret) { + dev_warn(ctrl->device, + "qid %u: authentication failed, error %d\n", + qid, ret); + ret =3D NVME_SC_AUTH_REQUIRED | NVME_SC_DNR; } } out_free_data: diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index d0ed64dc7380..882967365108 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -1122,7 +1122,7 @@ static inline int nvme_auth_negotiate(struct nvme_ctr= l *ctrl, int qid) } static inline int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid) { - return NVME_SC_AUTH_REQUIRED; + return NVME_SC_AUTH_REQUIRED | NVME_SC_DNR; } static inline void nvme_auth_free(struct nvme_ctrl *ctrl) {}; #endif --=20 2.44.0 From nobody Mon Feb 9 18:59:52 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 A0AEE86ADB for ; Thu, 4 Apr 2024 15:45:09 +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=1712245511; cv=none; b=V3BRYz9bFRwtG5++R7Y6jriqvw/WK9YXwzanh93ZlcSFLK7jkllWe+2n/JxUSCzno5OMV1Q1Kh5jFay5Q1ITNV0Og2yzwJVrRkmAP96t+HvS95xUqyz74RN860Xyg8xusXqRK5bGg8be1x2NAcWCn2dg91RbAhkBbHHo7RFOTNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245511; c=relaxed/simple; bh=g3w88NJvNIVVNbZvLx445agXw1wOt26dDzIYw21Eab0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MbRmBFgMzW5Sd0wqDbZBBryFFD17LCgAV2+G8gEO84FiQJAOAGe1i3y2gAMwq7Beyn1AOU6nelKAj98tFKoZcv6OGdalNfNLhcY0b54VKaf5kb2YZ2SNXWxUKCFmj96LtZMze9FVftfbLvNS+0inWKaeC5v6WIfELLaLyvEYbd0= 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=uRM6vYiy; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=/lpkBLAb; 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="uRM6vYiy"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="/lpkBLAb" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 E51E237BF4; Thu, 4 Apr 2024 15:45:07 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712245507; 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=TyZA3j85Z7pMInECy/q8xvo8tWrjUgChlPcQlRjOZI8=; b=uRM6vYiy8O5ipHZj3pAley1JHNq3/bTfHZzeUcvQFendSed27uPNnuNxGZNCYNiwjWr7s5 iCmBN+I4hZbe6fikW2BhvsXXkWw7xCjvzBqUuXviGHpf43T3oBtelFLhK70XHdHzRmJR/y WTV7rbdpFz5vJhvSIAYHPf99jvuj8jU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712245507; 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=TyZA3j85Z7pMInECy/q8xvo8tWrjUgChlPcQlRjOZI8=; b=/lpkBLAbYIlW9iVDx8gVCYKRi/RMaXLZQczePwsIJayUAi6nQvnHST30Ao//GinYbWSktM v7jf2ITy9Ujor0Dw== 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 D279513AA3; Thu, 4 Apr 2024 15:45:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id UrXyMQPLDmYGIgAAn2gu4w (envelope-from ); Thu, 04 Apr 2024 15:45:07 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Hannes Reinecke , Daniel Wagner Subject: [PATCH v4 2/5] nvmet: lock config semaphore when accessing DH-HMAC-CHAP key Date: Thu, 4 Apr 2024 17:44:57 +0200 Message-ID: <20240404154500.2101-3-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404154500.2101-1-dwagner@suse.de> References: <20240404154500.2101-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-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: E51E237BF4 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action Content-Type: text/plain; charset="utf-8" From: Hannes Reinecke When the DH-HMAC-CHAP key is accessed via configfs we need to take the config semaphore as a reconnect might be running at the same time. Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig --- drivers/nvme/target/auth.c | 2 ++ drivers/nvme/target/configfs.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index 3ddbc3880cac..9afc28f1ffac 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -44,6 +44,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const cha= r *secret, dhchap_secret =3D kstrdup(secret, GFP_KERNEL); if (!dhchap_secret) return -ENOMEM; + down_write(&nvmet_config_sem); if (set_ctrl) { kfree(host->dhchap_ctrl_secret); host->dhchap_ctrl_secret =3D strim(dhchap_secret); @@ -53,6 +54,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const cha= r *secret, host->dhchap_secret =3D strim(dhchap_secret); host->dhchap_key_hash =3D key_hash; } + up_write(&nvmet_config_sem); return 0; } =20 diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 77a6e817b315..7c28b9c0ee57 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -1990,11 +1990,17 @@ static struct config_group nvmet_ports_group; static ssize_t nvmet_host_dhchap_key_show(struct config_item *item, char *page) { - u8 *dhchap_secret =3D to_host(item)->dhchap_secret; + u8 *dhchap_secret; + ssize_t ret; =20 + down_read(&nvmet_config_sem); + dhchap_secret =3D to_host(item)->dhchap_secret; if (!dhchap_secret) - return sprintf(page, "\n"); - return sprintf(page, "%s\n", dhchap_secret); + ret =3D sprintf(page, "\n"); + else + ret =3D sprintf(page, "%s\n", dhchap_secret); + up_read(&nvmet_config_sem); + return ret; } =20 static ssize_t nvmet_host_dhchap_key_store(struct config_item *item, @@ -2018,10 +2024,16 @@ static ssize_t nvmet_host_dhchap_ctrl_key_show(stru= ct config_item *item, char *page) { u8 *dhchap_secret =3D to_host(item)->dhchap_ctrl_secret; + ssize_t ret; =20 + down_read(&nvmet_config_sem); + dhchap_secret =3D to_host(item)->dhchap_ctrl_secret; if (!dhchap_secret) - return sprintf(page, "\n"); - return sprintf(page, "%s\n", dhchap_secret); + ret =3D sprintf(page, "\n"); + else + ret =3D sprintf(page, "%s\n", dhchap_secret); + up_read(&nvmet_config_sem); + return ret; } =20 static ssize_t nvmet_host_dhchap_ctrl_key_store(struct config_item *item, --=20 2.44.0 From nobody Mon Feb 9 18:59:52 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 41404763F4 for ; Thu, 4 Apr 2024 15:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245511; cv=none; b=SSnF4NV0QZI/KbQA9OZ/44qi4UKnnqK+r4QsVXcJl4UT6XvBQY2OVe2Pc40mptYZFjdHuxnHh5uAcRgklT/LV5ub5qi504nse0YQ0Ckh0+xhmkvT1bzxbeNF46WoW2bARag6z3xF5jHKv1ms/KMijzCDJY7J3yJkcNsn9f2rZIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245511; c=relaxed/simple; bh=VxQDniNp1GvFx1AJkcj8trNLxPPYXZuO3OK1Fi/n0Bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZZl72Q3/hQYWriBLLrf13m1iRwACkgD/HGbOEJnUNIZnw/gMOJz9aO4bYXJEiWtZZa2KKP6MuHcAZ71UMZhTzcG+ivj7gdsvDkA9w1M1Md1ZM1z4EGHFp+D6yoy1NvWAKlrOfUB/m91RNTNfdGxx837PyRYkJb2yo8ojjm/IfdY= 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=Zx72GqoI; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=CP5iOcvm; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Zx72GqoI; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=CP5iOcvm; arc=none smtp.client-ip=195.135.223.131 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="Zx72GqoI"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="CP5iOcvm"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Zx72GqoI"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="CP5iOcvm" 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-out2.suse.de (Postfix) with ESMTPS id 8569C5F8A4; Thu, 4 Apr 2024 15:45:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712245508; 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=cWs/Gd1Hr0vOWvB9JrSbgOUDhqUyFVhZ4d5LzP32gcM=; b=Zx72GqoIytVZqcaQrKq1pYaU9wbEskpQkK//ZxEs3m0UWaXugZH+Ia4RAqOIZrScvdLepg PaekupjrsxvDYi05r4dAh9j5SNHYJRNxdQ49QwREnxK9heReJ3EatAGVdcIeCJxtjsJUgH OYiBdMDUXpgK10jKJ3w4C8HbqNB0Ky0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712245508; 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=cWs/Gd1Hr0vOWvB9JrSbgOUDhqUyFVhZ4d5LzP32gcM=; b=CP5iOcvm3JjmeYcj7rXD6n9Kmmp0gBDg2/3KMP8peFHGD9TXoB/KdUefoVNhlkq6Cm8zKs agJMB3gfuZuM36AA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712245508; 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=cWs/Gd1Hr0vOWvB9JrSbgOUDhqUyFVhZ4d5LzP32gcM=; b=Zx72GqoIytVZqcaQrKq1pYaU9wbEskpQkK//ZxEs3m0UWaXugZH+Ia4RAqOIZrScvdLepg PaekupjrsxvDYi05r4dAh9j5SNHYJRNxdQ49QwREnxK9heReJ3EatAGVdcIeCJxtjsJUgH OYiBdMDUXpgK10jKJ3w4C8HbqNB0Ky0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712245508; 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=cWs/Gd1Hr0vOWvB9JrSbgOUDhqUyFVhZ4d5LzP32gcM=; b=CP5iOcvm3JjmeYcj7rXD6n9Kmmp0gBDg2/3KMP8peFHGD9TXoB/KdUefoVNhlkq6Cm8zKs agJMB3gfuZuM36AA== 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 73CFE139E8; Thu, 4 Apr 2024 15:45:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id OljVGgTLDmYIIgAAn2gu4w (envelope-from ); Thu, 04 Apr 2024 15:45:08 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Hannes Reinecke , Daniel Wagner Subject: [PATCH v4 3/5] nvmet: return DHCHAP status codes from nvmet_setup_auth() Date: Thu, 4 Apr 2024 17:44:58 +0200 Message-ID: <20240404154500.2101-4-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404154500.2101-1-dwagner@suse.de> References: <20240404154500.2101-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)[9]; 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,suse.de:email]; 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 A failure in nvmet_setup_auth() does not mean that the NVMe authentication command failed, so we should rather return a protocol error with a 'failure1' response than an NVMe status. Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/target/auth.c | 18 +++++++----------- drivers/nvme/target/fabrics-cmd-auth.c | 11 ++++++----- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index 9afc28f1ffac..1079281a202e 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -131,7 +131,6 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) int ret =3D 0; struct nvmet_host_link *p; struct nvmet_host *host =3D NULL; - const char *hash_name; =20 down_read(&nvmet_config_sem); if (nvmet_is_disc_subsys(ctrl->subsys)) @@ -149,13 +148,16 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) } if (!host) { pr_debug("host %s not found\n", ctrl->hostnqn); - ret =3D -EPERM; + ret =3D NVME_AUTH_DHCHAP_FAILURE_FAILED; goto out_unlock; } =20 ret =3D nvmet_setup_dhgroup(ctrl, host->dhchap_dhgroup_id); - if (ret < 0) + if (ret < 0) { pr_warn("Failed to setup DH group"); + ret =3D NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE; + goto out_unlock; + } =20 if (!host->dhchap_secret) { pr_debug("No authentication provided\n"); @@ -166,12 +168,6 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) pr_debug("Re-use existing hash ID %d\n", ctrl->shash_id); } else { - hash_name =3D nvme_auth_hmac_name(host->dhchap_hash_id); - if (!hash_name) { - pr_warn("Hash ID %d invalid\n", host->dhchap_hash_id); - ret =3D -EINVAL; - goto out_unlock; - } ctrl->shash_id =3D host->dhchap_hash_id; } =20 @@ -180,7 +176,7 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) ctrl->host_key =3D nvme_auth_extract_key(host->dhchap_secret + 10, host->dhchap_key_hash); if (IS_ERR(ctrl->host_key)) { - ret =3D PTR_ERR(ctrl->host_key); + ret =3D NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; ctrl->host_key =3D NULL; goto out_free_hash; } @@ -198,7 +194,7 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) ctrl->ctrl_key =3D nvme_auth_extract_key(host->dhchap_ctrl_secret + 10, host->dhchap_ctrl_key_hash); if (IS_ERR(ctrl->ctrl_key)) { - ret =3D PTR_ERR(ctrl->ctrl_key); + ret =3D NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE; ctrl->ctrl_key =3D NULL; goto out_free_hash; } diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/f= abrics-cmd-auth.c index eb7785be0ca7..a95dc6606396 100644 --- a/drivers/nvme/target/fabrics-cmd-auth.c +++ b/drivers/nvme/target/fabrics-cmd-auth.c @@ -240,12 +240,13 @@ void nvmet_execute_auth_send(struct nvmet_req *req) pr_debug("%s: ctrl %d qid %d reset negotiation\n", __func__, ctrl->cntlid, req->sq->qid); if (!req->sq->qid) { - if (nvmet_setup_auth(ctrl) < 0) { - status =3D NVME_SC_INTERNAL; - pr_err("ctrl %d qid 0 failed to setup" - "re-authentication", + status =3D nvmet_setup_auth(ctrl); + if (status) { + pr_err("ctrl %d qid 0 failed to setup re-authentication\n", ctrl->cntlid); - goto done_failure1; + req->sq->dhchap_status =3D status; + req->sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_FAILURE1; + goto done_kfree; } } req->sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE; --=20 2.44.0 From nobody Mon Feb 9 18:59:52 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 CDD3A129E7C for ; Thu, 4 Apr 2024 15:45:10 +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=1712245512; cv=none; b=m5wJIOl3fEDtQ8p4oYY+LvQW+TlRgmDTEvHNVfoRwIALLltGCQywDPaRK2dwEvOzcieqnFMY2FQbtOVQ0q8DFHniE2dBS4SfadSEXNxJGNSNVzrRd5k3uTMhjgNSGRL4dNZ1PT+tj9kcxABIOVk8m7ePzKKaRvfUYjPJ+ghTTK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245512; c=relaxed/simple; bh=lM7wFrltAB0q00VSvTFLfrMBVNppZ+T0rgs5C2HFTaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AFy4y7fxjT95w9fojJjy8J4MPfXc9fFHBSsT4D/OdUUiXquV0KqP+7ync0j6RNSciwyGvpyrUIC5re+1nKrgaHZV5yKUbEjnOfHSQIVMFSeMjtE3YZm8MSRaVAkx2eAD/yz2Qc/ktAr0RDxmcKaNJ9pQ9TF0ZPRS6GSduPYVpb8= 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; 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 Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 2F2FD37CFF; Thu, 4 Apr 2024 15:45:09 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 1DE1D139E8; Thu, 4 Apr 2024 15:45:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id HZrYBQXLDmYOIgAAn2gu4w (envelope-from ); Thu, 04 Apr 2024 15:45:09 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Chaitanya Kulkarni , Daniel Wagner Subject: [PATCH v4 4/5] nvme-tcp: short-circuit reconnect retries Date: Thu, 4 Apr 2024 17:44:59 +0200 Message-ID: <20240404154500.2101-5-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404154500.2101-1-dwagner@suse.de> References: <20240404154500.2101-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-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 2F2FD37CFF 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. Reviewed-by: Chaitanya Kulkarni Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/host/nvme.h | 17 +++++++++++++++++ drivers/nvme/host/tcp.c | 23 +++++++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 882967365108..654d8d1a4d29 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -701,6 +701,23 @@ 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. + * 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) +{ + return status > 0 && (status & NVME_SC_DNR) ? false : 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 From nobody Mon Feb 9 18:59:52 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 7AB8812A166 for ; Thu, 4 Apr 2024 15:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245513; cv=none; b=pt4UDPtCE1Ew/aarz6Zl7zYnxBdVgwxD9xCEn71thgYz7v50T5YDIRFz0A9hm/KWmNHlh2LAM/q4DgOZmXylYYz2sJ5QWDe7J8sj4WdVGbxEEcuYZOpnhiJg2kWvsLGPw0/xLy8GVg8MX0OnJHox/5LXrJIYvYrHrsrud7CtTZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245513; c=relaxed/simple; bh=bJ5pd2ekVYicgouR8tepckM5I31aQ3YWMNK/Ke19O34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BeXbh5ow8WiLgekIiRqJ/t5u3WzZ4rvT/+CVvsclrkpJhOoqQcnfRAWelHsuxXEKuxG9jy7cExpMPsQ7X6Gme2A2NpDA0NSx5p1t229K3t7BnrPT/+3sit0BLArLmK1ryjIp1QTyTkzjb0vbVx+2Psh8nUOy59myhgftzHZPeFU= 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; arc=none smtp.client-ip=195.135.223.131 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 Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id CECEF5F8A8; Thu, 4 Apr 2024 15:45:09 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 B2450139E8; Thu, 4 Apr 2024 15:45:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id FbK+KgXLDmYQIgAAn2gu4w (envelope-from ); Thu, 04 Apr 2024 15:45:09 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Chaitanya Kulkarni , Daniel Wagner Subject: [PATCH v4 5/5] nvme-rdma: short-circuit reconnect retries Date: Thu, 4 Apr 2024 17:45:00 +0200 Message-ID: <20240404154500.2101-6-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404154500.2101-1-dwagner@suse.de> References: <20240404154500.2101-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-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: CECEF5F8A8 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action Content-Type: text/plain; charset="utf-8" From: Hannes Reinecke Returning an nvme status from nvme_rdma_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. Reviewed-by: Chaitanya Kulkarni Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/host/rdma.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 366f0bb4ebfc..53d51df26ae1 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -982,9 +982,11 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctr= l) kfree(ctrl); } =20 -static void nvme_rdma_reconnect_or_remove(struct nvme_rdma_ctrl *ctrl) +static void nvme_rdma_reconnect_or_remove(struct nvme_rdma_ctrl *ctrl, + int status) { enum nvme_ctrl_state state =3D nvme_ctrl_state(&ctrl->ctrl); + bool recon =3D nvme_ctrl_reconnect(status); =20 /* If we are resetting/deleting then do nothing */ if (state !=3D NVME_CTRL_CONNECTING) { @@ -992,12 +994,14 @@ static void nvme_rdma_reconnect_or_remove(struct nvme= _rdma_ctrl *ctrl) return; } =20 - if (nvmf_should_reconnect(&ctrl->ctrl)) { + if (recon && nvmf_should_reconnect(&ctrl->ctrl)) { dev_info(ctrl->ctrl.device, "Reconnecting in %d seconds...\n", ctrl->ctrl.opts->reconnect_delay); queue_delayed_work(nvme_wq, &ctrl->reconnect_work, ctrl->ctrl.opts->reconnect_delay * HZ); } else { + dev_info(ctrl->ctrl.device, "Removing controller (%d)...\n", + status); nvme_delete_ctrl(&ctrl->ctrl); } } @@ -1104,10 +1108,12 @@ static void nvme_rdma_reconnect_ctrl_work(struct wo= rk_struct *work) { struct nvme_rdma_ctrl *ctrl =3D container_of(to_delayed_work(work), struct nvme_rdma_ctrl, reconnect_work); + int ret; =20 ++ctrl->ctrl.nr_reconnects; =20 - if (nvme_rdma_setup_ctrl(ctrl, false)) + ret =3D nvme_rdma_setup_ctrl(ctrl, false); + if (ret) goto requeue; =20 dev_info(ctrl->ctrl.device, "Successfully reconnected (%d attempts)\n", @@ -1120,7 +1126,7 @@ static void nvme_rdma_reconnect_ctrl_work(struct work= _struct *work) requeue: dev_info(ctrl->ctrl.device, "Failed reconnect attempt %d\n", ctrl->ctrl.nr_reconnects); - nvme_rdma_reconnect_or_remove(ctrl); + nvme_rdma_reconnect_or_remove(ctrl, ret); } =20 static void nvme_rdma_error_recovery_work(struct work_struct *work) @@ -1145,7 +1151,7 @@ static void nvme_rdma_error_recovery_work(struct work= _struct *work) return; } =20 - nvme_rdma_reconnect_or_remove(ctrl); + nvme_rdma_reconnect_or_remove(ctrl, -ENOTCONN); } =20 static void nvme_rdma_error_recovery(struct nvme_rdma_ctrl *ctrl) @@ -2169,6 +2175,7 @@ static void nvme_rdma_reset_ctrl_work(struct work_str= uct *work) { struct nvme_rdma_ctrl *ctrl =3D container_of(work, struct nvme_rdma_ctrl, ctrl.reset_work); + int ret; =20 nvme_stop_ctrl(&ctrl->ctrl); nvme_rdma_shutdown_ctrl(ctrl, false); @@ -2179,14 +2186,15 @@ static void nvme_rdma_reset_ctrl_work(struct work_s= truct *work) return; } =20 - if (nvme_rdma_setup_ctrl(ctrl, false)) + ret =3D nvme_rdma_setup_ctrl(ctrl, false); + if (ret) goto out_fail; =20 return; =20 out_fail: ++ctrl->ctrl.nr_reconnects; - nvme_rdma_reconnect_or_remove(ctrl); + nvme_rdma_reconnect_or_remove(ctrl, ret); } =20 static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops =3D { --=20 2.44.0