Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Dave Marquardt <davemarq@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v7 5/8] scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ
Date: Thu, 03 Sep 2026 11:18:08 -0500	[thread overview]
Message-ID: <87a4py5mwv.fsf@linux.ibm.com> (raw)
In-Reply-To: <20260831221836.C605B1F000E9@smtp.kernel.org>

sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] The `ibmvfc_drain_async_subq()` function calls
> `ibmvfc_handle_async()` without holding the primary SCSI host lock
> (`vhost->host->host_lock`). This leads to severe data races and list
> corruption because `ibmvfc_handle_async()` mutates shared state and
> iterates over lists that are concurrently modified by other threads
> holding the lock.
> --
>
> commit d6b23b1e849e5108314e933b9d7ab6b8580d0218
> Author: Dave Marquardt <davemarq@linux.ibm.com>
>
> scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ
>
> Add ibmvfc_interrupt_async_subq(), an IRQ handler dedicated to
> asynchronous sub-CRQ events from the adapter. The handler disables
> the sub-CRQ IRQ and then calls ibmvfc_drain_async_subq() to consume
> all pending entries before re-enabling interrupts.
>
>> diff --git a/drivers/scsi/ibmvscsi/ibmvfc-core.c b/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> index 229b06effd4cf..a28875c1f9830 100644
>> --- a/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> +++ b/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> @@ -4369,6 +4369,56 @@ static struct ibmvfc_crq *ibmvfc_next_scrq(struct ibmvfc_queue *scrq)
>>  	return crq;
>>  }
>>  
>> +static void ibmvfc_drain_async_subq(struct ibmvfc_queue *scrq)
>> +{
>> +	struct ibmvfc_crq *crq;
>> +	int done = 0;
>> +
>> +	spin_lock(scrq->q_lock);
>> +	while (!done) {
>> +		while ((crq = ibmvfc_next_scrq(scrq)) != NULL) {
>> +			struct ibmvfc_async_crq_event ae = {
>> +				.type = IBMVFC_ASYNC_CRQ_SUB,
>> +				.subq = *(struct ibmvfc_async_sub_crq *)crq,
>> +			};
>> +			ibmvfc_handle_async(&ae, scrq->vhost);
>
> [Severity: High]
> Does this code need to hold the host_lock before calling ibmvfc_handle_async()?
>
> Calling ibmvfc_handle_async() with only the local queue lock (scrq->q_lock)
> held can lead to unprotected list iterations:
>
> drivers/scsi/ibmvscsi/ibmvfc-core.c:ibmvfc_handle_async() {
>     ...
> 		list_for_each_entry(tgt, &vhost->scsi_scrqs.targets, queue) {
>     ...
> }
>
> It can also lead to unprotected read-modify-write operations on shared state:
>
> drivers/scsi/ibmvscsi/ibmvfc-core.c:ibmvfc_handle_async() {
>     ...
> 			vhost->events_to_log |= IBMVFC_AE_LINKUP;
>     ...
> }
>
> If it races with normal target initialization, addition, or removal routines
> running on other CPUs holding the host_lock, could it result in list corruption
> or use-after-free?

I agree. Adding use of host lock in next revision.

>> +			crq->valid = 0;
>> +			wmb();	/* complete write */
>> +		}
>> +
>> +		ibmvfc_toggle_scrq_irq(scrq, 1);
>> +		crq = ibmvfc_next_scrq(scrq);
>> +		if (crq != NULL) {
>> +			struct ibmvfc_async_crq_event ae = {
>> +				.type = IBMVFC_ASYNC_CRQ_SUB,
>> +				.subq = *(struct ibmvfc_async_sub_crq *)crq,
>> +			};
>> +			ibmvfc_toggle_scrq_irq(scrq, 0);
>> +			ibmvfc_handle_async(&ae, scrq->vhost);
>
> [Severity: High]
> Does this call to ibmvfc_handle_async() also need the host_lock for the same
> reasons as above?
>
>> +			crq->valid = 0;
>> +			wmb();	/* complete write */
>> +		} else
>> +			done = 1;
>> +	}
>> +	spin_unlock(scrq->q_lock);
>> +}

Yes.

-Dave

  reply	other threads:[~2026-09-03 16:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 19:00 [PATCH v7 0/8] scsi: ibmvfc: make ibmvfc support FPIN messages Dave Marquardt via B4 Relay
2026-08-31 19:00 ` [PATCH v7 1/8] scsi: ibmvfc: add basic FPIN support Dave Marquardt via B4 Relay
2026-08-31 21:30   ` sashiko-bot
2026-09-02 20:29     ` Dave Marquardt
2026-09-02 21:59     ` Dave Marquardt
2026-08-31 19:00 ` [PATCH v7 2/8] scsi: ibmvfc: Add NOOP command support Dave Marquardt via B4 Relay
2026-08-31 21:40   ` sashiko-bot
2026-09-03 15:08     ` Dave Marquardt
2026-08-31 19:00 ` [PATCH v7 3/8] scsi: ibmvfc: add FPIN extended flag and async sub-CRQ queue handle Dave Marquardt via B4 Relay
2026-08-31 19:00 ` [PATCH v7 4/8] scsi: ibmvfc: extend async event handlers to handle async sub queue events Dave Marquardt via B4 Relay
2026-08-31 19:00 ` [PATCH v7 5/8] scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ Dave Marquardt via B4 Relay
2026-08-31 22:18   ` sashiko-bot
2026-09-03 16:18     ` Dave Marquardt [this message]
2026-08-31 19:00 ` [PATCH v7 6/8] scsi: ibmvfc: extend channel registration and deregistration for async subq Dave Marquardt via B4 Relay
2026-08-31 22:34   ` sashiko-bot
2026-09-03 18:43     ` Dave Marquardt
2026-08-31 19:00 ` [PATCH v7 7/8] scsi: ibmvfc: register and use asynchronous sub CRQ for events Dave Marquardt via B4 Relay
2026-08-31 22:46   ` sashiko-bot
2026-08-31 19:00 ` [PATCH v7 8/8] scsi: ibmvfc: handle extended FPIN events Dave Marquardt via B4 Relay
2026-08-31 22:56   ` 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=87a4py5mwv.fsf@linux.ibm.com \
    --to=davemarq@linux.ibm.com \
    --cc=linux-scsi@vger.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