From: Hannes Reinecke <hare@suse.de>
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: Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 08/14] nvmet-fcloop: prevent double port deletion
Date: Wed, 7 May 2025 15:59:02 +0200 [thread overview]
Message-ID: <8ce7f125-66b3-4c8c-8c99-77d129adb1a8@suse.de> (raw)
In-Reply-To: <20250507-nvmet-fcloop-v6-8-ca02e16fb018@kernel.org>
On 5/7/25 14:23, Daniel Wagner wrote:
> The delete callback can be called either via the unregister function or
> from the transport directly. Thus it is necessary ensure resources are
> not freed multiple times.
>
> Signed-off-by: Daniel Wagner <wagi@kernel.org>
> ---
> drivers/nvme/target/fcloop.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c
> index 9adaee3c7129f7e270842c5d09f78de2e108479a..c74baa7f6e43c8bddd9e6948f806f27b032b1d4d 100644
> --- a/drivers/nvme/target/fcloop.c
> +++ b/drivers/nvme/target/fcloop.c
> @@ -215,6 +215,9 @@ struct fcloop_lport_priv {
> struct fcloop_lport *lport;
> };
>
> +/* The port is already being removed, avoid double free */
> +#define PORT_DELETED 0
> +
> struct fcloop_rport {
> struct nvme_fc_remote_port *remoteport;
> struct nvmet_fc_target_port *targetport;
> @@ -223,6 +226,7 @@ struct fcloop_rport {
> spinlock_t lock;
> struct list_head ls_list;
> struct work_struct ls_work;
> + unsigned long flags;
> };
>
> struct fcloop_tport {
> @@ -233,6 +237,7 @@ struct fcloop_tport {
> spinlock_t lock;
> struct list_head ls_list;
> struct work_struct ls_work;
> + unsigned long flags;
> };
>
> struct fcloop_nport {
> @@ -1067,30 +1072,38 @@ static void
> fcloop_remoteport_delete(struct nvme_fc_remote_port *remoteport)
> {
> struct fcloop_rport *rport = remoteport->private;
> + bool put_port = false;
> unsigned long flags;
>
> flush_work(&rport->ls_work);
>
> spin_lock_irqsave(&fcloop_lock, flags);
> + if (!test_and_set_bit(PORT_DELETED, &rport->flags))
> + put_port = true;
> rport->nport->rport = NULL;
Can't we set '->nport' to NULL here (and save it in a temporary
variable)?
Then it's quite obvious if we need to call nport_put(),
and we would do away with the 'flags' field ...
> spin_unlock_irqrestore(&fcloop_lock, flags);
>
> - fcloop_nport_put(rport->nport);
> + if (put_port)
> + fcloop_nport_put(rport->nport);
> }
>
> static void
> fcloop_targetport_delete(struct nvmet_fc_target_port *targetport)
> {
> struct fcloop_tport *tport = targetport->private;
> + bool put_port = false;
> unsigned long flags;
>
> flush_work(&tport->ls_work);
>
> spin_lock_irqsave(&fcloop_lock, flags);
> + if (!test_and_set_bit(PORT_DELETED, &tport->flags))
> + put_port = true;
> tport->nport->tport = NULL;
Similar here.
> spin_unlock_irqrestore(&fcloop_lock, flags);
>
> - fcloop_nport_put(tport->nport);
> + if (put_port)
> + fcloop_nport_put(tport->nport);
> }
>
> #define FCLOOP_HW_QUEUES 4
> @@ -1433,6 +1446,7 @@ fcloop_create_remote_port(struct device *dev, struct device_attribute *attr,
> rport->nport = nport;
> rport->lport = nport->lport;
> nport->rport = rport;
> + rport->flags = 0;
> spin_lock_init(&rport->lock);
> INIT_WORK(&rport->ls_work, fcloop_rport_lsrqst_work);
> INIT_LIST_HEAD(&rport->ls_list);
> @@ -1530,6 +1544,7 @@ fcloop_create_target_port(struct device *dev, struct device_attribute *attr,
> tport->nport = nport;
> tport->lport = nport->lport;
> nport->tport = tport;
> + tport->flags = 0;
> spin_lock_init(&tport->lock);
> INIT_WORK(&tport->ls_work, fcloop_tport_lsrqst_work);
> INIT_LIST_HEAD(&tport->ls_list);
>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
next prev parent reply other threads:[~2025-05-07 13:59 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 12:22 [PATCH v6 00/14] nvmet-fcloop: track resources via reference counting Daniel Wagner
2025-05-07 12:22 ` [PATCH v6 01/14] nvmet-fcloop: track ref counts for nports Daniel Wagner
2025-05-07 13:50 ` Hannes Reinecke
2025-05-08 10:06 ` Daniel Wagner
2025-05-07 12:22 ` [PATCH v6 02/14] nvmet-fcloop: remove nport from list on last user Daniel Wagner
2025-05-07 12:22 ` [PATCH v6 03/14] nvmet-fcloop: refactor fcloop_nport_alloc and track lport Daniel Wagner
2025-05-07 12:23 ` [PATCH v6 04/14] nvmet-fcloop: refactor fcloop_delete_local_port Daniel Wagner
2025-05-07 12:23 ` [PATCH v6 05/14] nvmet-fcloop: update refs on tfcp_req Daniel Wagner
2025-05-07 12:23 ` [PATCH v6 06/14] nvmet-fcloop: add missing fcloop_callback_host_done Daniel Wagner
2025-05-07 13:51 ` Hannes Reinecke
2025-05-07 12:23 ` [PATCH v6 07/14] nvmet-fcloop: access fcpreq only when holding reqlock Daniel Wagner
2025-05-07 13:52 ` Hannes Reinecke
2025-05-07 12:23 ` [PATCH v6 08/14] nvmet-fcloop: prevent double port deletion Daniel Wagner
2025-05-07 13:59 ` Hannes Reinecke [this message]
2025-05-07 12:23 ` [PATCH v6 09/14] nvmet-fcloop: allocate/free fcloop_lsreq directly Daniel Wagner
2025-05-07 12:23 ` [PATCH v6 10/14] nvmet-fcloop: don't wait for lport cleanup Daniel Wagner
2025-05-07 13:59 ` Hannes Reinecke
2025-05-07 12:23 ` [PATCH v6 11/14] nvmet-fcloop: drop response if targetport is gone Daniel Wagner
2025-05-07 12:23 ` [PATCH v6 12/14] nvmet-fc: free pending reqs on tgtport unregister Daniel Wagner
2025-05-07 12:23 ` [PATCH v6 13/14] nvmet-fc: take tgtport refs for portentry Daniel Wagner
2025-05-07 12:23 ` [PATCH v6 14/14] nvme-fc: do not reference lsrsp after failure Daniel Wagner
2025-05-07 14:00 ` Hannes Reinecke
2025-05-12 14:16 ` [PATCH v6 00/14] nvmet-fcloop: track resources via reference counting Christoph Hellwig
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=8ce7f125-66b3-4c8c-8c99-77d129adb1a8@suse.de \
--to=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®