public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 0/5] nvme-fc: misc small improvents
@ 2025-10-28 15:26 Daniel Wagner
  2025-10-28 15:26 ` [PATCH 1/5] nvme-fc: don't hold rport lock when putting ctrl Daniel Wagner
                   ` (4 more replies)
  0 siblings, 5 replies; 23+ messages in thread
From: Daniel Wagner @ 2025-10-28 15:26 UTC (permalink / raw)
  To: Justin Tee, Christoph Hellwig, Keith Busch
  Cc: James Smart, Jens Axboe, linux-nvme, linux-kernel, Daniel Wagner

I've collected a bunch of patches from the last debugging session. I think it's
worth documenting which conditions are expected in the cleanup path by adding a
bunch of WARNs.

Also found a deadlock in the nvme-fc code, so this one should definitly go in.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
---
Daniel Wagner (5):
      nvme-fc: don't hold rport lock when putting ctrl
      nvme-fc: check all request and response have been processed
      nvmet-fcloop: check all request and response have been processed
      nvmet-fcloop: remove unused lsdir member.
      nvmet-fc: use pr_* print macros instead of dev_*

 drivers/nvme/host/fc.c       |  4 ++++
 drivers/nvme/target/fc.c     | 48 +++++++++++++++++++-------------------------
 drivers/nvme/target/fcloop.c |  9 ++++++---
 3 files changed, 31 insertions(+), 30 deletions(-)
---
base-commit: 77a4fe6a06e265bd94d2b3cdc87fb3cde877a05b
change-id: 20251028-nvmet-fcloop-fixes-4e57e82f1f15

Best regards,
-- 
Daniel Wagner <wagi@kernel.org>



^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: [PATCH 1/5] nvme-fc: don't hold rport lock when putting ctrl
@ 2025-10-29  0:33 Justin Tee
  2025-10-29 10:05 ` Daniel Wagner
  2025-10-30  9:49 ` Daniel Wagner
  0 siblings, 2 replies; 23+ messages in thread
From: Justin Tee @ 2025-10-29  0:33 UTC (permalink / raw)
  To: Daniel Wagner
  Cc: Christoph Hellwig, Keith Busch, James Smart, Jens Axboe,
	linux-nvme, LKML, Justin Tee

Hi Daniel,

> 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.

While I agree that we can’t hold the rport lock when calling
nvme_fc_ctrl_put, nvme_fc_ctrl_free also does a nvme_fc_rport_put,
which could also trigger nvme_fc_free_rport, making rport invalid.
Should we also add kref get on the rport before entering the
list_for_each_entry loop?

Also, because nvme_fc_ctrl_free removes itself from the
rport->ctrl_list, should we also start using list_for_each_entry_safe?

So, something like this?

diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 03987f497a5b..fcd30801921b 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -1468,14 +1468,16 @@ nvme_fc_match_disconn_ls(struct nvme_fc_rport *rport,
 {
        struct fcnvme_ls_disconnect_assoc_rqst *rqst =
                                        &lsop->rqstbuf->rq_dis_assoc;
-       struct nvme_fc_ctrl *ctrl, *ret = NULL;
+       struct nvme_fc_ctrl *ctrl, *tmp, *ret = NULL;
        struct nvmefc_ls_rcv_op *oldls = NULL;
        u64 association_id = be64_to_cpu(rqst->associd.association_id);
        unsigned long flags;

+       nvme_fc_rport_get(rport);
+
        spin_lock_irqsave(&rport->lock, flags);

-       list_for_each_entry(ctrl, &rport->ctrl_list, ctrl_list) {
+       list_for_each_entry_safe(ctrl, tmp, &rport->ctrl_list, ctrl_list) {
                if (!nvme_fc_ctrl_get(ctrl))
                        continue;
                spin_lock(&ctrl->lock);
@@ -1488,11 +1490,15 @@ 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);

+       nvme_fc_rport_put(rport);
+
        /* transmit a response for anything that was pending */
        if (oldls) {
                dev_info(rport->lport->dev,

Regards,
Justin


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2025-11-04 12:32 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
  -- strict thread matches above, loose matches on Subject: below --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox