From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E501434DB6E; Fri, 21 Nov 2025 13:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732351; cv=none; b=fExz/RR7MEO4T6vHxN6fs7mLJ8lotGihoi2oc0Yr8grU3zcgkT38vqQxPWl0L21MjiUKIUzehgF7QZ+V4b9305JOtUL55yC8fVTZ4QgT4DqLIZ3CuK8HeXSIFCMF5bD0F95uyCtCFNfXzQrC/dF9YIppFvtRRebPXywOpM1P4ww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732351; c=relaxed/simple; bh=YLsNGQePXmQtiW3oVVBXSav4hN/EF/Pkp4K2APiYqGs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bi4Qc6EYH19J9BxLIfkcKcpdbft2M9p9/qfhrsXmYpBtWLggdZy/pDpO4DT4IL/kG00IXbzOfO1OVbqPiD6/pYRQg1u6qaTM5i6b+3TYyC84KTQtGtkEeX+d835AbU50odCl6gRkTxCSdod3R2EN1r8QZkLY5xDRjEpxUVjV+WQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tsGhEtD7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tsGhEtD7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 466EFC4CEF1; Fri, 21 Nov 2025 13:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1763732350; bh=YLsNGQePXmQtiW3oVVBXSav4hN/EF/Pkp4K2APiYqGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsGhEtD7L62YSJZ1nLqbTJPazwWELRuhx6dOmcoG+hfxsFW20sXpkJs+sHqZNarwg pRR8PzaD5hpq+2HrCSpFS7PnkEc2uWJYInk6teV75y3FXh/RiYZsEcua0wMRSQSqHq 70SlPy5bQEdK4bty5YskTxsK+EwNhWurbfBS2jKA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shinichiro Kawasaki , Daniel Wagner , Hannes Reinecke , Keith Busch , Sasha Levin Subject: [PATCH 6.6 089/529] nvme-fc: use lock accessing port_state and rport state Date: Fri, 21 Nov 2025 14:06:28 +0100 Message-ID: <20251121130234.195527958@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251121130230.985163914@linuxfoundation.org> References: <20251121130230.985163914@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Wagner [ Upstream commit 891cdbb162ccdb079cd5228ae43bdeebce8597ad ] nvme_fc_unregister_remote removes the remote port on a lport object at any point in time when there is no active association. This races with with the reconnect logic, because nvme_fc_create_association is not taking a lock to check the port_state and atomically increase the active count on the rport. Reported-by: Shinichiro Kawasaki Closes: https://lore.kernel.org/all/u4ttvhnn7lark5w3sgrbuy2rxupcvosp4qmvj46nwzgeo5ausc@uyrkdls2muwx Signed-off-by: Daniel Wagner Reviewed-by: Hannes Reinecke Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/fc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 3e0da2422b334..bf9ab07257642 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -3024,11 +3024,17 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl) ++ctrl->ctrl.nr_reconnects; - if (ctrl->rport->remoteport.port_state != FC_OBJSTATE_ONLINE) + spin_lock_irqsave(&ctrl->rport->lock, flags); + if (ctrl->rport->remoteport.port_state != FC_OBJSTATE_ONLINE) { + spin_unlock_irqrestore(&ctrl->rport->lock, flags); return -ENODEV; + } - if (nvme_fc_ctlr_active_on_rport(ctrl)) + if (nvme_fc_ctlr_active_on_rport(ctrl)) { + spin_unlock_irqrestore(&ctrl->rport->lock, flags); return -ENOTUNIQ; + } + spin_unlock_irqrestore(&ctrl->rport->lock, flags); dev_info(ctrl->ctrl.device, "NVME-FC{%d}: create association : host wwpn 0x%016llx " -- 2.51.0