Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Dave Marquardt <davemarq@linux.ibm.com>
To: sashiko-bot@kernel.org
Cc: sashiko-reviews@lists.linux.dev, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v15 04/11] scsi: ibmvfc: add basic FPIN support
Date: Tue, 20 Oct 2026 10:49:49 -0500	[thread overview]
Message-ID: <87bj8ol6ci.fsf@linux.ibm.com> (raw)
In-Reply-To: <sashiko-outbox-178325@kernel.org> (sashiko-bot@kernel.org's message of "Mon, 19 Oct 2026 22:35:19 +0000")

sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] scsi: ibmvfc: wrong fpin_workq teardown order in ibmvfc_probe() error path
> --
>
> commit f3dce48358b69cb9e305579053b02a88579e0f88
> Author: Dave Marquardt <davemarq@linux.ibm.com>
>
> scsi: ibmvfc: add basic FPIN support
>
> This commit adds basic Fabric Performance Impact Notification (FPIN)
> support to the ibmvfc driver by offloading IBMVFC_AE_FPIN async events to
> a per-adapter ordered workqueue, converting VIOS FPIN messages into
> fc_els_fpin structures for fc_host_fpin_rcv(), and adding KUnit test
> coverage.
>
>> diff --git a/drivers/scsi/ibmvscsi/ibmvfc-core.c b/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> index 0fe6b6f4260ba..0750e722c46c5 100644
>> --- a/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> +++ b/drivers/scsi/ibmvscsi/ibmvfc-core.c
>
> [ ... ]
>
>> @@ -6898,9 +7169,15 @@ static int ibmvfc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
>>  	INIT_WORK(&vhost->rport_add_work_q, ibmvfc_rport_add_thread);
>>  	mutex_init(&vhost->passthru_mutex);
>>  
>> -	if ((rc = ibmvfc_alloc_mem(vhost)))
>> +	vhost->fpin_workq = alloc_ordered_workqueue("%s-fpin-workq-%u", 0,
>> +						    IBMVFC_NAME, shost->host_no);
>> +	if (!vhost->fpin_workq)
>>  		goto free_scsi_host;
>>  
>> +	rc = ibmvfc_alloc_mem(vhost);
>> +	if (rc)
>> +		goto free_workq;
>> +
>>  	vhost->work_thread = kthread_run(ibmvfc_work, vhost, "%s_%d", IBMVFC_NAME,
>>  					 shost->host_no);
>>  
>> @@ -6946,6 +7223,8 @@ static int ibmvfc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
>>  	kthread_stop(vhost->work_thread);
>>  free_host_mem:
>>  	ibmvfc_free_mem(vhost);
>> +free_workq:
>> +	destroy_workqueue(vhost->fpin_workq);
>>  free_scsi_host:
>>  	scsi_host_put(shost);
>>  out:
>
> [Severity: High]
> Can the error unwind order in ibmvfc_probe() cause a use-after-free of
> vhost->tgt_pool?
>
> In ibmvfc_remove(), destroy_workqueue(vhost->fpin_workq) is called after
> ibmvfc_release_crq_queue(vhost) and before ibmvfc_free_mem(vhost):
>
>     ibmvfc_release_crq_queue(vhost);
>     destroy_workqueue(vhost->fpin_workq);
>
>     ibmvfc_free_mem(vhost);
>
> As described in the commit message, this ordering ensures that queued FPIN
> work items are drained before ibmvfc_free_mem() destroys vhost->tgt_pool.
>
> In ibmvfc_probe(), however, vhost->fpin_workq is allocated before
> ibmvfc_alloc_mem(vhost), so the error unwind path runs ibmvfc_free_mem()
> before destroy_workqueue(vhost->fpin_workq):
>
>     release_crq:
>         ibmvfc_release_crq_queue(vhost);
>     kill_kthread:
>         kthread_stop(vhost->work_thread);
>     free_host_mem:
>         ibmvfc_free_mem(vhost);
>     free_workq:
>         destroy_workqueue(vhost->fpin_workq);
>
> Because vhost->work_thread is started and ibmvfc_init_crq() registers the
> CRQ and enables interrupts before scsi_add_host() and
> ibmvfc_create_trace_file() are called, a partner-initiated CRQ handshake
> and subsequent IBMVFC_AE_FPIN event can queue ibmvfc_process_async_work()
> on vhost->fpin_workq before scsi_add_host() or ibmvfc_create_trace_file()
> fails.
>
> If that happens, ibmvfc_free_mem() will call
> mempool_destroy(vhost->tgt_pool) while ibmvfc_process_async_work() is
> still running or pending, and ibmvfc_process_async_work() ->
> kref_put(&tgt->kref, ibmvfc_release_tgt) ->
> mempool_free(tgt, tgt->vhost->tgt_pool) will access the destroyed
> tgt_pool.
>
> Should vhost->fpin_workq be allocated after ibmvfc_alloc_mem(vhost) (or
> destroyed before ibmvfc_free_mem(vhost) on the error path) to match the
> teardown order in ibmvfc_remove()?

Yes. I'll change the teardown order to match the teardown order in
ibmvfc_remove().

-Dave

  reply	other threads:[~2026-10-20 15:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 22:15 [PATCH v15 00/11] scsi: ibmvfc: make ibmvfc support FPIN messages Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 01/11] scsi: ibmvfc: fix IRQ leak and guard deregister on channel reg failure Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 02/11] scsi: ibmvfc: fix potential clobbering of rc after failed irq setup Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 03/11] scsi: ibmvfc: fix potential NULL pointer dereference on failed queue allocation Dave Marquardt via B4 Relay
2026-10-19 22:29   ` sashiko-bot
2026-10-20 14:26     ` Dave Marquardt
2026-10-19 22:15 ` [PATCH v15 04/11] scsi: ibmvfc: add basic FPIN support Dave Marquardt via B4 Relay
2026-10-19 22:35   ` sashiko-bot
2026-10-20 15:49     ` Dave Marquardt [this message]
2026-10-19 22:15 ` [PATCH v15 05/11] scsi: ibmvfc: add NOOP command support Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 06/11] scsi: ibmvfc: add FPIN extended flag and async sub-CRQ queue handle Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 07/11] scsi: ibmvfc: extend async event handlers for async sub-CRQ events Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 08/11] scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 09/11] scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 10/11] scsi: ibmvfc: register and use asynchronous sub CRQ for events Dave Marquardt via B4 Relay
2026-10-19 22:26   ` sashiko-bot
2026-10-19 22:15 ` [PATCH v15 11/11] scsi: ibmvfc: handle extended FPIN events Dave Marquardt via B4 Relay

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=87bj8ol6ci.fsf@linux.ibm.com \
    --to=davemarq@linux.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-bot@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox