From nobody Thu Dec 18 14:46:05 2025 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 DE589225419 for ; Tue, 8 Apr 2025 15:29:15 +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=1744126156; cv=none; b=uVBpXeAjQIXNjRLT0fBqJzF5RgP/4eA2ITuIRJRMD/TeqBx1zrJowLg+0k4xUFTtf9TwRF3pKYkMtyYB2ewOdP9QV7xMc7N8AH1c1LdTJDsxAqWVUCRclfM6q5ae9xzMqS/ulN3lUrj6q9U0Didd/xvOrqGSDWP+R1m/MTUeWCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126156; c=relaxed/simple; bh=ceT3G4N2zSseN3NqLnEA5gWCVWS4Ndi292BWL+Gup0U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b6MBKy7cY24g6FnaUbIVKBfwSXyiTDaR7ZuJgGnnNtZgBAUjX/spmsvPt0/paRdAl8UF5AkMVraTmiIMEqfAXGQ4vCCFFbYta6xS8o2BA7GqeyqvdD0gX22lmJ8OwX1kEWbE41rxpCl6q2HqW0exPTQm3A9nxpinQsDwyvZ2Bog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=czlxT9kR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="czlxT9kR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D702BC4CEE5; Tue, 8 Apr 2025 15:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126155; bh=ceT3G4N2zSseN3NqLnEA5gWCVWS4Ndi292BWL+Gup0U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=czlxT9kRhBLmtKGT/QixXHY0itWmeybUxG5ZqaqSBmYjH1weGRUNa84JgtPtlpm33 DNWnlbt6gUs8BK/lwxoRmRWJ/U5KiYFXJnXl7O8k5T4qCZxDj/T2Lmyv8Z8ecpwBdR Ozl3Xm1Bc9WXcn3apefwESxbxTO50ud+v9RfLnOh1PlB3FF5yeIvWf4q8GC3wLo1We z2bOeQwv6gDZoORGAjL053llN3+iLmbbdDwvDEyJT5icbRRJcWwi/OamuMPLghjQGW u17RzhBw8YXLQ/vregQtW9wLrYVs4O1Nfflhb19DvOTfSoa+CAP6cvYcPxE3b8nTra jFpVP32wP6UFw== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:03 +0200 Subject: [PATCH 1/8] nvmet-fcloop: swap list_add_tail arguments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-1-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 The newly element to be added to the list is the first argument of list_add_tail. This fix is missing dcfad4ab4d67 ("nvmet-fcloop: swap the list_add_tail arguments"). Fixes: 437c0b824dbd ("nvme-fcloop: add target to host LS request support") Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/nvme/target/fcloop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c index e1abb27927ff74c9c55ddefd9581aab18bf3b00f..da195d61a9664cba21880a4b99b= a0ee94a58f81a 100644 --- a/drivers/nvme/target/fcloop.c +++ b/drivers/nvme/target/fcloop.c @@ -478,7 +478,7 @@ fcloop_t2h_xmt_ls_rsp(struct nvme_fc_local_port *localp= ort, if (targetport) { tport =3D targetport->private; spin_lock(&tport->lock); - list_add_tail(&tport->ls_list, &tls_req->ls_list); + list_add_tail(&tls_req->ls_list, &tport->ls_list); spin_unlock(&tport->lock); queue_work(nvmet_wq, &tport->ls_work); } --=20 2.49.0 From nobody Thu Dec 18 14:46:05 2025 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 36E8A22D4E5 for ; Tue, 8 Apr 2025 15:29:18 +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=1744126158; cv=none; b=dJEd+KKUpkSi+NhwCGSORtayoTo/9XcKpeM2r2bILDMBCvTzcyPDLa93CFeg3NkV61HT/MR1SAD32AZMH2VFbhYLuQXGdVN5yR5EoVDlw193KjkzpAauED5GhRIWCW9ZeV4g1B5ODLJiwO9OqrfxnrJrzmma5OzUL0DfgiA1Ijg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126158; c=relaxed/simple; bh=A1SZibPm0tk02AGXjML854OFU77oW9j7YzgfK99CFZg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hXBKW3MooaD04fSLMn+TIEb+vOuVikRQuw3Vkcw1dPlkrc+oqIiI3uVsuKEWJUWnKJryWKYY0PGyA21h2Ad71gnBt0qIS0mFh7vDy9MM6LayOlOFOBEooVSLI3UyVgzFo4YOfQhaLc40eXYZ80fcrxjA4eUCs3VvDtYDNBPSLu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fBPrAPv1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fBPrAPv1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9955CC4CEEC; Tue, 8 Apr 2025 15:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126158; bh=A1SZibPm0tk02AGXjML854OFU77oW9j7YzgfK99CFZg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fBPrAPv17s6sUpEHo+jNZC7UbZJj7R00IwqIfKt8e10Hqg7oVahoL7rO4wvxoB0pP ZKmb+SOrzYzJZdBHW4SYRq6qoSLFAfpAQ7X84rcKcMRXuUYgezMo7RqQv8vzX3fP7C IQSgITc6mubWS944yHzQn/T5sdC3zoBVsLcrHHyJyLVnQwRKZy3V1/D16hrcWjl6L9 EEy6PPtE0bodQ6F6m7nOtCqyeaS3hnBH/TCh5aXHqb1rKlwcKJ66yDoXnJ7OFaqMKr Jr42vWo1jVWHuJ63LawMo83/xMqaOqt0vs+1ZgsagDOgekNmh1e+AEmTqC/v4xzbdN IDXk0vYdcC4Tg== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:04 +0200 Subject: [PATCH 2/8] nvmet-fcloop: replace kref with refcount Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-2-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 The kref wrapper is not really adding any value ontop of refcount. Thus replace the kref API with the refcount API. Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner --- drivers/nvme/target/fcloop.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c index da195d61a9664cba21880a4b99ba0ee94a58f81a..67e24c7d59306fec4aa88cacc53= 6c876c465af35 100644 --- a/drivers/nvme/target/fcloop.c +++ b/drivers/nvme/target/fcloop.c @@ -239,7 +239,7 @@ struct fcloop_nport { struct fcloop_tport *tport; struct fcloop_lport *lport; struct list_head nport_list; - struct kref ref; + refcount_t ref; u64 node_name; u64 port_name; u32 port_role; @@ -274,7 +274,7 @@ struct fcloop_fcpreq { u32 inistate; bool active; bool aborted; - struct kref ref; + refcount_t ref; struct work_struct fcp_rcv_work; struct work_struct abort_rcv_work; struct work_struct tio_done_work; @@ -534,24 +534,18 @@ fcloop_tgt_discovery_evt(struct nvmet_fc_target_port = *tgtport) } =20 static void -fcloop_tfcp_req_free(struct kref *ref) +fcloop_tfcp_req_put(struct fcloop_fcpreq *tfcp_req) { - struct fcloop_fcpreq *tfcp_req =3D - container_of(ref, struct fcloop_fcpreq, ref); + if (!refcount_dec_and_test(&tfcp_req->ref)) + return; =20 kfree(tfcp_req); } =20 -static void -fcloop_tfcp_req_put(struct fcloop_fcpreq *tfcp_req) -{ - kref_put(&tfcp_req->ref, fcloop_tfcp_req_free); -} - static int fcloop_tfcp_req_get(struct fcloop_fcpreq *tfcp_req) { - return kref_get_unless_zero(&tfcp_req->ref); + return refcount_inc_not_zero(&tfcp_req->ref); } =20 static void @@ -748,7 +742,7 @@ fcloop_fcp_req(struct nvme_fc_local_port *localport, INIT_WORK(&tfcp_req->fcp_rcv_work, fcloop_fcp_recv_work); INIT_WORK(&tfcp_req->abort_rcv_work, fcloop_fcp_abort_recv_work); INIT_WORK(&tfcp_req->tio_done_work, fcloop_tgt_fcprqst_done_work); - kref_init(&tfcp_req->ref); + refcount_set(&tfcp_req->ref, 1); =20 queue_work(nvmet_wq, &tfcp_req->fcp_rcv_work); =20 @@ -1001,24 +995,18 @@ fcloop_fcp_abort(struct nvme_fc_local_port *localpor= t, } =20 static void -fcloop_nport_free(struct kref *ref) +fcloop_nport_put(struct fcloop_nport *nport) { - struct fcloop_nport *nport =3D - container_of(ref, struct fcloop_nport, ref); + if (!refcount_dec_and_test(&nport->ref)) + return; =20 kfree(nport); } =20 -static void -fcloop_nport_put(struct fcloop_nport *nport) -{ - kref_put(&nport->ref, fcloop_nport_free); -} - static int fcloop_nport_get(struct fcloop_nport *nport) { - return kref_get_unless_zero(&nport->ref); + return refcount_inc_not_zero(&nport->ref); } =20 static void @@ -1249,7 +1237,7 @@ fcloop_alloc_nport(const char *buf, size_t count, boo= l remoteport) newnport->port_role =3D opts->roles; if (opts->mask & NVMF_OPT_FCADDR) newnport->port_id =3D opts->fcaddr; - kref_init(&newnport->ref); + refcount_set(&newnport->ref, 1); =20 spin_lock_irqsave(&fcloop_lock, flags); =20 --=20 2.49.0 From nobody Thu Dec 18 14:46:05 2025 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 40CB422D78D for ; Tue, 8 Apr 2025 15:29:20 +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=1744126161; cv=none; b=VZfQiM3B7V6CuRC86bMbCYljiyLFpccN9Xc4uqczVljcf2Ky8HklRoAyLDW+TWFMXvpweYvymzVG9xKHzLvE/9dz5Cc4DrC1tWiVzoJ9EqCtqDRPbWkX/puELQwA55YJOdYrmO4qeI4bZODcQE4NWFgBQpOxoXm2ul9NKWf1frI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126161; c=relaxed/simple; bh=GSOhZSJXTqBDeMybmCwfGO34LVgry2NBtLmYpTfhtC4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RQXCFOXCGe3+889QzOOY6iTt2hL+J/YOQsOzCJkiNPXZ9XeTHFweVXanxIWjQR+4WFYBsMzbdeg8Qrqj3jbpkpltswNHtyF4R7Xe/zXDVDUJz8FJNhJdhBIxxvr3hZE8PwzTb5+OghFORUZfXQ4PmWfSx/Z11n3IC9xtXD3kBkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o70oWhqx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o70oWhqx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2950DC4CEE9; Tue, 8 Apr 2025 15:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126160; bh=GSOhZSJXTqBDeMybmCwfGO34LVgry2NBtLmYpTfhtC4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=o70oWhqxnwdJfNhdmmReZ+FwwD7RCKOS82aV9uMvdumvge79qWj5sy62pnH9BPqUP Z2V4SUP9FARy9OECTeEn52hYR1wMuyQ/wRS058pNXy6huI78pLPhN8YqKH/3ZElxXx covQHTE8aEKmPm8L/bh9zMOJfYU7kY4/X8gFEkzAIYmpX3OmgtYi8ey6c4mbf2svSN 7l3Av6qw9qyjf2xhejMs+lsdsIkZ6CSzaWds1j8z61t4AiRD3BB8MiSd1SDEBmIREU sZLN1Npz6Lf+wqzigPX+sKcIoGkQGPaUOY4SfDKFBc9pMiloFwEL4R/4TWuo+Yyvgw EC7u0js6KcRXQ== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:05 +0200 Subject: [PATCH 3/8] nvmet-fcloop: add ref counting to lport Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-3-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 The fcloop_lport objects live time is controlled by the user interface add_local_port and del_local_port. nport, rport and tport objects are pointing to the lport objects but here is no clear tracking. Let's introduce an explicit ref counter for the lport objects and prepare the stage for restructuring how lports are used. Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner --- drivers/nvme/target/fcloop.c | 44 +++++++++++++++++++++++++++++++---------= ---- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c index 67e24c7d59306fec4aa88cacc536c876c465af35..641201e62c1bafa13986642c6c4= 067b35f784edd 100644 --- a/drivers/nvme/target/fcloop.c +++ b/drivers/nvme/target/fcloop.c @@ -208,6 +208,7 @@ struct fcloop_lport { struct nvme_fc_local_port *localport; struct list_head lport_list; struct completion unreg_done; + refcount_t ref; }; =20 struct fcloop_lport_priv { @@ -994,6 +995,27 @@ fcloop_fcp_abort(struct nvme_fc_local_port *localport, } } =20 +static void +fcloop_lport_put(struct fcloop_lport *lport) +{ + unsigned long flags; + + if (!refcount_dec_and_test(&lport->ref)) + return; + + spin_lock_irqsave(&fcloop_lock, flags); + list_del(&lport->lport_list); + spin_unlock_irqrestore(&fcloop_lock, flags); + + kfree(lport); +} + +static int +fcloop_lport_get(struct fcloop_lport *lport) +{ + return refcount_inc_not_zero(&lport->ref); +} + static void fcloop_nport_put(struct fcloop_nport *nport) { @@ -1017,6 +1039,8 @@ fcloop_localport_delete(struct nvme_fc_local_port *lo= calport) =20 /* release any threads waiting for the unreg to complete */ complete(&lport->unreg_done); + + fcloop_lport_put(lport); } =20 static void @@ -1128,6 +1152,7 @@ fcloop_create_local_port(struct device *dev, struct d= evice_attribute *attr, =20 lport->localport =3D localport; INIT_LIST_HEAD(&lport->lport_list); + refcount_set(&lport->ref, 1); =20 spin_lock_irqsave(&fcloop_lock, flags); list_add_tail(&lport->lport_list, &fcloop_lports); @@ -1144,13 +1169,6 @@ fcloop_create_local_port(struct device *dev, struct = device_attribute *attr, return ret ? ret : count; } =20 - -static void -__unlink_local_port(struct fcloop_lport *lport) -{ - list_del(&lport->lport_list); -} - static int __wait_localport_unreg(struct fcloop_lport *lport) { @@ -1163,8 +1181,6 @@ __wait_localport_unreg(struct fcloop_lport *lport) if (!ret) wait_for_completion(&lport->unreg_done); =20 - kfree(lport); - return ret; } =20 @@ -1187,8 +1203,9 @@ fcloop_delete_local_port(struct device *dev, struct d= evice_attribute *attr, list_for_each_entry(tlport, &fcloop_lports, lport_list) { if (tlport->localport->node_name =3D=3D nodename && tlport->localport->port_name =3D=3D portname) { + if (!fcloop_lport_get(tlport)) + break; lport =3D tlport; - __unlink_local_port(lport); break; } } @@ -1198,6 +1215,7 @@ fcloop_delete_local_port(struct device *dev, struct d= evice_attribute *attr, return -ENOENT; =20 ret =3D __wait_localport_unreg(lport); + fcloop_lport_put(lport); =20 return ret ? ret : count; } @@ -1625,17 +1643,17 @@ static void __exit fcloop_exit(void) for (;;) { lport =3D list_first_entry_or_null(&fcloop_lports, typeof(*lport), lport_list); - if (!lport) + if (!lport || !fcloop_lport_get(lport)) break; =20 - __unlink_local_port(lport); - spin_unlock_irqrestore(&fcloop_lock, flags); =20 ret =3D __wait_localport_unreg(lport); if (ret) pr_warn("%s: Failed deleting local port\n", __func__); =20 + fcloop_lport_put(lport); + spin_lock_irqsave(&fcloop_lock, flags); } =20 --=20 2.49.0 From nobody Thu Dec 18 14:46:05 2025 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 C6CFA22DFFA for ; Tue, 8 Apr 2025 15:29: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=1744126163; cv=none; b=LsZV5aoLvHewJ1keWb2MH9i5eVC8KHLAt50UqLkBvxoCfN5iqY+T8x3AKhTGI/5zbMwkG91j4sFkIubZP+1ql28aIn4cUnBRFwKp0O1idyoMJ+6Hj3gAO/rm/MZwUXWyMcQ0zl1T0ttD2yTvfPH1uFCBq2IMFq+AEBxl+P+GEMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126163; c=relaxed/simple; bh=2Kg2F1UvaxPLtadqebSyN12HG3Ln8iAYi38zz3aODQY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t5uAdS4JAclRes5JNAWK2zXH2Mvp+rq785JL8r0PB359tHKwpXGfMwoGSN4uSYyhbikxy89u4Z5NFT8FODfjp3MP7Uvl7Sc/WdVg9vx0dJ2ileQ44JOSXicjrUXKKQ3bzKEd48M6qmAw/78m9RqzikITzmdEsSDsN9Bh3gh8H9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SKruh0wx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SKruh0wx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAEB5C4CEE5; Tue, 8 Apr 2025 15:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126163; bh=2Kg2F1UvaxPLtadqebSyN12HG3Ln8iAYi38zz3aODQY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SKruh0wxaqHJpjAZk7Dj0zSDGUj1xJsvCR1rsKT42HC0WjdPDUQyr7tOHvUmiSKXX +X4l/6IhRPkGmEi/D/gMQbGpg18xFI+9Ucz3mn2spGlwq6nx3n1akvkF4p6Oh5GGxF MruRP74WLvdSIK5+ll+DnE41ru4B1NvCXamF/xeY2lkDkXqaZF3/bPVZSny7IBW/BJ 2OUbg9UHh/eicEsNQRWzp4S7OkMi2bwHxGlusvg3c59I9IhAXLuqRrBZCH4LbMsAMe wkvomPG+1fbNdZKwgGGZkS4VBNCibx7C6FkQ8v/jAXap+Y2+dTMYd8zn8XsAz1i8g2 opMz1FHuLUJpA== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:06 +0200 Subject: [PATCH 4/8] nvmet-fc: inline nvmet_fc_delete_assoc Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-4-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 No need for this tiny helper with only one user, just inline it. Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner --- drivers/nvme/target/fc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 7318b736d41417bd974f58f1ef66bce8640db422..6487c46ebba8d12e573d19fe8c3= 9d526492c506a 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1075,13 +1075,6 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgt= port, void *hosthandle) return newhost; } =20 -static void -nvmet_fc_delete_assoc(struct nvmet_fc_tgt_assoc *assoc) -{ - nvmet_fc_delete_target_assoc(assoc); - nvmet_fc_tgt_a_put(assoc); -} - static void nvmet_fc_delete_assoc_work(struct work_struct *work) { @@ -1089,7 +1082,8 @@ nvmet_fc_delete_assoc_work(struct work_struct *work) container_of(work, struct nvmet_fc_tgt_assoc, del_work); struct nvmet_fc_tgtport *tgtport =3D assoc->tgtport; =20 - nvmet_fc_delete_assoc(assoc); + nvmet_fc_delete_target_assoc(assoc); + nvmet_fc_tgt_a_put(assoc); nvmet_fc_tgtport_put(tgtport); } =20 --=20 2.49.0 From nobody Thu Dec 18 14:46:05 2025 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 1310D22F175 for ; Tue, 8 Apr 2025 15:29:25 +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=1744126166; cv=none; b=adFku16KNWmdhYzU56delh+ViHjErGbGcZ0QY3CPwH8vXCBpDrcSJUfNVLIhsWzXVfRBZ/Klw9/foc/dQZ3vtHxPyiJHICLQmNj6tI79as1Y2kK3peM173tsmDr3dEEU2cFe7AjqpWxkiOCu/I+x2Wn93SiWWA+d0Qg0r28bmlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126166; c=relaxed/simple; bh=O5GHwCVJjRcxblaYbgVMKB2kCGt6YrQb7Ba5ru7hUuo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gIUcTPzNHRxkIK78ZsLMKQxEZWEFHBI7r3mYJJcK2HIQ3mC2e18WKHbncaY2adPWAeu5JmbaaUJ9QtaMhWEyxicTbxRGdGwd4P/fSBdOZ/7no8R3txgEKUVKE5cLbbQlyMjNcR/4I4/eky8JgkWWOshMpzBGFIIIacrXDb+vIAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B/P2rIHL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B/P2rIHL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79D86C4CEE5; Tue, 8 Apr 2025 15:29:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126165; bh=O5GHwCVJjRcxblaYbgVMKB2kCGt6YrQb7Ba5ru7hUuo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B/P2rIHL6acwI//GuwPxF9W4886pJxQCrbbkjHHMcNrjaLOFOjwx//wZ9f7+YZqK6 +fQscAGwC+bsz19GNevNIfrmKmms8VmAUzW946bebPOJ6mHDod9uNUStMdyjyA9Edu 0RJweyEDCRH799Hjqf05sI7/zKno+XnqMgl/+RtcPUJybo4YER2LldsENj/E+wDE/F DF9g7tp+FAzuNDcdhbAsJzSiXvoEoQppmioO2GqLskGMISJn0EPDKNZvWszRqmJHk0 Bn7okh5zyI6AaSh23ZpJ6qW8H6IMfbJgCT8nDW7nxP+CoHy1wpvf9knIDcQPjTNOPy 4xt4nva6aa8EA== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:07 +0200 Subject: [PATCH 5/8] nvmet-fc: inline nvmet_fc_free_hostport Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-5-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 No need for this tiny helper with only one user, let's inline it. And since the hostport ref counter needs to stay in sync, it's not optional anymore to give back the reference. Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner --- drivers/nvme/target/fc.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 6487c46ebba8d12e573d19fe8c39d526492c506a..6d64dadcb356b78b522d0deaa43= 3cc745bfcd8f6 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -995,16 +995,6 @@ nvmet_fc_hostport_get(struct nvmet_fc_hostport *hostpo= rt) return kref_get_unless_zero(&hostport->ref); } =20 -static void -nvmet_fc_free_hostport(struct nvmet_fc_hostport *hostport) -{ - /* if LLDD not implemented, leave as NULL */ - if (!hostport || !hostport->hosthandle) - return; - - nvmet_fc_hostport_put(hostport); -} - static struct nvmet_fc_hostport * nvmet_fc_match_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle) { @@ -1184,7 +1174,7 @@ nvmet_fc_target_assoc_free(struct kref *ref) /* Send Disconnect now that all i/o has completed */ nvmet_fc_xmt_disconnect_assoc(assoc); =20 - nvmet_fc_free_hostport(assoc->hostport); + nvmet_fc_hostport_put(assoc->hostport); spin_lock_irqsave(&tgtport->lock, flags); oldls =3D assoc->rcv_disconn; spin_unlock_irqrestore(&tgtport->lock, flags); @@ -1449,11 +1439,6 @@ nvmet_fc_free_tgtport(struct kref *ref) struct nvmet_fc_tgtport *tgtport =3D container_of(ref, struct nvmet_fc_tgtport, ref); struct device *dev =3D tgtport->dev; - unsigned long flags; - - spin_lock_irqsave(&nvmet_fc_tgtlock, flags); - list_del(&tgtport->tgt_list); - spin_unlock_irqrestore(&nvmet_fc_tgtlock, flags); =20 nvmet_fc_free_ls_iodlist(tgtport); =20 @@ -1614,6 +1599,11 @@ int nvmet_fc_unregister_targetport(struct nvmet_fc_target_port *target_port) { struct nvmet_fc_tgtport *tgtport =3D targetport_to_tgtport(target_port); + unsigned long flags; + + spin_lock_irqsave(&nvmet_fc_tgtlock, flags); + list_del(&tgtport->tgt_list); + spin_unlock_irqrestore(&nvmet_fc_tgtlock, flags); =20 nvmet_fc_portentry_unbind_tgt(tgtport); =20 --=20 2.49.0 From nobody Thu Dec 18 14:46:05 2025 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 575261E5B7F for ; Tue, 8 Apr 2025 15:29:29 +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=1744126170; cv=none; b=N01ix5+5MoHWide9BTh86k4/m/iGSBILt0yhlMwUcvBhXAOuYWNv0UHCVr/0vi8cJvDzWVLRUxei7m91RJcCB8i/FDmloNBJ/eAoo+lI33862C1QjqEq9hPoRNVFCgofM2eaMP8Y4UvyJBjF4oEyUN2azO84fe1uvY3BN4G8yDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126170; c=relaxed/simple; bh=xJGc+4ZfEtXd0Q1inHLwc+Miuup2DabedmlojQWG/4M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=un2hmSyHpFxc8N6rTX2gCPV7QXwTwAj8+HIrl9A2VBhTSInAO6nK65qR8BQZbGgBW1DGZQArJ/I2JTTJ/T4UQAZ8tQsNCFBamez4yfonPeOpJpip5R7wWpKEW1NYYINN4uQG34hp3l4jEnC7hQdyhXmPxSONjjraskVvE7zjDVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cnHKkn1/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cnHKkn1/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52FD8C4CEE9; Tue, 8 Apr 2025 15:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126169; bh=xJGc+4ZfEtXd0Q1inHLwc+Miuup2DabedmlojQWG/4M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cnHKkn1/i/vfN8L94bedD3cqiEus3Owc9Akn0InGkpSFwh2a9E3we/bAH7PrvgUsZ XVTvZI3sb0JV0s5tpbZL887wljckaMCvo539mnaqvda+488C9q2D05HIMIAZ5jgqxE Py/q3GagC9o8wsUAuCoz0HV2qPZYgMAo3Muc+v8Fo9y0wchluxSfYN7S5domQblPAz VKvQ1j4sbpyvH2uc3BeyS7qkaliv742LkEbIn3gIymcDPWO6ZguAFerfnjsfIeQB9f Sklg3s3e+jBW5tNPvY+dFoZGR4+uvVFUAkm0UYt9/PubKLNam2ilWamZq8qphJIUl2 12bd3B2d8RHQQ== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:08 +0200 Subject: [PATCH 6/8] nvmet-fc: update tgtport ref per assoc Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-6-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 We need to take for each unique association a reference. nvmet_fc_alloc_hostport for each newly created association. Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Daniel Wagner --- drivers/nvme/target/fc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 6d64dadcb356b78b522d0deaa433cc745bfcd8f6..42613280c06e82a0236520d9347= 0ec6fdede37ea 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1127,6 +1127,7 @@ nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *= tgtport, void *hosthandle) goto out_ida; =20 assoc->tgtport =3D tgtport; + nvmet_fc_tgtport_get(tgtport); assoc->a_id =3D idx; INIT_LIST_HEAD(&assoc->a_list); kref_init(&assoc->ref); @@ -1228,6 +1229,8 @@ nvmet_fc_delete_target_assoc(struct nvmet_fc_tgt_asso= c *assoc) dev_info(tgtport->dev, "{%d:%d} Association deleted\n", tgtport->fc_target_port.port_num, assoc->a_id); + + nvmet_fc_tgtport_put(tgtport); } =20 static struct nvmet_fc_tgt_assoc * --=20 2.49.0 From nobody Thu Dec 18 14:46:05 2025 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 777C31D63C4 for ; Tue, 8 Apr 2025 15:29:32 +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=1744126172; cv=none; b=bmw+r4idMTHTr/W4wPJym9gGImeZVjHxcq9W5mNZard08Oscot4R/a3iG9q4f/OATv5dj2s/Z4dDaBoY7z/Vv2YRfaX4MYY6CQVZDPJkDWjOXveuRY8ZrBxPSsd7G8JOTz9DjjPnRTj7LeGi9tdYxsfu0nkGAjM8USE6XecoWHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126172; c=relaxed/simple; bh=tsk2YMjqBLydxk+bAIUX9VPBT2iOvhNNO848oWtfRbY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j5ywyxi3o0ES9OdBwhS8pjQjPzkbtxG5PYkDygDulh99Q+liXWObvvHIJiN9iNumHRkDjFo9qK72p4GD3Mqy15Xzq7DamTCTJy3Lq4/grmg2WVY4ddf9V6Qp7fWZ6hUm6XcQuSE9B63kKEQGF7bbx6qAfvFHt1s+mZdjNVFfNYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G/3P65ya; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G/3P65ya" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0988CC4CEE5; Tue, 8 Apr 2025 15:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126172; bh=tsk2YMjqBLydxk+bAIUX9VPBT2iOvhNNO848oWtfRbY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=G/3P65yasluv92XU+RZtxMrHfkil9eol/CREQG+XPaGqJRrNFe/Om3IlRqnCoay+b IthqrthbVOaV6lGAGGuyPAYbqOQVByyk903hixR01L0BQI/e6KXYJBDWODy5dRvWLy jF38AoMtK2VTB5QvFv9p36+oy+Qr3EgUqIUV3My/YI6pQag7otvz5UDxMA2bstD64E LCTeQRyvOCHR6+hIGEL8HLZ/Lb1lfiDD2a1TiNYpojJrNAaNm+Ij7JA7KSAKJ9VN6v +xDIqHV+Wdre5TCNAsXFWscL0m6ZQbYNqzS6MwKZy3T0gyxWssFk7GTMCreYwRNhyJ Ts0mbVdL+0VPw== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:09 +0200 Subject: [PATCH 7/8] nvmet-fc: take tgtport reference only once Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-7-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 The reference counting code can be simplified. Instead taking a tgtport refrerence at the beginning of nvmet_fc_alloc_hostport and put it back if not a new hostport object is allocated, only take it when a new hostport object is allocated. Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/target/fc.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 42613280c06e82a0236520d93470ec6fdede37ea..61e9eea3bee430bfdef541bfe0d= 1f2538a49d9eb 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1018,33 +1018,24 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tg= tport, void *hosthandle) struct nvmet_fc_hostport *newhost, *match =3D NULL; unsigned long flags; =20 + /* + * Caller holds a reference on tgtport. + */ + /* if LLDD not implemented, leave as NULL */ if (!hosthandle) return NULL; =20 - /* - * take reference for what will be the newly allocated hostport if - * we end up using a new allocation - */ - if (!nvmet_fc_tgtport_get(tgtport)) - return ERR_PTR(-EINVAL); - spin_lock_irqsave(&tgtport->lock, flags); match =3D nvmet_fc_match_hostport(tgtport, hosthandle); spin_unlock_irqrestore(&tgtport->lock, flags); =20 - if (match) { - /* no new allocation - release reference */ - nvmet_fc_tgtport_put(tgtport); + if (match) return match; - } =20 newhost =3D kzalloc(sizeof(*newhost), GFP_KERNEL); - if (!newhost) { - /* no new allocation - release reference */ - nvmet_fc_tgtport_put(tgtport); + if (!newhost) return ERR_PTR(-ENOMEM); - } =20 spin_lock_irqsave(&tgtport->lock, flags); match =3D nvmet_fc_match_hostport(tgtport, hosthandle); @@ -1053,6 +1044,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtp= ort, void *hosthandle) kfree(newhost); newhost =3D match; } else { + nvmet_fc_tgtport_get(tgtport); newhost->tgtport =3D tgtport; newhost->hosthandle =3D hosthandle; INIT_LIST_HEAD(&newhost->host_list); --=20 2.49.0 From nobody Thu Dec 18 14:46:05 2025 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 2B7D01CCEE2 for ; Tue, 8 Apr 2025 15:29:35 +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=1744126175; cv=none; b=iYdEIKwv6gL56pNi4UOLz3hk9U3fVg23/Q7G93NMbZ8m7AvFU8ns2vIgTKgIEniFGwGn555Bbj1n7K5wC0lhSe9YOE9RhVM0yHAaAK65to86GMw0bRLjh0RVpGjvD8nvmYoEfdEseCmhzkChahkA2p2j2NL436PMc/jkPIEZ6LM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744126175; c=relaxed/simple; bh=lL5xvBPnp71ji+5WknENKAr4x5TL8jAfZndzTEyuBIA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lkGtg4sNWzAwmRB9vi2MlENvOEDr1wuqCxUnEPj3vmIZUW84rTxjPGJSkbagiJTzNkb0D33cvA4MRmovg/eJIT28u2W6bpY7ERPnAfC4eTDbghpCkjoeFBY/7hKfAk5tg88UQr5Ii1P6RNzEC9QoY3rDHYlupy5QabfrvYyQdMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SiSabXla; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SiSabXla" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8C33C4CEE9; Tue, 8 Apr 2025 15:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744126175; bh=lL5xvBPnp71ji+5WknENKAr4x5TL8jAfZndzTEyuBIA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SiSabXlaOkIywKuDWoKj4WIzb6MSLyktUbxB/lS7Au3ht3fdiWfrHbA+cvCmfbB5G /a96f6yJtUqz6um2491bCzn7+J+yRB85v+0LcUxZFDMo8V0+QUdY1kZcmyQ1Q+4zlI I0e+51xQOGj7MVUigoBz7UoocI+GBnPcwujzI2b7aZq7Wv4oLkoYpF3whjvpaaC/YZ dNC7k2REF408lAaunuMJs6o30H/upQQKOJ70cvKujA4SirFw/qrb/1f7Flq61rVyo5 1QpXLXPS3EDT6epMdoZQYHi0Hgo0gsrE+rhtqOM2IQ94RX2lhLK/Q/TCiKpQ/EUwfD ywT6tvNOPF44g== From: Daniel Wagner Date: Tue, 08 Apr 2025 17:29:10 +0200 Subject: [PATCH 8/8] nvmet-fc: put ref when assoc->del_work is already scheduled Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250408-nvmet-fcloop-part-one-v1-8-382ec97ab7eb@kernel.org> References: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> In-Reply-To: <20250408-nvmet-fcloop-part-one-v1-0-382ec97ab7eb@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Jens Axboe , Hannes Reinecke Cc: James Smart , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 Do not leak the tgtport reference when the work is already scheduled. Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/target/fc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 61e9eea3bee430bfdef541bfe0d1f2538a49d9eb..7b50130f10f6578e6e49fe8ea66= 1de34dfbb3683 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1073,7 +1073,8 @@ static void nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc) { nvmet_fc_tgtport_get(assoc->tgtport); - queue_work(nvmet_wq, &assoc->del_work); + if (!queue_work(nvmet_wq, &assoc->del_work)) + nvmet_fc_tgtport_put(assoc->tgtport); } =20 static bool --=20 2.49.0