mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Daniel Wagner <wagi@kernel.org>,
	Justin Tee <justin.tee@broadcom.com>,
	Christoph Hellwig <hch@lst.de>, Keith Busch <kbusch@kernel.org>
Cc: James Smart <james.smart@broadcom.com>,
	Jens Axboe <axboe@kernel.dk>,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] nvme-fc: don't hold rport lock when putting ctrl
Date: Tue, 4 Nov 2025 11:51:09 +0100	[thread overview]
Message-ID: <accf6ad7-047b-48d0-b626-f3ef0facd649@suse.de> (raw)
In-Reply-To: <20251028-nvmet-fcloop-fixes-v1-1-765427148613@kernel.org>

On 10/28/25 16:26, Daniel Wagner wrote:
> nvme_fc_ctrl_put can acquire the rport lock when freeing the
> ctrl object:
> 
> nvme_fc_ctrl_put
>    nvme_fc_ctrl_free
>      spin_lock_irqsave(rport->lock)
> 
> Thus we can't hold the rport lock when calling nvme_fc_ctrl_put.
> 
> Signed-off-by: Daniel Wagner <wagi@kernel.org>
> ---
>   drivers/nvme/host/fc.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 03987f497a5b..2c0ea843ae57 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -1488,7 +1488,9 @@ nvme_fc_match_disconn_ls(struct nvme_fc_rport *rport,
>   		if (ret)
>   			/* leave the ctrl get reference */
>   			break;
> +		spin_unlock_irqrestore(&rport->lock, flags);
>   		nvme_fc_ctrl_put(ctrl);
> +		spin_lock_irqsave(&rport->lock, flags);
>   	}
>   
>   	spin_unlock_irqrestore(&rport->lock, flags);
> 
In theory, yes.
In practice we're getting a reference to the controller at the start
of the loop, so nvme_fc_ctrl_put() should just decrement the refcount.
But _if_ someone manages to sneak in an drop the reference while we are
within that loop then the entire logic falls apart as the controller
will be deleted and the next loop iteration will trip over an
uninitialized pointer.
So you would need to modify the loop to use
loop_for_each_entry_safe() to avoid this, too.

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

  parent reply	other threads:[~2025-11-04 10:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28 15:26 [PATCH 0/5] nvme-fc: misc small improvents Daniel Wagner
2025-10-28 15:26 ` [PATCH 1/5] nvme-fc: don't hold rport lock when putting ctrl Daniel Wagner
2025-10-29  8:51   ` Christoph Hellwig
2025-11-04 10:51   ` Hannes Reinecke [this message]
2025-11-04 12:32     ` Daniel Wagner
2025-10-28 15:26 ` [PATCH 2/5] nvme-fc: check all request and response have been processed Daniel Wagner
2025-10-29  8:51   ` Christoph Hellwig
2025-11-04 10:51   ` Hannes Reinecke
2025-10-28 15:26 ` [PATCH 3/5] nvmet-fcloop: " Daniel Wagner
2025-10-29  8:52   ` Christoph Hellwig
2025-11-04 10:52   ` Hannes Reinecke
2025-10-28 15:26 ` [PATCH 4/5] nvmet-fcloop: remove unused lsdir member Daniel Wagner
2025-10-29  8:52   ` Christoph Hellwig
2025-11-04 10:52   ` Hannes Reinecke
2025-10-28 15:26 ` [PATCH 5/5] nvmet-fc: use pr_* print macros instead of dev_* Daniel Wagner
2025-10-28 15:47   ` Daniel Wagner
2025-10-29  8:52   ` Christoph Hellwig
2025-11-04 10:54   ` Hannes Reinecke
2025-10-29  0:33 [PATCH 1/5] nvme-fc: don't hold rport lock when putting ctrl Justin Tee
2025-10-29 10:05 ` Daniel Wagner
2025-10-29 16:36   ` Justin Tee
2025-10-30  9:49 ` Daniel Wagner
2025-10-30 22:02   ` Justin Tee

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=accf6ad7-047b-48d0-b626-f3ef0facd649@suse.de \
    --to=hare@suse.de \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=justin.tee@broadcom.com \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --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®