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 08/11] nvmet-fc: take tgtport reference only once
Date: Fri, 28 Feb 2025 08:34:51 +0100 [thread overview]
Message-ID: <f944fdb3-081f-474a-9193-f482fe87f72b@suse.de> (raw)
In-Reply-To: <20250226-nvmet-fcloop-v1-8-c0bd83d43e6a@kernel.org>
On 2/26/25 19:46, Daniel Wagner wrote:
> 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.
>
Can it really?
Main point of this operation is that 'tgtport' isn't going away during
while we're figuring out whether we need it.
With this patch it means that
> Signed-off-by: Daniel Wagner <wagi@kernel.org>
> ---
> drivers/nvme/target/fc.c | 18 +++---------------
> 1 file changed, 3 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
> index b807b4c05cac7fe4764df3df76f8fa50f4bab6ba..391917b4ce0115dbc0ad99d1fb363b1af6ee0685 100644
> --- a/drivers/nvme/target/fc.c
> +++ b/drivers/nvme/target/fc.c
> @@ -1046,29 +1046,16 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
> if (!hosthandle)
> return NULL;
>
> - /*
> - * 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 =
nvmet_fc_match_hostport(tgtport, hosthandle);
> spin_unlock_irqrestore(&tgtport->lock, flags);
>
'tgtport' might be invalid here, causing a crash when taking the lock.
> - if (match) {
> - /* no new allocation - release reference */
> - nvmet_fc_tgtport_put(tgtport);
> + if (match)
> return match;
> - }
>
> newhost = kzalloc(sizeof(*newhost), GFP_KERNEL);
> - if (!newhost) {
> - /* no new allocation - release reference */
> - nvmet_fc_tgtport_put(tgtport);
> + if (!newhost)
> return ERR_PTR(-ENOMEM);
> - }
>
> spin_lock_irqsave(&tgtport->lock, flags);
> match = nvmet_fc_match_hostport(tgtport, hosthandle);
> @@ -1077,6 +1064,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
> kfree(newhost);
> newhost = match;
> } else {
> + nvmet_fc_tgtport_get(tgtport);
> newhost->tgtport = tgtport;
> newhost->hosthandle = hosthandle;
> INIT_LIST_HEAD(&newhost->host_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-02-28 7:35 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 18:45 [PATCH 00/11] nvmet-fcloop: track resources via reference counting Daniel Wagner
2025-02-26 18:45 ` [PATCH 01/11] nvmet-fcloop: remove nport from list on last user Daniel Wagner
2025-02-28 7:04 ` Hannes Reinecke
2025-03-05 14:16 ` Christoph Hellwig
2025-02-26 18:45 ` [PATCH 02/11] nvmet-fcloop: add ref counting to lport Daniel Wagner
2025-02-28 7:05 ` Hannes Reinecke
2025-03-05 14:17 ` Christoph Hellwig
2025-03-06 9:26 ` Daniel Wagner
2025-03-06 10:06 ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 03/11] nvmet-fcloop: refactor fcloop_nport_alloc Daniel Wagner
2025-02-28 7:11 ` Hannes Reinecke
2025-02-28 7:56 ` Daniel Wagner
2025-03-05 14:18 ` Christoph Hellwig
2025-02-26 18:45 ` [PATCH 04/11] nvmet-fcloop: track ref counts for nports Daniel Wagner
2025-02-28 7:19 ` Hannes Reinecke
2025-02-28 8:09 ` Daniel Wagner
2025-02-28 8:18 ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 05/11] nvmet-fcloop: track tport with ref counting Daniel Wagner
2025-02-28 7:27 ` Hannes Reinecke
2025-02-28 8:30 ` Daniel Wagner
2025-02-28 14:31 ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 06/11] nvmet-fcloop: track rport " Daniel Wagner
2025-02-28 7:29 ` Hannes Reinecke
2025-02-26 18:45 ` [PATCH 07/11] nvmet-fc: update tgtport ref per assoc Daniel Wagner
2025-02-28 7:30 ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 08/11] nvmet-fc: take tgtport reference only once Daniel Wagner
2025-02-28 7:34 ` Hannes Reinecke [this message]
2025-02-28 8:45 ` Daniel Wagner
2025-02-26 18:46 ` [PATCH 09/11] nvmet-fc: free pending reqs on tgtport unregister Daniel Wagner
2025-02-28 7:35 ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 10/11] nvmet-fc: inline nvmet_fc_delete_assoc Daniel Wagner
2025-02-28 7:36 ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 11/11] nvmet-fc: inline nvmet_fc_free_hostport Daniel Wagner
2025-02-28 7:37 ` Hannes Reinecke
2025-02-27 16:30 ` [PATCH 00/11] nvmet-fcloop: track resources via reference counting 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=f944fdb3-081f-474a-9193-f482fe87f72b@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®