All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tyrel Datwyler" <tyreld@linux.ibm.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 02/33] ibmvfc: flush rport_add_work_q during driver teardown
Date: Thu, 23 Jul 2026 00:35:00 +0000	[thread overview]
Message-ID: <20260723003500.D32951F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723000149.969416-3-tyreld@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [High] The patch incorrectly assumes all events with `!evt->cmnd` are MAD events, assigning an uninitialized `evt->_done` pointer to `evt->done` for TMF events, causing a kernel panic or deadlock.

Pre-existing issues:
- [High] The error path in `ibmvfc_probe()` lacks a `cancel_work_sync()` or `flush_work()` for `vhost->rport_add_work_q`, leading to a workqueue leak and a use-after-free.
- [High] Target objects allocated from `vhost->tgt_pool` are improperly freed using `kfree()` instead of `mempool_free()`, permanently depleting the mempool's reserves.
- [High] In `ibmvfc_cancel_all_mq()`, the return value of `ibmvfc_send_event()` is ignored. If sending fails with `H_CLOSED`, the event is freed internally but the caller adds it to a wait list, causing a use-after-free and an indefinite hang.
--

--- Patch [2]: [PATCH v2 02/33] ibmvfc: flush rport_add_work_q during driver teardown ---
commit 17edf5c871930177f3e5dcc29059e768abdcd3dd
Author: Tyrel Datwyler <tyreld@linux.ibm.com>

    ibmvfc: flush rport_add_work_q during driver teardown
    
    INIT_WORK is called on rport_add_work_q during driver probe. When the
    adapter is removed, ibmvfc_remove() stops the work thread and proceeds
    to tear down the FC host, but any work item queued via schedule_work()
    that raced the teardown could still be running or pending in the
    system workqueue.
    
    Add a flush_work() call after kthread_stop() and before fc_remove_host()
    to drain any outstanding rport add work before the FC host and its rports
    are torn down.

> diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
> index 0a5f73df8d7d2..72317d7840a53 100644
> --- a/drivers/scsi/ibmvscsi/ibmvfc.c
> +++ b/drivers/scsi/ibmvscsi/ibmvfc.c
> @@ -6443,6 +6443,7 @@ static void ibmvfc_remove(struct vio_dev *vdev)
>  
>  	ibmvfc_wait_while_resetting(vhost);
>  	kthread_stop(vhost->work_thread);
> +	flush_work(&vhost->rport_add_work_q);
>  	fc_remove_host(vhost->host);
>  	scsi_remove_host(vhost->host);

[Severity: High]
This isn't a bug introduced by this patch, but does ibmvfc_probe() also need 
a similar flush_work() or cancel_work_sync() in its error path?

If ibmvfc_probe() fails after starting the kthread and initializing the CRQ 
(for example, if scsi_add_host() fails), it stops the kthread and frees the
host memory:

kill_kthread:
	kthread_stop(vhost->work_thread);
free_host_mem:
	ibmvfc_free_mem(vhost);
free_scsi_host:
	scsi_host_put(shost);

If the CRQ initialization has already received an interrupt, transitioned the
host state, and scheduled rport_add_work_q on the system workqueue, wouldn't
ibmvfc_rport_add_thread() execute after the vhost structure has been freed,
causing a use-after-free?

[ ... ]

> @@ -1367,8 +1367,8 @@ static void ibmvfc_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
>  static void ibmvfc_release_tgt(struct kref *kref)
>  {
>  	struct ibmvfc_target *tgt = container_of(kref, struct ibmvfc_target, kref);
>  	kfree(tgt);
>  }

[Severity: High]
This isn't a bug introduced by this patch, but does ibmvfc_release_tgt()
permanently deplete the tgt_pool mempool reserves?

Target structures are allocated from a mempool in ibmvfc_alloc_target():

	tgt = mempool_alloc(vhost->tgt_pool, GFP_NOIO);

However, ibmvfc_release_tgt() frees them directly using kfree(). While the
memory is returned to the slab allocator, bypassing mempool_free() means the
mempool's internal reserve count is never replenished.

