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 4D1F17262A; Tue, 11 Nov 2025 01:02:23 +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=1762822944; cv=none; b=tlaqTUrRGKKGSim/mUhJ5CA4R2me8C+SplFB1ZGDoNeD3+YcEapEFpavJaJoerRdNjCi4WOVxkEISy5mumVpHAeOnsQfm1kXsZC/hoNTLAIwlAM6zoDfpvXAB0rt2aKIGrRgz9ff7YJRtJ7dE9fgqPQdj5xRgn3JSLRD9wMc3r0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762822944; c=relaxed/simple; bh=3yrO09orLFRACu3cDSi+eqXHGH5x/BsziGzoYy6lA2I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UHWF3JWXtj3H4NFDKrKVXsXnaC6+eWbnyrAKE6qayGmH7Tv3+AaivlVN1kMzygDiq7psp5N3fhgPecamXwCJ9u3RE+CczT0Xak1eBVTCpktiSjZ9CKHHk2+aaqydGhprjBN22bQhlyseSnWa5NCv+WW19KszefQHKiiEQeEeisk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KcE8cxHu; 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="KcE8cxHu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E5C4C16AAE; Tue, 11 Nov 2025 01:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1762822943; bh=3yrO09orLFRACu3cDSi+eqXHGH5x/BsziGzoYy6lA2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KcE8cxHuHkxTmtcP01zc4KoMl1U6jwaOoFEaaHThpS0tQgA106RkLTQLJyI14TGg4 9XPGAuDvqnFfc0xwNIQ7AN0/+AXHz2+bIypW1V6b3ny75rQA+52x0MON9XGk1hi+Bs PGug6Hp4ds+YNH+JqE0AxqZ7goLmafTW2Tl7OgYA= 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.12 138/565] nvme-fc: use lock accessing port_state and rport state Date: Tue, 11 Nov 2025 09:39:54 +0900 Message-ID: <20251111004530.049682215@linuxfoundation.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251111004526.816196597@linuxfoundation.org> References: <20251111004526.816196597@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.12-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 7c13a400071e6..57c9491233860 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -3026,11 +3026,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