From nobody Sun Feb 8 00:28:07 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 E996F171664 for ; Tue, 30 Apr 2024 13:19:37 +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=1714483179; cv=none; b=JCZse+BEQ6NAi+pcRr3q++mYiLA08DrMHvIi/1abgBqzBam/fsUchmAFATyNJhjCdMZUWQJeV6YEu1nIxrM5k7ZPbdX3SJBFUlBO2lqjKjlaY2jn1vna2wZqJRWH6vh1c3M4dXE4FAIZSxQcxyVwEcKdIWKC4Yu1Gvz8XcGmeaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714483179; c=relaxed/simple; bh=2pEw6VivEu28Mo3DUny6NNh9kyZmW0ocFsTrPvhuHtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ckID+RUToA8ksm4KPbbjUby3PqwV8irFG/dUDSuulOfiZB2uJkJGTSzQL4xnufKpSaAZwunfagYLLAL36NPrjyn0JQcq5u04D9AdyOcku1rLdjX0jvNOw0a4EmxwVQcqCZxxiITHsgCcCf2tYwNzjQ9VJrqiAXhg4GreyPZE8vE= 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=HBwqzsO2; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IDvklSiT; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=HBwqzsO2; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IDvklSiT; 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="HBwqzsO2"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IDvklSiT"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="HBwqzsO2"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IDvklSiT" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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 193313406B; Tue, 30 Apr 2024 13:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=HBwqzsO2tvy7femgoknMrDBC+32vIVXELC0BJG9CmIEtwFhTm8JzQmmHYrEd1rgC47av4u ykss4v37J5MoT3DnO8iGLvP+Qw6rnveED52FaB8RG4bcId+NPZL1NqbmwnPJi/e5xsQM0U UpebAyhHHChvA64p8oYKhVfnd9p4voc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=IDvklSiTmCd/cD2cNhR+fqaN0Zl+MF2LrqFiZIldbf8zqhV6kCSbF9/FwH1XjsrcSGTq1N jdBiEM6mQKEhqCDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=HBwqzsO2tvy7femgoknMrDBC+32vIVXELC0BJG9CmIEtwFhTm8JzQmmHYrEd1rgC47av4u ykss4v37J5MoT3DnO8iGLvP+Qw6rnveED52FaB8RG4bcId+NPZL1NqbmwnPJi/e5xsQM0U UpebAyhHHChvA64p8oYKhVfnd9p4voc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=IDvklSiTmCd/cD2cNhR+fqaN0Zl+MF2LrqFiZIldbf8zqhV6kCSbF9/FwH1XjsrcSGTq1N jdBiEM6mQKEhqCDQ== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 073CC133A7; Tue, 30 Apr 2024 13:19:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id urFMAOjvMGZwMAAAD6G6ig (envelope-from ); Tue, 30 Apr 2024 13:19:36 +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, Hannes Reinecke , Daniel Wagner Subject: [PATCH v7 1/5] nvmet: lock config semaphore when accessing DH-HMAC-CHAP key Date: Tue, 30 Apr 2024 15:19:24 +0200 Message-ID: <20240430131928.29766-2-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430131928.29766-1-dwagner@suse.de> References: <20240430131928.29766-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 [-2.80 / 50.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)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO 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. Reviewed-by: Sagi Grimberg Reviewed-by: Christoph Hellwig Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- 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 Sun Feb 8 00:28:07 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 94E49171E5F for ; Tue, 30 Apr 2024 13:19:38 +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=1714483180; cv=none; b=MluF4nY7UI23lnOg7imuGWCrA63olE+P5laW2DAx1zrsLKWuCRSMdeGiMGPyBs1ddx2TfcizaRwsV0tAx5ZhPS+IuLyA6bCbSgVr1RG/UvTXKvoAJAbIEEF1+e+mEQbzJ+9QQlfelRGonbdv8vsvbB/011+m4f4ry/yUSvXhWPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714483180; c=relaxed/simple; bh=nnJzm8T74bjJ2sBzbnniv95zAmpWRjbeC6PVsOH9sNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n/pVS/Ja1/HYYVXw1/u9biGUTQCmiPCBG9P71fTNykSRJfWsuh8CtqR5WEzCrsmY7RTOcayPQ8X9xJIfMkva0DLbmQKeOo5Uzf/NocGNaFQm2PET8qX3wOqEKMOiheP1G5WVkySa9blfEZrko+WbUX+fXlEnnXUmoJmakCv1QW0= 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=ow52n/2o; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tZ9xmj9T; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ow52n/2o; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tZ9xmj9T; 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="ow52n/2o"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tZ9xmj9T"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ow52n/2o"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tZ9xmj9T" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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 C6BED34067; Tue, 30 Apr 2024 13:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483176; 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=Egnbg/DT6A5u2Qw0Nt3LBJd28TckgI7kfiP2XhNJy5g=; b=ow52n/2oFtu02yz2vRtJnSihMASyHM9UIMzcy1kN6PtHx9Yqnq2eOl77vmm6Bx9Pfdmg/b a0bsbU65IysmiMiPKdx2GJDx/gxrU1d0kLNtDyrAHvCyn1zdMqXlq9DQUpUTIdqEm3ME0O FQ/H3qz8SB0PdEJZh+eVsLjMrE85Ve4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483176; 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=Egnbg/DT6A5u2Qw0Nt3LBJd28TckgI7kfiP2XhNJy5g=; b=tZ9xmj9TECWwTe8+WDIr1DvQdkOz8v8o4e/dlGmRQtZJjPPEcLtx1zHIJMl2EIme2WjwCY ttHLMY6AEEk24kCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483176; 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=Egnbg/DT6A5u2Qw0Nt3LBJd28TckgI7kfiP2XhNJy5g=; b=ow52n/2oFtu02yz2vRtJnSihMASyHM9UIMzcy1kN6PtHx9Yqnq2eOl77vmm6Bx9Pfdmg/b a0bsbU65IysmiMiPKdx2GJDx/gxrU1d0kLNtDyrAHvCyn1zdMqXlq9DQUpUTIdqEm3ME0O FQ/H3qz8SB0PdEJZh+eVsLjMrE85Ve4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483176; 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=Egnbg/DT6A5u2Qw0Nt3LBJd28TckgI7kfiP2XhNJy5g=; b=tZ9xmj9TECWwTe8+WDIr1DvQdkOz8v8o4e/dlGmRQtZJjPPEcLtx1zHIJMl2EIme2WjwCY ttHLMY6AEEk24kCg== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B53EB133A7; Tue, 30 Apr 2024 13:19:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id jqfBKujvMGZzMAAAD6G6ig (envelope-from ); Tue, 30 Apr 2024 13:19:36 +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, Hannes Reinecke , Daniel Wagner Subject: [PATCH v7 2/5] nvmet: return DHCHAP status codes from nvmet_setup_auth() Date: Tue, 30 Apr 2024 15:19:25 +0200 Message-ID: <20240430131928.29766-3-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430131928.29766-1-dwagner@suse.de> References: <20240430131928.29766-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: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.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]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email] 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. Also update the type used for dhchap_step and dhchap_status to u8 to avoid confusions with nvme status. Furthermore, split dhchap_status and nvme status so we don't accidentally mix these return values. Reviewed-by: Christoph Hellwig Signed-off-by: Hannes Reinecke [dwagner: - use u8 as type for dhchap_{step|status} - separate nvme status from dhcap_status] Signed-off-by: Daniel Wagner --- drivers/nvme/target/auth.c | 20 +++++------ drivers/nvme/target/fabrics-cmd-auth.c | 49 +++++++++++++------------- drivers/nvme/target/fabrics-cmd.c | 11 +++--- drivers/nvme/target/nvmet.h | 8 ++--- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index 9afc28f1ffac..53bf1a084469 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -126,12 +126,11 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 d= hgroup_id) return ret; } =20 -int nvmet_setup_auth(struct nvmet_ctrl *ctrl) +u8 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 ee76491e8b12..cb34d644ed08 100644 --- a/drivers/nvme/target/fabrics-cmd-auth.c +++ b/drivers/nvme/target/fabrics-cmd-auth.c @@ -31,7 +31,7 @@ void nvmet_auth_sq_init(struct nvmet_sq *sq) sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE; } =20 -static u16 nvmet_auth_negotiate(struct nvmet_req *req, void *d) +static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d) { struct nvmet_ctrl *ctrl =3D req->sq->ctrl; struct nvmf_auth_dhchap_negotiate_data *data =3D d; @@ -109,7 +109,7 @@ static u16 nvmet_auth_negotiate(struct nvmet_req *req, = void *d) return 0; } =20 -static u16 nvmet_auth_reply(struct nvmet_req *req, void *d) +static u8 nvmet_auth_reply(struct nvmet_req *req, void *d) { struct nvmet_ctrl *ctrl =3D req->sq->ctrl; struct nvmf_auth_dhchap_reply_data *data =3D d; @@ -172,7 +172,7 @@ static u16 nvmet_auth_reply(struct nvmet_req *req, void= *d) return 0; } =20 -static u16 nvmet_auth_failure2(void *d) +static u8 nvmet_auth_failure2(void *d) { struct nvmf_auth_dhchap_failure_data *data =3D d; =20 @@ -186,6 +186,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req) void *d; u32 tl; u16 status =3D 0; + u8 dhchap_status; =20 if (req->cmd->auth_send.secp !=3D NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER) { status =3D NVME_SC_INVALID_FIELD | NVME_SC_DNR; @@ -237,30 +238,32 @@ void nvmet_execute_auth_send(struct nvmet_req *req) if (data->auth_type =3D=3D NVME_AUTH_COMMON_MESSAGES) { if (data->auth_id =3D=3D NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE) { /* Restart negotiation */ - pr_debug("%s: ctrl %d qid %d reset negotiation\n", __func__, - ctrl->cntlid, req->sq->qid); + 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", + dhchap_status =3D nvmet_setup_auth(ctrl); + if (dhchap_status) { + pr_err("ctrl %d qid 0 failed to setup re-authentication\n", ctrl->cntlid); - goto done_failure1; + req->sq->dhchap_status =3D dhchap_status; + req->sq->dhchap_step =3D + NVME_AUTH_DHCHAP_MESSAGE_FAILURE1; + goto done_kfree; } } - req->sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE; + req->sq->dhchap_step =3D + NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE; } else if (data->auth_id !=3D req->sq->dhchap_step) goto done_failure1; /* Validate negotiation parameters */ - status =3D nvmet_auth_negotiate(req, d); - if (status =3D=3D 0) + dhchap_status =3D nvmet_auth_negotiate(req, d); + if (dhchap_status =3D=3D 0) req->sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE; else { req->sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_FAILURE1; - req->sq->dhchap_status =3D status; - status =3D 0; + req->sq->dhchap_status =3D dhchap_status; } goto done_kfree; } @@ -284,15 +287,14 @@ void nvmet_execute_auth_send(struct nvmet_req *req) =20 switch (data->auth_id) { case NVME_AUTH_DHCHAP_MESSAGE_REPLY: - status =3D nvmet_auth_reply(req, d); - if (status =3D=3D 0) + dhchap_status =3D nvmet_auth_reply(req, d); + if (dhchap_status =3D=3D 0) req->sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1; else { req->sq->dhchap_step =3D NVME_AUTH_DHCHAP_MESSAGE_FAILURE1; - req->sq->dhchap_status =3D status; - status =3D 0; + req->sq->dhchap_status =3D dhchap_status; } goto done_kfree; case NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2: @@ -301,13 +303,12 @@ void nvmet_execute_auth_send(struct nvmet_req *req) __func__, ctrl->cntlid, req->sq->qid); goto done_kfree; case NVME_AUTH_DHCHAP_MESSAGE_FAILURE2: - status =3D nvmet_auth_failure2(d); - if (status) { + dhchap_status =3D nvmet_auth_failure2(d); + if (dhchap_status) { pr_warn("ctrl %d qid %d: authentication failed (%d)\n", - ctrl->cntlid, req->sq->qid, status); - req->sq->dhchap_status =3D status; + ctrl->cntlid, req->sq->qid, dhchap_status); + req->sq->dhchap_status =3D dhchap_status; req->sq->authenticated =3D false; - status =3D 0; } goto done_kfree; default: diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabric= s-cmd.c index f6714453b8bb..69d77d34bec1 100644 --- a/drivers/nvme/target/fabrics-cmd.c +++ b/drivers/nvme/target/fabrics-cmd.c @@ -211,7 +211,7 @@ static void nvmet_execute_admin_connect(struct nvmet_re= q *req) struct nvmf_connect_data *d; struct nvmet_ctrl *ctrl =3D NULL; u16 status; - int ret; + u8 dhchap_status; =20 if (!nvmet_check_transfer_len(req, sizeof(struct nvmf_connect_data))) return; @@ -251,11 +251,12 @@ static void nvmet_execute_admin_connect(struct nvmet_= req *req) =20 uuid_copy(&ctrl->hostid, &d->hostid); =20 - ret =3D nvmet_setup_auth(ctrl); - if (ret < 0) { - pr_err("Failed to setup authentication, error %d\n", ret); + dhchap_status =3D nvmet_setup_auth(ctrl); + if (dhchap_status) { + pr_err("Failed to setup authentication, dhchap status %u\n", + dhchap_status); nvmet_ctrl_put(ctrl); - if (ret =3D=3D -EPERM) + if (dhchap_status =3D=3D NVME_AUTH_DHCHAP_FAILURE_FAILED) status =3D (NVME_SC_CONNECT_INVALID_HOST | NVME_SC_DNR); else status =3D NVME_SC_INTERNAL; diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 257cace53924..5d6adb5c2fc0 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -113,8 +113,8 @@ struct nvmet_sq { bool authenticated; struct delayed_work auth_expired_work; u16 dhchap_tid; - u16 dhchap_status; - int dhchap_step; + u8 dhchap_status; + u8 dhchap_step; u8 *dhchap_c1; u8 *dhchap_c2; u32 dhchap_s1; @@ -721,7 +721,7 @@ void nvmet_execute_auth_receive(struct nvmet_req *req); int nvmet_auth_set_key(struct nvmet_host *host, const char *secret, bool set_ctrl); int nvmet_auth_set_host_hash(struct nvmet_host *host, const char *hash); -int nvmet_setup_auth(struct nvmet_ctrl *ctrl); +u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl); void nvmet_auth_sq_init(struct nvmet_sq *sq); void nvmet_destroy_auth(struct nvmet_ctrl *ctrl); void nvmet_auth_sq_free(struct nvmet_sq *sq); @@ -740,7 +740,7 @@ int nvmet_auth_ctrl_exponential(struct nvmet_req *req, int nvmet_auth_ctrl_sesskey(struct nvmet_req *req, u8 *buf, int buf_size); #else -static inline int nvmet_setup_auth(struct nvmet_ctrl *ctrl) +static inline u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl) { return 0; } --=20 2.44.0 From nobody Sun Feb 8 00:28:07 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 5CACC171E67 for ; Tue, 30 Apr 2024 13:19:39 +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=1714483180; cv=none; b=Yh3ySKEXRKeuewivtZkiXpKvfNgLpdTQYxNfXGqaDq6OXYjXWHUKCJ9xZk7IvRiw/9RlHlr+rTtM+W0O4mLuQ0eNBVQcTWAptEer0raaO0nj7M9m2GKVHSKvxdeY2eq+EwiWi3VNBSE4hfim1uyTPyS6fsSV5uT7i3fBIsBQaQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714483180; c=relaxed/simple; bh=BK3COps9RWbDbzAXm6b9is1mXXB7VVBI1k12WaLmR9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ky+o7YZmu5bZz5mjai9xeWpTv3tT87WWvyVq34MKwPfsEFQ65TNdm9i9D3F1SZjE/o78XuIubTY9WikQrNciZUZW87b6XMZekyElhO063csNSS4Wt76Z4TBjpwtpI1o0YNKyqmUFkm3/nDnFvIoyVKizzFXyvWg7hu4MGlwD+pE= 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=ri79Gfyt; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Yp/18S0B; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ri79Gfyt; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Yp/18S0B; 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="ri79Gfyt"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Yp/18S0B"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ri79Gfyt"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Yp/18S0B" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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 8259E1F7E5; Tue, 30 Apr 2024 13:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483177; 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=IqmLcu21VKVleGdDKkyS5kWnZkHjeaB7QlqTWzxzX+Q=; b=ri79Gfyt2hjCszVM2HXT7m6dJtRVBDt7pz+7Xz3DIr3rvgd6RFzaYp5snlcAeSOus6a4SP +asZDdC+KPTH9jAEfxJG5WkuQ/UcnkPZTyaHivCw8+lxR5ZTDSlWJfa4HfnBB2grD6jLxR fWMsci6J+HPxjoJ2/poLD9EaI3ItfZ8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483177; 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=IqmLcu21VKVleGdDKkyS5kWnZkHjeaB7QlqTWzxzX+Q=; b=Yp/18S0BUq6vlyHbUavon5SWh59FIXkm6fJ2fa7uSuc3dHni+GVvbLgBmWWQZ4Dtq5frh/ FTYKNhgvLOTcprBg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483177; 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=IqmLcu21VKVleGdDKkyS5kWnZkHjeaB7QlqTWzxzX+Q=; b=ri79Gfyt2hjCszVM2HXT7m6dJtRVBDt7pz+7Xz3DIr3rvgd6RFzaYp5snlcAeSOus6a4SP +asZDdC+KPTH9jAEfxJG5WkuQ/UcnkPZTyaHivCw8+lxR5ZTDSlWJfa4HfnBB2grD6jLxR fWMsci6J+HPxjoJ2/poLD9EaI3ItfZ8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483177; 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=IqmLcu21VKVleGdDKkyS5kWnZkHjeaB7QlqTWzxzX+Q=; b=Yp/18S0BUq6vlyHbUavon5SWh59FIXkm6fJ2fa7uSuc3dHni+GVvbLgBmWWQZ4Dtq5frh/ FTYKNhgvLOTcprBg== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 70A95133A7; Tue, 30 Apr 2024 13:19:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id z1EMGunvMGZ1MAAAD6G6ig (envelope-from ); Tue, 30 Apr 2024 13:19:37 +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 v7 3/5] nvme: return kernel error codes for admin queue connect Date: Tue, 30 Apr 2024 15:19:26 +0200 Message-ID: <20240430131928.29766-4-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430131928.29766-1-dwagner@suse.de> References: <20240430131928.29766-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 [-2.80 / 50.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]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email] X-Spam-Score: -2.80 X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" From: Hannes Reinecke nvmf_connect_admin_queue returns NVMe error status codes and kernel error codes. This mixes the different domains which makes maintainability difficult. Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimberg Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/host/core.c | 6 +++--- drivers/nvme/host/fabrics.c | 31 +++++++++++++------------------ drivers/nvme/host/nvme.h | 2 +- 3 files changed, 17 insertions(+), 22 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..f7eaf9580b4f 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -428,12 +428,6 @@ static void nvmf_connect_cmd_prep(struct nvme_ctrl *ct= rl, u16 qid, * fabrics-protocol connection of the NVMe Admin queue between the * host system device and the allocated NVMe controller on the * target system via a NVMe Fabrics "Connect" command. - * - * Return: - * 0: success - * > 0: NVMe error status code - * < 0: Linux errno error code - * */ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) { @@ -467,7 +461,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 -EOPNOTSUPP; goto out_free_data; } /* Authentication required */ @@ -475,14 +469,14 @@ 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; 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); + } else dev_info(ctrl->device, "qid 0: authenticated\n"); } @@ -542,7 +536,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 -EOPNOTSUPP; goto out_free_data; } /* Authentication required */ @@ -550,12 +544,13 @@ 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); + 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); } } out_free_data: diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index d0ed64dc7380..9b8904a476b8 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 -EPROTONOSUPPORT; } static inline void nvme_auth_free(struct nvme_ctrl *ctrl) {}; #endif --=20 2.44.0 From nobody Sun Feb 8 00:28:07 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 ED43B171E7F for ; Tue, 30 Apr 2024 13:19:39 +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=1714483181; cv=none; b=T6SNQpYs5X+Yd+r0Sqh18MUqEGQyI3YqayNeRKSO6F06QjYmHydwGuYuIfWvbgaO/iYQNm1VF7qiRPaGY4+SiJohLnF66ERwBACOk93fWP4cwGIFNf0fo64R7GkqKEAX39AWplKE/zG/uP7v+Dv+KvqSA6idwt/F6nQxp1UpSqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714483181; c=relaxed/simple; bh=lS7wUqdc0VdIs9OvvUYxXJpNZuU+GdXvqqQEbOZ+6HI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ESdeKL/wEoAG7TnlVjkagloDctmPutC0+7/OHgRac5HICZ8qIr1EOI6eyjayDhvwwM2KhOh50Uiz/lBuBUfGjIDQttqMfBpahRIicSreusMTyhXhG7ybXfFGovWEyLOjbRes0wvgstR/VkeWNQdVz81XtsNanZospVlVFSu49cA= 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=uHODIbNc; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=f9be0gWD; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=uHODIbNc; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=f9be0gWD; 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="uHODIbNc"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="f9be0gWD"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="uHODIbNc"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="f9be0gWD" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 398D41F7E7; Tue, 30 Apr 2024 13:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483178; 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=cYsmsTTRr0wN/+5f5fuIh8FMdmRxcT7Afz3setUoM2s=; b=uHODIbNcJXuVyuxNXawudk3JJ59yo8h2edon2YFFlVjA/Fi03OtL+3FOLZNIi9o29gaJvO 9oGaUol4SR42+RJZG1Rqsr9qoe9Ckhy06zdhvW+Kk404Va4c439d2Gi6TL3K8eaPP/ShLm XlMWZwxYurwcjBnkEKMs/Sv99ztOn90= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483178; 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=cYsmsTTRr0wN/+5f5fuIh8FMdmRxcT7Afz3setUoM2s=; b=f9be0gWDoXkYo8tZsyNNLEDRWVgH7PFZJ1kg1PE17MCgPrVn0/X35748XG0Cl9lJwJFUGs EhZnbXpFhRZsewDg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=uHODIbNc; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=f9be0gWD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483178; 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=cYsmsTTRr0wN/+5f5fuIh8FMdmRxcT7Afz3setUoM2s=; b=uHODIbNcJXuVyuxNXawudk3JJ59yo8h2edon2YFFlVjA/Fi03OtL+3FOLZNIi9o29gaJvO 9oGaUol4SR42+RJZG1Rqsr9qoe9Ckhy06zdhvW+Kk404Va4c439d2Gi6TL3K8eaPP/ShLm XlMWZwxYurwcjBnkEKMs/Sv99ztOn90= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483178; 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=cYsmsTTRr0wN/+5f5fuIh8FMdmRxcT7Afz3setUoM2s=; b=f9be0gWDoXkYo8tZsyNNLEDRWVgH7PFZJ1kg1PE17MCgPrVn0/X35748XG0Cl9lJwJFUGs EhZnbXpFhRZsewDg== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 28517133A7; Tue, 30 Apr 2024 13:19:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6zJnCOrvMGZ5MAAAD6G6ig (envelope-from ); Tue, 30 Apr 2024 13:19:38 +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 v7 4/5] nvme-fabrics: short-circuit reconnect retries Date: Tue, 30 Apr 2024 15:19:27 +0200 Message-ID: <20240430131928.29766-5-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430131928.29766-1-dwagner@suse.de> References: <20240430131928.29766-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 [-5.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received,2a07:de40:b281:104:10:150:64:97:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:email] X-Rspamd-Action: no action X-Rspamd-Queue-Id: 398D41F7E7 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Score: -5.01 Content-Type: text/plain; charset="utf-8" From: Hannes Reinecke Returning a 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: - extended nvme_should_reconnect] Signed-off-by: Daniel Wagner --- drivers/nvme/host/fabrics.c | 14 +++++++++++++- drivers/nvme/host/fabrics.h | 2 +- drivers/nvme/host/fc.c | 4 +--- drivers/nvme/host/rdma.c | 19 ++++++++++++------- drivers/nvme/host/tcp.c | 22 ++++++++++++++-------- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index f7eaf9580b4f..36d3e2ff27f3 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -559,8 +559,20 @@ int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 = qid) } EXPORT_SYMBOL_GPL(nvmf_connect_io_queue); =20 -bool nvmf_should_reconnect(struct nvme_ctrl *ctrl) +/* + * Evaluate the status information returned by the transport in order to d= ecided + * if a reconnect attempt should be scheduled. + * + * Do not retry when: + * + * - the DNR bit is set and the specification states no further connect + * attempts with the same set of paramenters should be attempted. + */ +bool nvmf_should_reconnect(struct nvme_ctrl *ctrl, int status) { + if (status > 0 && (status & NVME_SC_DNR)) + return false; + if (ctrl->opts->max_reconnects =3D=3D -1 || ctrl->nr_reconnects < ctrl->opts->max_reconnects) return true; diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h index 37c974c38dcb..602135910ae9 100644 --- a/drivers/nvme/host/fabrics.h +++ b/drivers/nvme/host/fabrics.h @@ -223,7 +223,7 @@ int nvmf_register_transport(struct nvmf_transport_ops *= ops); void nvmf_unregister_transport(struct nvmf_transport_ops *ops); void nvmf_free_options(struct nvmf_ctrl_options *opts); int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size); -bool nvmf_should_reconnect(struct nvme_ctrl *ctrl); +bool nvmf_should_reconnect(struct nvme_ctrl *ctrl, int status); bool nvmf_ip_options_match(struct nvme_ctrl *ctrl, struct nvmf_ctrl_options *opts); void nvmf_set_io_queues(struct nvmf_ctrl_options *opts, u32 nr_io_queues, diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index a5b29e9ad342..f0b081332749 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -3310,12 +3310,10 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ct= rl, int status) dev_info(ctrl->ctrl.device, "NVME-FC{%d}: reset: Reconnect attempt failed (%d)\n", ctrl->cnum, status); - if (status > 0 && (status & NVME_SC_DNR)) - recon =3D false; } else if (time_after_eq(jiffies, rport->dev_loss_end)) recon =3D false; =20 - if (recon && nvmf_should_reconnect(&ctrl->ctrl)) { + if (recon && nvmf_should_reconnect(&ctrl->ctrl, status)) { if (portptr->port_state =3D=3D FC_OBJSTATE_ONLINE) dev_info(ctrl->ctrl.device, "NVME-FC{%d}: Reconnect attempt in %ld " diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 366f0bb4ebfc..821ab3e0fd3b 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -982,7 +982,8 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl) 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); =20 @@ -992,7 +993,7 @@ static void nvme_rdma_reconnect_or_remove(struct nvme_r= dma_ctrl *ctrl) return; } =20 - if (nvmf_should_reconnect(&ctrl->ctrl)) { + if (nvmf_should_reconnect(&ctrl->ctrl, status)) { dev_info(ctrl->ctrl.device, "Reconnecting in %d seconds...\n", ctrl->ctrl.opts->reconnect_delay); queue_delayed_work(nvme_wq, &ctrl->reconnect_work, @@ -1104,10 +1105,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 +1123,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 +1148,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, 0); } =20 static void nvme_rdma_error_recovery(struct nvme_rdma_ctrl *ctrl) @@ -2169,6 +2172,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 +2183,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 { diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index fdbcdcedcee9..3e0c33323320 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -2155,7 +2155,8 @@ static void nvme_tcp_teardown_io_queues(struct nvme_c= trl *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); =20 @@ -2165,13 +2166,14 @@ static void nvme_tcp_reconnect_or_remove(struct nvm= e_ctrl *ctrl) return; } =20 - if (nvmf_should_reconnect(ctrl)) { + if (nvmf_should_reconnect(ctrl, status)) { 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 +2254,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 +2272,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 +2299,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, 0); } =20 static void nvme_tcp_teardown_ctrl(struct nvme_ctrl *ctrl, bool shutdown) @@ -2315,6 +2319,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 +2333,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 Sun Feb 8 00:28:07 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 ABB2E172BBF for ; Tue, 30 Apr 2024 13:19:41 +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=1714483183; cv=none; b=qZ45ce6rohJp6OQHGMF47VvgeauxaLCEimQw9YAGYacDRZMhMfsnEvRx/xAdR8OwKkDe0S4kuL173USfXEBQwJiOf5+lR9flSjhSfv+bfEvOUIdMaMnHAOQTFW7IMxROenL+LNc9iN5A2kiAoA3ptgA2ZkHenVttwHj7sWWJLT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714483183; c=relaxed/simple; bh=C6Zn8VOHwXTgHLQaPeMnYxE2OulkefG+XkQTMoyYnpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YmsTmPX+voc8u+oVTWik5EuZ5FVcLOtB8BPiazTH02BUz/1szX2Sna6exGIN72HSifcfcsASYRkKzZeqkLBDYOflrPNxuvmo9Eq2q3uNJdptIwA6l+1iUndiZc+5knaMN7G9xGUUAlHT+GVJTfZSKMdpQ/aW7oiQ1tWlshxqKlI= 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=lYt3wGrT; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=YW3g6yvJ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=lYt3wGrT; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=YW3g6yvJ; 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="lYt3wGrT"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="YW3g6yvJ"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="lYt3wGrT"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="YW3g6yvJ" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 E68CC3406F; Tue, 30 Apr 2024 13:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483178; 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=D5rUttiao1gfgHiNuULv3j0RH1kQuIhcL6vcbzvshaQ=; b=lYt3wGrT8Fgv/Byww9jQhKoS1wZ2QJUuruYZsLj+dh+S3PET2l47ijL/TujEB2mwRAdhOi 6KFeAcGH6BYnqj9Xbi7HnBIAAdjTzgrjNrhK2HzBVDBqMBYCeZPlosAczMarh6RyZuJlP9 ALs81uj2apNenS9ourAbKt8W7o8HMVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483178; 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=D5rUttiao1gfgHiNuULv3j0RH1kQuIhcL6vcbzvshaQ=; b=YW3g6yvJEPm5Y3U3HAheci9Sv1O8U4Lz5jPkw7DtF88iByTsVA+5WqVRpKrzORicSv7SkZ SbmbBefnwTLf4nDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=lYt3wGrT; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=YW3g6yvJ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483178; 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=D5rUttiao1gfgHiNuULv3j0RH1kQuIhcL6vcbzvshaQ=; b=lYt3wGrT8Fgv/Byww9jQhKoS1wZ2QJUuruYZsLj+dh+S3PET2l47ijL/TujEB2mwRAdhOi 6KFeAcGH6BYnqj9Xbi7HnBIAAdjTzgrjNrhK2HzBVDBqMBYCeZPlosAczMarh6RyZuJlP9 ALs81uj2apNenS9ourAbKt8W7o8HMVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483178; 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=D5rUttiao1gfgHiNuULv3j0RH1kQuIhcL6vcbzvshaQ=; b=YW3g6yvJEPm5Y3U3HAheci9Sv1O8U4Lz5jPkw7DtF88iByTsVA+5WqVRpKrzORicSv7SkZ SbmbBefnwTLf4nDw== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D25D4133A7; Tue, 30 Apr 2024 13:19:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GObnMervMGZ7MAAAD6G6ig (envelope-from ); Tue, 30 Apr 2024 13:19:38 +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 v7 5/5] nvme: do not retry authentication failures Date: Tue, 30 Apr 2024 15:19:28 +0200 Message-ID: <20240430131928.29766-6-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430131928.29766-1-dwagner@suse.de> References: <20240430131928.29766-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: -3.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: E68CC3406F X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:email] Content-Type: text/plain; charset="utf-8" When the key is invalid there is no point in retrying. Because the auth code returns kernel error codes only, we can't test on the DNR bit. Signed-off-by: Daniel Wagner --- drivers/nvme/host/auth.c | 6 +++--- drivers/nvme/host/fabrics.c | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c index a264b3ae078b..371e14f0a203 100644 --- a/drivers/nvme/host/auth.c +++ b/drivers/nvme/host/auth.c @@ -730,7 +730,7 @@ static void nvme_queue_auth_work(struct work_struct *wo= rk) NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE); if (ret) { chap->status =3D ret; - chap->error =3D -ECONNREFUSED; + chap->error =3D -EKEYREJECTED; return; } =20 @@ -797,7 +797,7 @@ static void nvme_queue_auth_work(struct work_struct *wo= rk) NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1); if (ret) { chap->status =3D ret; - chap->error =3D -ECONNREFUSED; + chap->error =3D -EKEYREJECTED; return; } =20 @@ -818,7 +818,7 @@ static void nvme_queue_auth_work(struct work_struct *wo= rk) ret =3D nvme_auth_process_dhchap_success1(ctrl, chap); if (ret) { /* Controller authentication failed */ - chap->error =3D -ECONNREFUSED; + chap->error =3D -EKEYREJECTED; goto fail2; } =20 diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index 36d3e2ff27f3..c6ad2148c2e0 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -567,12 +567,18 @@ EXPORT_SYMBOL_GPL(nvmf_connect_io_queue); * * - the DNR bit is set and the specification states no further connect * attempts with the same set of paramenters should be attempted. + * + * - when the authentication attempt fails, because the key was invalid. + * This error code is set on the host side. */ bool nvmf_should_reconnect(struct nvme_ctrl *ctrl, int status) { if (status > 0 && (status & NVME_SC_DNR)) return false; =20 + if (status =3D=3D -EKEYREJECTED) + return false; + if (ctrl->opts->max_reconnects =3D=3D -1 || ctrl->nr_reconnects < ctrl->opts->max_reconnects) return true; --=20 2.44.0