Could this permanently deplete the mempool's preallocated reserves and lead
to allocation failures or device discovery hangs under memory pressure?

[ ... ]

> @@ -1591,8 +1591,8 @@ static void ibmvfc_init_event(struct ibmvfc_event *evt,
>  {
>  	evt->cmnd = NULL;
>  	evt->sync_iu = NULL;
>  	evt->eh_comp = NULL;
>  	evt->crq.format = format;
>  	if (format == IBMVFC_CMD_FORMAT)
>  		evt->done = done;
>  	else {
>  		evt->_done = done;

[ ... ]

> @@ -1774,9 +1774,9 @@ static int ibmvfc_send_event(struct ibmvfc_event *evt,
>  		if (evt->cmnd) {
>  			evt->cmnd->result = DID_ERROR << 16;
>  			evt->done = ibmvfc_scsi_eh_done;
>  		} else {
>  			evt->xfer_iu->mad_common.status = cpu_to_be16(IBMVFC_MAD_CRQ_ERROR);
>  			evt->done = evt->_done;
>  		}
>  
>  		evt->done(evt);

[Severity: High]
Does this else branch in ibmvfc_send_event() correctly handle Task
Management Function (TMF) events?

TMF events use the IBMVFC_CMD_FORMAT format and have evt->cmnd = NULL.
When ibmvfc_init_event() initializes a CMD format event, it explicitly leaves
evt->_done uninitialized.

If ibmvfc_send_event() encounters an error sending a TMF event, it evaluates
!evt->cmnd, enters the else branch, and assigns evt->done = evt->_done.

Could this execute an uninitialized or stale callback?

[ ... ]

> @@ -2630,8 +2630,8 @@ static int ibmvfc_cancel_all_mq(struct scsi_device *sdev, int type)
>  			}
>  			evt->sync_iu = &queues[i].cancel_rsp;
>  			ibmvfc_send_event(evt, vhost, default_timeout);
>  			list_add_tail(&evt->cancel, &cancelq);
>  		}
>  
>  		spin_unlock(queues[i].q_lock);
>  	}
>  	spin_unlock_irqrestore(vhost->host->host_lock, flags);
>  
>  	if (list_empty(&cancelq)) {
>  		if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
>  			sdev_printk(KERN_INFO, sdev, "No events found to cancel\n");
>  		return 0;
>  	}
>  
>  	sdev_printk(KERN_INFO, sdev, "Cancelling outstanding commands.\n");
>  
>  	list_for_each_entry_safe(evt, temp, &cancelq, cancel) {
>  		wait_for_completion(&evt->comp);

[Severity: High]
This isn't a bug introduced by this patch, but does ibmvfc_cancel_all_mq() 
hang indefinitely if ibmvfc_send_event() fails with H_CLOSED?

If ibmvfc_send_event() returns H_CLOSED, it returns SCSI_MLQUEUE_HOST_BUSY 
and frees the event via ibmvfc_free_event().

However, ibmvfc_cancel_all_mq() ignores the return value of 
ibmvfc_send_event(). It unconditionally proceeds to call 
list_add_tail(&evt->cancel, &cancelq) on the now-freed event and 
subsequently loops over the cancelq list calling 
wait_for_completion(&evt->comp). 

Could this cause a use-after-free and an indefinite hang since the completion
object resides in freed memory and will never be signaled?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723000149.969416-1-tyreld@linux.ibm.com?part=2

  reply	other threads:[~2026-07-23  0:35 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23  0:01 [PATCH v2 00/33] ibmvfc: NVMe/FC support over IBM Virtual FC Tyrel Datwyler
2026-07-23  0:01 ` [PATCH v2 01/33] ibmvfc: don't call locked done variant for MADs on send failure Tyrel Datwyler
2026-07-23  0:42   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 02/33] ibmvfc: flush rport_add_work_q during driver teardown Tyrel Datwyler
2026-07-23  0:35   ` sashiko-bot [this message]
2026-07-23  0:01 ` [PATCH v2 03/33] ibmvfc: check for NULL evt in implicit LOGO and target delete path Tyrel Datwyler
2026-07-23  0:30   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 04/33] ibmvfc: free ibmvfc_target allocations with mempool_free Tyrel Datwyler
2026-07-23  0:01 ` [PATCH v2 05/33] ibmvfc: move target list from host to protocol specific channel groups Tyrel Datwyler
2026-07-23  0:34   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 06/33] ibmvfc: add NVMe/FC protocol interface definitions Tyrel Datwyler
2026-07-23  0:28   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 07/33] ibmvfc: split NVMe support into separate source file and add transport stubs Tyrel Datwyler
2026-07-23  0:22   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 08/33] ibmvfc: initialize NVMe channel configuration during driver probe Tyrel Datwyler
2026-07-23  0:21   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 09/33] ibmvfc: alloc/dealloc sub-queues for nvme channels Tyrel Datwyler
2026-07-23  0:33   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 10/33] ibmvfc: add logic for protocol specific fabric logins Tyrel Datwyler
2026-07-23  0:28   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 11/33] ibmvfc: add wrapper to get vhost associated with a channel struct Tyrel Datwyler
2026-07-23  0:01 ` [PATCH v2 12/33] ibmvfc: add helper for creating protocol specific discovery event Tyrel Datwyler
2026-07-23  0:01 ` [PATCH v2 13/33] ibmvfc: add helper to check NVMe/FC support with active channels Tyrel Datwyler
2026-07-23  0:17   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 14/33] ibmvfc: allocate and free NVMe channel group discover buffer Tyrel Datwyler
2026-07-23  0:01 ` [PATCH v2 15/33] ibmvfc: send NVMe target discovery MAD Tyrel Datwyler
2026-07-23  0:31   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 16/33] ibmvfc: add NVMe/FC Implicit Logout and Move Login support Tyrel Datwyler
2026-07-23  0:36   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 17/33] ibmvfc: add NVMe/FC Port " Tyrel Datwyler
2026-07-23  0:38   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 18/33] ibmvfc: add NVMe/FC Process " Tyrel Datwyler
2026-07-23  0:39   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 19/33] ibmvfc: add NVMe/FC Query Target support Tyrel Datwyler
2026-07-23  0:50   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 20/33] ibmvfc: allocate targets based on protocol Tyrel Datwyler
2026-07-23  0:43   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 21/33] ibmvfc: delete NVMe/FC targets as well as SCSI Tyrel Datwyler
2026-07-23  0:52   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 22/33] ibmvfc: update state machine to process NVMe/FC targets Tyrel Datwyler
2026-07-23  0:53   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 23/33] ibmvfc: implement NVMe/FC stubs for local/remote port registration Tyrel Datwyler
2026-07-23  0:54   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 24/33] ibmvfc: register local nvme fc port after fabric login Tyrel Datwyler
2026-07-23  0:53   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 25/33] ibmvfc: process NVMe/FC rports in work thread Tyrel Datwyler
2026-07-23  0:50   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 26/33] ibmvfc: extend ibmvfc_debug visibility to ibmvfc-nvme.h Tyrel Datwyler
2026-07-23  0:42   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 27/33] ibmvfc: declare global function definitions Tyrel Datwyler
2026-07-23  0:01 ` [PATCH v2 28/33] ibmvfc: implement LLDD callbacks for mapping nvme-fc queues Tyrel Datwyler
2026-07-23  0:58   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 29/33] ibmvfc: implement nvme-fc LS submission transport callback Tyrel Datwyler
2026-07-23  1:00   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 30/33] ibmvfc: implement nvme-fc IO command submission callback Tyrel Datwyler
2026-07-23  1:08   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 31/33] ibmvfc: implement nvme-fc LS abort handling callback Tyrel Datwyler
2026-07-23  1:05   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 32/33] ibmvfc: implement nvme-fc FCP abort callback Tyrel Datwyler
2026-07-23  1:05   ` sashiko-bot
2026-07-23  0:01 ` [PATCH v2 33/33] ibmvfc: fail nvme-fc fcp-io and ls requests during transport reset Tyrel Datwyler
2026-07-23  0:58   ` sashiko-bot

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=20260723003500.D32951F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tyreld@linux.ibm.com \
    /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.