From: James Smart <jsmart2021@gmail.com>
To: Daniel Wagner <wagi@kernel.org>,
James Smart <james.smart@broadcom.com>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>
Cc: Hannes Reinecke <hare@suse.de>, Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 10/18] nvmet-fcloop: allocate/free fcloop_lsreq directly
Date: Wed, 19 Mar 2025 15:47:20 -0700 [thread overview]
Message-ID: <4937c9f8-fbc7-46d4-a14f-262a0244f1f0@gmail.com> (raw)
In-Reply-To: <20250318-nvmet-fcloop-v3-10-05fec0fc02f6@kernel.org>
On 3/18/2025 3:40 AM, Daniel Wagner wrote:
> fcloop depends on the host or the target to allocate the fcloop_lsreq
> object. This means that the lifetime of the fcloop_lsreq is tied to
> either the host or the target. Consequently, the host or the target must
> cooperate during shutdown.
>
> Unfortunately, this approach does not work well when the target forces a
> shutdown, as there are dependencies that are difficult to resolve in a
> clean way.
ok - although I'm guessing you'll trading one set of problems for another.
>
> The simplest solution is to decouple the lifetime of the fcloop_lsreq
> object by managing them directly within fcloop. Since this is not a
> performance-critical path and only a small number of LS objects are used
> during setup and cleanup, it does not significantly impact performance
> to allocate them during normal operation.
ok
>
> Signed-off-by: Daniel Wagner <wagi@kernel.org>
> ---
> drivers/nvme/target/fcloop.c | 53 +++++++++++++++++++++++++++++---------------
> 1 file changed, 35 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c
> index 06f42da6a0335c53ae319133119d057aab12e07e..537fc6533a4cf5d39855cf850b82af739eeb3056 100644
> --- a/drivers/nvme/target/fcloop.c
> +++ b/drivers/nvme/target/fcloop.c
> @@ -342,6 +342,7 @@ fcloop_rport_lsrqst_work(struct work_struct *work)
> * callee may free memory containing tls_req.
> * do not reference lsreq after this.
> */
> + kfree(tls_req);
>
> spin_lock(&rport->lock);
> }
> @@ -353,10 +354,13 @@ fcloop_h2t_ls_req(struct nvme_fc_local_port *localport,
> struct nvme_fc_remote_port *remoteport,
> struct nvmefc_ls_req *lsreq)
> {
> - struct fcloop_lsreq *tls_req = lsreq->private;
> struct fcloop_rport *rport = remoteport->private;
> + struct fcloop_lsreq *tls_req;
> int ret = 0;
>
> + tls_req = kmalloc(sizeof(*tls_req), GFP_KERNEL);
> + if (!tls_req)
> + return -ENOMEM;
> tls_req->lsreq = lsreq;
> INIT_LIST_HEAD(&tls_req->ls_list);
>
> @@ -387,19 +391,23 @@ fcloop_h2t_xmt_ls_rsp(struct nvmet_fc_target_port *targetport,
> struct nvme_fc_remote_port *remoteport = tport->remoteport;
> struct fcloop_rport *rport;
>
> +
> + if (!remoteport) {
> + kfree(tls_req);
> + return -ECONNREFUSED;
> + }
> +
don't do this - this is not a path the lldd would generate.
> memcpy(lsreq->rspaddr, lsrsp->rspbuf,
> ((lsreq->rsplen < lsrsp->rsplen) ?
> lsreq->rsplen : lsrsp->rsplen));
>
> lsrsp->done(lsrsp);
This done() call should always be made regardless of the remoteport
presence.
instead, put the check here
if (!remoteport) {
kfree(tls_req);
return 0;
}
>
> - if (remoteport) {
> - rport = remoteport->private;
> - spin_lock(&rport->lock);
> - list_add_tail(&tls_req->ls_list, &rport->ls_list);
> - spin_unlock(&rport->lock);
> - queue_work(nvmet_wq, &rport->ls_work);
> - }
> + rport = remoteport->private;
> + spin_lock(&rport->lock);
> + list_add_tail(&tls_req->ls_list, &rport->ls_list);
> + spin_unlock(&rport->lock);
> + queue_work(nvmet_wq, &rport->ls_work);
this is just an indentation style - whichever way works.
>
> return 0;
> }
> @@ -426,6 +434,7 @@ fcloop_tport_lsrqst_work(struct work_struct *work)
> * callee may free memory containing tls_req.
> * do not reference lsreq after this.
> */
> + kfree(tls_req);
>
> spin_lock(&tport->lock);
> }
> @@ -436,8 +445,8 @@ static int
> fcloop_t2h_ls_req(struct nvmet_fc_target_port *targetport, void *hosthandle,
> struct nvmefc_ls_req *lsreq)
> {
> - struct fcloop_lsreq *tls_req = lsreq->private;
> struct fcloop_tport *tport = targetport->private;
> + struct fcloop_lsreq *tls_req;
> int ret = 0;
>
> /*
> @@ -445,6 +454,10 @@ fcloop_t2h_ls_req(struct nvmet_fc_target_port *targetport, void *hosthandle,
> * hosthandle ignored as fcloop currently is
> * 1:1 tgtport vs remoteport
> */
> +
> + tls_req = kmalloc(sizeof(*tls_req), GFP_KERNEL);
> + if (!tls_req)
> + return -ENOMEM;
> tls_req->lsreq = lsreq;
> INIT_LIST_HEAD(&tls_req->ls_list);
>
> @@ -461,6 +474,9 @@ fcloop_t2h_ls_req(struct nvmet_fc_target_port *targetport, void *hosthandle,
> ret = nvme_fc_rcv_ls_req(tport->remoteport, &tls_req->ls_rsp,
> lsreq->rqstaddr, lsreq->rqstlen);
>
> + if (ret)
> + kfree(tls_req);
> +
> return ret;
> }
>
> @@ -475,18 +491,21 @@ fcloop_t2h_xmt_ls_rsp(struct nvme_fc_local_port *localport,
> struct nvmet_fc_target_port *targetport = rport->targetport;
> struct fcloop_tport *tport;
>
> + if (!targetport) {
> + kfree(tls_req);
> + return -ECONNREFUSED;
> + }
> +
same here - don't do this - this is not a path the lldd would generate.
> memcpy(lsreq->rspaddr, lsrsp->rspbuf,
> ((lsreq->rsplen < lsrsp->rsplen) ?
> lsreq->rsplen : lsrsp->rsplen));
> lsrsp->done(lsrsp);
>
Same for this done().
instead, put the check here
if (!targetport) {
kfree(tls_req);
return 0;
}
> - if (targetport) {
> - tport = targetport->private;
> - spin_lock(&tport->lock);
> - list_add_tail(&tport->ls_list, &tls_req->ls_list);
> - spin_unlock(&tport->lock);
> - queue_work(nvmet_wq, &tport->ls_work);
> - }
> + tport = targetport->private;
> + spin_lock(&tport->lock);
> + list_add_tail(&tport->ls_list, &tls_req->ls_list);
> + spin_unlock(&tport->lock);
> + queue_work(nvmet_wq, &tport->ls_work);
>
> return 0;
> }
> @@ -1129,7 +1148,6 @@ static struct nvme_fc_port_template fctemplate = {
> /* sizes of additional private data for data structures */
> .local_priv_sz = sizeof(struct fcloop_lport_priv),
> .remote_priv_sz = sizeof(struct fcloop_rport),
> - .lsrqst_priv_sz = sizeof(struct fcloop_lsreq),
> .fcprqst_priv_sz = sizeof(struct fcloop_ini_fcpreq),
> };
>
> @@ -1152,7 +1170,6 @@ static struct nvmet_fc_target_template tgttemplate = {
> .target_features = 0,
> /* sizes of additional private data for data structures */
> .target_priv_sz = sizeof(struct fcloop_tport),
> - .lsrqst_priv_sz = sizeof(struct fcloop_lsreq),
> };
>
> static ssize_t
>
-- james
next prev parent reply other threads:[~2025-03-19 22:47 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 10:39 [PATCH v3 00/18] nvmet-fcloop: track resources via reference counting Daniel Wagner
2025-03-18 10:39 ` [PATCH v3 01/18] nvmet-fcloop: remove nport from list on last user Daniel Wagner
2025-03-18 10:39 ` [PATCH v3 02/18] nvmet-fcloop: replace kref with refcount Daniel Wagner
2025-03-18 10:56 ` Hannes Reinecke
2025-04-02 14:03 ` Daniel Wagner
2025-04-02 14:06 ` Hannes Reinecke
2025-03-21 6:03 ` Christoph Hellwig
2025-03-21 14:16 ` Hannes Reinecke
2025-03-18 10:39 ` [PATCH v3 03/18] nvmet-fcloop: add ref counting to lport Daniel Wagner
2025-03-21 6:04 ` Christoph Hellwig
2025-03-18 10:39 ` [PATCH v3 04/18] nvmet-fcloop: refactor fcloop_nport_alloc Daniel Wagner
2025-03-18 11:02 ` Hannes Reinecke
2025-03-18 13:38 ` Daniel Wagner
2025-03-18 14:10 ` Hannes Reinecke
2025-03-21 6:05 ` Christoph Hellwig
2025-03-18 10:39 ` [PATCH v3 05/18] nvmet-fcloop: track ref counts for nports Daniel Wagner
2025-03-18 11:06 ` Hannes Reinecke
2025-03-18 13:44 ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 06/18] nvmet-fcloop: sync targetport removal Daniel Wagner
2025-03-18 11:07 ` Hannes Reinecke
2025-03-21 6:08 ` Christoph Hellwig
2025-04-02 16:39 ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 07/18] nvmet-fcloop: update refs on tfcp_req Daniel Wagner
2025-03-18 11:09 ` Hannes Reinecke
2025-03-21 6:08 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 08/18] nvmet-fcloop: add missing fcloop_callback_host_done Daniel Wagner
2025-03-18 11:12 ` Hannes Reinecke
2025-03-18 13:49 ` Daniel Wagner
2025-04-02 17:08 ` Daniel Wagner
2025-04-03 13:25 ` Daniel Wagner
2025-04-04 7:28 ` Daniel Wagner
2025-03-21 6:12 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 09/18] nvmet-fcloop: prevent double port deletion Daniel Wagner
2025-03-18 11:15 ` Hannes Reinecke
2025-03-18 13:55 ` Daniel Wagner
2025-03-21 6:13 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 10/18] nvmet-fcloop: allocate/free fcloop_lsreq directly Daniel Wagner
2025-03-18 11:17 ` Hannes Reinecke
2025-03-18 13:58 ` Daniel Wagner
2025-04-08 11:20 ` Daniel Wagner
2025-03-19 22:47 ` James Smart [this message]
2025-04-04 12:53 ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 11/18] nvmet-fc: inline nvmet_fc_delete_assoc Daniel Wagner
2025-03-21 6:14 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 12/18] nvmet-fc: inline nvmet_fc_free_hostport Daniel Wagner
2025-03-21 6:15 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 13/18] nvmet-fc: update tgtport ref per assoc Daniel Wagner
2025-03-21 6:15 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 14/18] nvmet-fc: take tgtport reference only once Daniel Wagner
2025-03-18 11:18 ` Hannes Reinecke
2025-03-21 6:17 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 15/18] nvmet-fc: free pending reqs on tgtport unregister Daniel Wagner
2025-03-21 6:19 ` Christoph Hellwig
2025-04-08 11:29 ` Daniel Wagner
2025-03-18 10:40 ` [PATCH v3 16/18] nvmet-fc: take tgtport refs for portentry Daniel Wagner
2025-03-18 11:19 ` Hannes Reinecke
2025-03-18 10:40 ` [PATCH v3 17/18] nvmet-fc: put ref when assoc->del_work is already scheduled Daniel Wagner
2025-03-18 11:20 ` Hannes Reinecke
2025-03-21 6:19 ` Christoph Hellwig
2025-03-18 10:40 ` [PATCH v3 18/18] nvme-fc: do not reference lsrsp after failure Daniel Wagner
2025-03-18 11:33 ` Hannes Reinecke
2025-03-18 14:01 ` Daniel Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4937c9f8-fbc7-46d4-a14f-262a0244f1f0@gmail.com \
--to=jsmart2021@gmail.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=james.smart@broadcom.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=wagi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®