From: Hannes Reinecke <hare@suse.de>
To: Daniel Wagner <dwagner@suse.de>
Cc: 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>,
Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 04/18] nvmet-fcloop: refactor fcloop_nport_alloc
Date: Tue, 18 Mar 2025 15:10:29 +0100 [thread overview]
Message-ID: <b89fcad1-ed97-4354-9892-14631794d95d@suse.de> (raw)
In-Reply-To: <66261f08-5386-4b22-aa6f-7be1d4023fee@flourine.local>
On 3/18/25 14:38, Daniel Wagner wrote:
> On Tue, Mar 18, 2025 at 12:02:48PM +0100, Hannes Reinecke wrote:
>>> - list_for_each_entry(tmplport, &fcloop_lports, lport_list) {
>>> - if (tmplport->localport->node_name == opts->wwnn &&
>>> - tmplport->localport->port_name == opts->wwpn)
>>> - goto out_invalid_opts;
>>> + INIT_LIST_HEAD(&nport->nport_list);
>>> + nport->node_name = opts->wwnn;
>>> + nport->port_name = opts->wwpn;
>>> + refcount_set(&nport->ref, 1);
>>> - if (tmplport->localport->node_name == opts->lpwwnn &&
>>> - tmplport->localport->port_name == opts->lpwwpn)
>>> - lport = tmplport;
>>> + spin_lock_irqsave(&fcloop_lock, flags);
>>> + list_add_tail(&nport->nport_list, &fcloop_nports);
>>> + spin_unlock_irqrestore(&fcloop_lock, flags);
>>> }
>> Hmm. I don't really like this pattern; there is a race condition
>> between lookup and allocation leading to possibly duplicate entries
>> on the list.
>
> Yes, that's not a good thing.
>
>> Lookup and allocation really need to be under the same lock.
>
> This means the new entry has always to be allocated first and then we
> either free it again or insert into the list, because it's not possible
> to allocate under the spinlock. Not that beautiful but correctness wins.
Allocate first, and then free it if the entry is already present.
Slightly wasteful, but that's what it is.
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-03-18 14:10 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 [this message]
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
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=b89fcad1-ed97-4354-9892-14631794d95d@suse.de \
--to=hare@suse.de \
--cc=dwagner@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®