[PATCH] nvmet-fc: hold queue reference while freeing FCP IOD

sashiko-bot at kernel.org sashiko-bot at kernel.org
Wed Nov 25 04:15:13 PST 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] nvmet-fc: redundant back-to-back kref_get() and put in
  nvmet_fc_free_fcp_iod()
--

commit 6c7c03981acb44ae799c2343512f506b50503766
Author: Bin Luo <luob87709 at gmail.com>

nvmet-fc: hold queue reference while freeing FCP IOD

This commit holds a reference on the target queue in
nvmet_fc_free_fcp_iod() until after queue list operations and deferred
work submission complete.

> diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
> index 5d6c1c79508af..0b3a44886c3df 100644
> --- a/drivers/nvme/target/fc.c
> +++ b/drivers/nvme/target/fc.c
> @@ -733,6 +733,9 @@ nvmet_fc_free_fcp_iod(struct nvmet_fc_tgt_queue *queue,
>  
>  	tgtport->ops->fcp_req_release(&tgtport->fc_target_port, fcpreq);
>  
> +	/* Hold queue across the FOD reference put and queue/list accesses. */
> +	kref_get(&queue->ref);
> +
>  	/* release the queue lookup reference on the completed IO */
>  	nvmet_fc_tgt_q_put(queue);
>  
> @@ -742,6 +745,7 @@ nvmet_fc_free_fcp_iod(struct nvmet_fc_tgt_queue *queue,
>  	if (!deferfcp) {
>  		list_add_tail(&fod->fcp_list, &fod->queue->fod_list);
>  		spin_unlock_irqrestore(&queue->qlock, flags);
> +		nvmet_fc_tgt_q_put(queue);
>  		return;
>  	}
>  
> @@ -774,6 +778,7 @@ nvmet_fc_free_fcp_iod(struct nvmet_fc_tgt_queue *queue,
>  	 */
>  
>  	queue_work(queue->work_q, &fod->defer_work);
> +	nvmet_fc_tgt_q_put(queue);
>  }

[Severity: Low]
Can nvmet_fc_free_fcp_iod() drop the early nvmet_fc_tgt_q_put(queue)
instead of pairing it with a kref_get(&queue->ref) right above it?

Since nvmet_fc_tgt_q_put() calls kref_put(&queue->ref, ...), taking
queue->ref and immediately putting it performs two back-to-back atomic
operations on queue->ref that cancel each other out on every FCP I/O
completion.  Removing the early nvmet_fc_tgt_q_put() and letting the two
new puts at the exit paths release the completing FOD's lookup reference
directly would avoid the extra atomic operations.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125115444.783-1-luob87709@gmail.com?part=1



More information about the Linux-nvme mailing list