All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mohamed Khalfella" <mkhalfella@purestorage.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v7 13/17] nvme-fc: perform error recovery directly from ioerr_work
Date: Sat, 14 Nov 2026 03:31:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-214114@kernel.org> (raw)
In-Reply-To: <20261114030454.2836543-14-mkhalfella@purestorage.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] nvme-fc: race between nvme_fc_ctrl_ioerr_work() and controller
  deletion
- [Low] nvme-fc: unused forward declaration of
  __nvme_fc_abort_outstanding_ios()
--

commit f47f39335cf25a25520dc165768b29ed4e1e01c4
Author: Mohamed Khalfella <mkhalfella@purestorage.com>

nvme-fc: perform error recovery directly from ioerr_work

This commit replaces nvme_fc_error_recovery() with direct association
teardown, controller stop, and reconnect scheduling inside
nvme_fc_ctrl_ioerr_work().

> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index c4603be381445..0ba621649afed 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -229,6 +229,8 @@ static struct device *fc_udev_device;
>  static void nvme_fc_complete_rq(struct request *rq);
>  static void nvme_fc_start_ioerr_recovery(struct nvme_fc_ctrl *ctrl,
>  					 char *errmsg);
> +static void __nvme_fc_abort_outstanding_ios(struct nvme_fc_ctrl *ctrl,
> +					    bool start_queues);

[Severity: Low]
This isn't a bug, but nothing calls __nvme_fc_abort_outstanding_ios()
before its definition now that nvme_fc_error_recovery() is removed, so this
forward declaration is unused.

[ ... ]

> @@ -1880,7 +1883,23 @@ nvme_fc_ctrl_ioerr_work(struct work_struct *work)
>  	struct nvme_fc_ctrl *ctrl =
>  			container_of(work, struct nvme_fc_ctrl, ioerr_work);
>  
> -	nvme_fc_error_recovery(ctrl, "transport detected io error");
> +	nvme_stop_keep_alive(&ctrl->ctrl);
> +	flush_work(&ctrl->ctrl.async_event_work);
> +
> +	/* will block while waiting for io to terminate */
> +	nvme_fc_delete_association(ctrl);
> +	nvme_stop_ctrl(&ctrl->ctrl);
> +
> +	/* Do not reconnect if controller is being deleted */
> +	if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING))
> +		return;
> +
> +	if (ctrl->rport->remoteport.port_state == FC_OBJSTATE_ONLINE) {
> +		queue_delayed_work(nvme_wq, &ctrl->connect_work, 0);
> +		return;
> +	}
> +
> +	nvme_fc_reconnect_or_delete(ctrl, -ENOTCONN);
>  }

[Severity: High]
Can nvme_fc_ctrl_ioerr_work() race with controller deletion and re-arm
ctrl->connect_work after nvme_fc_delete_ctrl() has already canceled it?

Previously, error recovery called nvme_reset_ctrl(), and
nvme_do_delete_ctrl() flushed ctrl->reset_work before calling
nvme_stop_ctrl(), nvme_remove_namespaces(), and ctrl->ops->delete_ctrl().
Unlike rdma and tcp, nvme_fc_ctrl_ops does not implement .stop_ctrl to
flush ioerr_work, and nvme_fc_delete_ctrl() cancels connect_work before
canceling ioerr_work:

drivers/nvme/host/fc.c:nvme_fc_delete_ctrl() {
	...
	cancel_delayed_work_sync(&ctrl->connect_work);
	...
	nvme_fc_delete_association(ctrl);
	cancel_work_sync(&ctrl->ioerr_work);
	...
}

If controller deletion starts right after nvme_fc_ctrl_ioerr_work() moves
the controller to NVME_CTRL_CONNECTING, connect_work can be queued after
cancel_delayed_work_sync(&ctrl->connect_work) has already completed:

CPU0                                    CPU1
nvme_fc_ctrl_ioerr_work()
  ...
  nvme_change_ctrl_state(...,
    NVME_CTRL_CONNECTING)
                                        nvme_delete_ctrl()
                                          nvme_change_ctrl_state(...,
                                            NVME_CTRL_DELETING)
                                          ...
                                          nvme_do_delete_ctrl()
                                            ...
                                            nvme_fc_delete_ctrl()
                                              cancel_delayed_work_sync(
                                                &ctrl->connect_work)
                                              ...
                                              cancel_work_sync(
                                                &ctrl->ioerr_work)
  queue_delayed_work(nvme_wq,
    &ctrl->connect_work, 0)
                                              nvme_remove_io_tag_set()
                                              nvme_remove_admin_tag_set()
                                            nvme_uninit_ctrl()
                                        nvme_fc_connect_ctrl_work()
                                          nvme_fc_create_association()
                                            <-- use-after-free

This leaves connect_work running nvme_fc_create_association() while the
tag sets are torn down and struct nvme_fc_ctrl is freed.

In addition, because nvme_do_delete_ctrl() does not wait for ioerr_work
before calling nvme_remove_namespaces(), nvme_fc_delete_association() in
ioerr_work can run concurrently with nvme_remove_namespaces(), racing on
quiescing and unquiescing the I/O queues while scan_work is flushed and
hardware queues are deleted.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114030454.2836543-1-mkhalfella@purestorage.com?part=13


  reply	other threads:[~2026-11-14  3:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  3:04 [PATCH v7 00/17] TP8028 Rapid Path Failure Recovery Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 01/17] nvmet: Rapid Path Failure Recovery set controller identify fields Mohamed Khalfella
2026-11-14  3:17   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 02/17] nvmet/debugfs: Export controller CIU and CIRN via debugfs Mohamed Khalfella
2026-11-14  3:12   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 03/17] nvmet: Implement CCR nvme command Mohamed Khalfella
2026-11-14  3:30   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 04/17] nvmet: Implement CCR logpage Mohamed Khalfella
2026-11-14  3:20   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 05/17] nvmet: Send an AEN on CCR completion Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 06/17] nvme: Rapid Path Failure Recovery read controller identify fields Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 07/17] nvme: Introduce FENCING and FENCED controller states Mohamed Khalfella
2026-11-14  3:29   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 08/17] nvme: Implement cross-controller reset recovery Mohamed Khalfella
2026-11-14  3:26   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 09/17] nvme: Implement cross-controller reset completion Mohamed Khalfella
2026-11-14  3:29   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 10/17] nvme-tcp: Use CCR to recover controller that hits an error Mohamed Khalfella
2026-11-14  3:38   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 11/17] nvme-rdma: " Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 12/17] nvme-fc: start error recovery instead of aborting timed out IOs Mohamed Khalfella
2026-11-14  3:46   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 13/17] nvme-fc: perform error recovery directly from ioerr_work Mohamed Khalfella
2026-11-14  3:31   ` sashiko-bot [this message]
2026-11-14  3:04 ` [PATCH v7 14/17] nvme-fc: Use CCR to recover controller that hits an error Mohamed Khalfella
2026-11-14  3:38   ` sashiko-bot
2026-11-14  3:04 ` [PATCH v7 15/17] nvme-fc: Hold inflight requests while in FENCING state Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 16/17] nvmet: Add support for CQT to nvme target Mohamed Khalfella
2026-11-14  3:04 ` [PATCH v7 17/17] nvme: Add support for CQT to nvme host Mohamed Khalfella

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=sashiko-outbox-214114@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mkhalfella@purestorage.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.