All of lore.kernel.org
 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 v20 12/13] scsi: ibmvfc: register and use asynchronous sub CRQ for events
Date: Tue, 01 Dec 2026 11:56:52 -0600	[thread overview]
Message-ID: <87jyls995n.fsf@linux.ibm.com> (raw)
In-Reply-To: <sashiko-outbox-241983@kernel.org>

sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] scsi: ibmvfc: NULL dereference on scsi->scrqs in
>   ibmvfc_channel_setup()
> - [Medium] scsi: ibmvfc: stale active_queues and do_enquiry on CRQ reset
>   and re-enable
> --
>
> commit 4e91118011515253d54521b6e51230ef63114d4c
> Author: Dave Marquardt <davemarq@linux.ibm.com>
>
> scsi: ibmvfc: register and use asynchronous sub CRQ for events
>
> This commit wires the asynchronous sub-CRQ into the ibmvfc sub-CRQ
> allocation, registration, channel setup, and teardown lifecycle alongside
> the SCSI and NVMe channel queues.
>
>> diff --git a/drivers/scsi/ibmvscsi/ibmvfc-core.c b/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> index 5e8b25673ff5d..4a67a1a472f22 100644
>> --- a/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> +++ b/drivers/scsi/ibmvscsi/ibmvfc-core.c
> [ ... ]
>> @@ -988,8 +989,20 @@ static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)
>>  	spin_unlock(vhost->crq.q_lock);
>>  	spin_unlock_irqrestore(&vhost->host->host_lock, flags);
>>  
>> -	ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs);
>> -	ibmvfc_reg_sub_crqs(vhost, &vhost->nvme_scrqs);
>> +	if (ibmvfc_reg_sub_crqs(vhost, &vhost->async_scrqs) ||
>> +	    ibmvfc_reg_sub_crqs(vhost, &vhost->scsi_scrqs) ||
>> +	    ibmvfc_reg_sub_crqs(vhost, &vhost->nvme_scrqs)) {
>> +		ibmvfc_dereg_sub_crqs(vhost, &vhost->async_scrqs);
>> +		ibmvfc_dereg_sub_crqs(vhost, &vhost->scsi_scrqs);
>> +		ibmvfc_dereg_sub_crqs(vhost, &vhost->nvme_scrqs);
>> +		spin_lock_irqsave(&vhost->host->host_lock, flags);
>> +		vhost->do_enquiry = 0;
>> +		vhost->mq_enabled = 0;
>> +		vhost->async_scrqs.active_queues = 0;
>> +		vhost->scsi_scrqs.active_queues = 0;
>> +		vhost->nvme_scrqs.active_queues = 0;
>> +		spin_unlock_irqrestore(&vhost->host->host_lock, flags);
>> +	}
>>  
>>  	return rc;
>>  }
>
> [Severity: Medium]
> Does ibmvfc_reenable_crq_queue() (and ibmvfc_reset_crq() below) leave
> active_queues stale when ibmvfc_reg_sub_crqs() succeeds, and re-enable
> vhost->do_enquiry even when vhost->mq_enabled is already 0?
>
> Both functions deregister all sub-CRQs and clear vhost->using_channels = 0
> under host_lock, but only zero active_queues if ibmvfc_reg_sub_crqs()
> fails.  While vhost->using_channels is 0—or permanently after migration to
> a VIOS that does not advertise IBMVFC_CAN_SUPPORT_CHANNELS—callers that
> test only active_queues (such as ibmvfc_nvme_active() and
> ibmvfc_nvme_create_queue()) will see non-zero active_queues with stale
> vios_cookie handles.
>
> In addition, both functions set vhost->do_enquiry = 1 unconditionally
> before calling ibmvfc_reg_sub_crqs().  Because ibmvfc_reg_sub_crqs()
> returns 0 immediately when vhost->mq_enabled is 0, a prior registration
> failure that cleared vhost->mq_enabled = 0 causes the error block to be
> skipped, leaving vhost->do_enquiry = 1 with no sub-CRQs allocated or
> registered.
>
> Resetting active_queues alongside vhost->using_channels = 0 and setting
> vhost->do_enquiry = vhost->mq_enabled under host_lock in both functions
> would avoid both issues.

Agreed on the first point. After a successful re-register, active_queues
keeps its old value until the next channel setup, and
ibmvfc_nvme_create_queue() tests only that field. v21 zeroes the async,
SCS I and NVMe counts under host_lock next to using_channels = 0 in both
ibmvfc_reenable_crq_queue() and i bmvfc_reset_crq(). The other readers
are already guarded by using_channels, and queuecommand holds hos
t_lock, so there's no race with the new zeroing.

I'm not changing do_enquiry. With mq_enabled == 0 the login doesn't
advertise CAN_USE_CHANNELS, so the VIOS doesn't return SUPPORT_CHANNELS,
and ibmvfc_npiv_login_done() takes the non-channel branch and clears
do_enquiry itself. Probe leaves the same state when the mq module
parameter is 0. Gating it on mq_enabled would behave the same.

> [ ... ]
>
>> @@ -5925,12 +5954,19 @@ static void ibmvfc_channel_setup_done(struct ibmvfc_event *evt)
>>  		ibmvfc_dbg(vhost, "Channel Setup succeeded\n");
>>  		flags = be32_to_cpu(setup->flags);
>>  		vhost->do_enquiry = 0;
>> -		scsi->active_queues = be32_to_cpu(setup->num_scsi_subq_channels);
>> -		nvme->active_queues = be32_to_cpu(setup->num_nvme_subq_channels);
>> +		scsi->active_queues = min(be32_to_cpu(setup->num_scsi_subq_channels),
>> +					  scsi->max_queues);
>> +		nvme->active_queues = nvme->scrqs ?
>> +			min(be32_to_cpu(setup->num_nvme_subq_channels),
>> +			    nvme->max_queues) : 0;
>> +		async->active_queues = (async->scrqs && setup->async_sub_crq_handle) ? 1 : 0;
>>  
>>  		if (flags & IBMVFC_CHANNELS_CANCELED) {
>>  			ibmvfc_dbg(vhost, "Channels Canceled\n");
>>  			vhost->using_channels = 0;
>> +			scsi->active_queues = 0;
>> +			nvme->active_queues = 0;
>> +			async->active_queues = 0;
>>  			break;
>>  		}
>>  
>> @@ -5942,6 +5978,8 @@ static void ibmvfc_channel_setup_done(struct ibmvfc_event *evt)
>>  		for (i = 0; i < nvme->active_queues; i++)
>>  			nvme->scrqs[i].vios_cookie =
>>  				be64_to_cpu(setup->channel_handles[scsi->active_queues + i]);
>> +		for (i = 0; i < async->active_queues; i++)
>> +			async->scrqs[i].vios_cookie = be64_to_cpu(setup->async_sub_crq_handle);
>>  
>>  		ibmvfc_dbg(vhost, "Using %u SCSI channels\n",
>>  			   scsi->active_queues);
>> @@ -5976,10 +6014,11 @@ static void ibmvfc_channel_setup(struct ibmvfc_host *vhost)
>>  	struct ibmvfc_event *evt = ibmvfc_get_reserved_event(&vhost->crq);
>>  	struct ibmvfc_channels *scsi = &vhost->scsi_scrqs;
>>  	struct ibmvfc_channels *nvme = &vhost->nvme_scrqs;
>> +	struct ibmvfc_channels *async = &vhost->async_scrqs;
>>  	unsigned int scsi_channels =
>>  		min(scsi->desired_queues, vhost->max_vios_scsi_channels);
>> -	unsigned int nvme_channels =
>> -		min(nvme->desired_queues, vhost->max_vios_nvme_channels);
>> +	unsigned int nvme_channels = nvme->scrqs ?
>> +		min(nvme->desired_queues, vhost->max_vios_nvme_channels) : 0;
>>  	int level = IBMVFC_DEFAULT_LOG_LEVEL;
>>  	int i;
>>  
>> @@ -6003,6 +6042,9 @@ static void ibmvfc_channel_setup(struct ibmvfc_host *vhost)
>>  				cpu_to_be64(nvme->scrqs[i].cookie);
>>  	}
>>  
>> +	if (async->scrqs)
>> +		setup_buf->async_sub_crq_handle = cpu_to_be64(async->scrqs[0].cookie);
>
> [Severity: High]
> Can ibmvfc_channel_setup() and ibmvfc_channel_setup_done() dereference a
> NULL scsi->scrqs pointer when mq_enabled is 0?
>
> In ibmvfc_probe(), scsi->desired_queues and scsi->max_queues are
> initialized to at least 1 and vhost->do_enquiry is set to 1 even when
> mq_enabled is 0, while ibmvfc_init_sub_crqs() returns early without
> allocating scsi->scrqs.  When ibmvfc_channel_setup() and
> ibmvfc_channel_setup_done() run, nvme->scrqs and async->scrqs are checked
> for NULL, but scsi_channels and scsi->active_queues are computed without
> checking scsi->scrqs, leading to a NULL pointer dereference on
> scsi->scrqs[i].cookie and scsi->scrqs[i].vios_cookie.

ibmvfc_channel_setup() is only reached from
ibmvfc_channel_enquiry_done(), which is only started from
ibmvfc_npiv_login_done() when the login response has
IBMVFC_CAN_SUPPORT_CHANNELS. The VIOS sets that only if the client
advertised IBMVFC_CAN_USE_CHANNELS, and ibmvfc_set_login_info() does
that only when mq_enabled (or using_channels) is set. Every path that
leaves scsi->scrqs NULL also clears mq_enabled, so with mq_enabled == 0
the login doesn't request channels and ibmvfc_npiv_login_done() takes
the n on-channel branch, which clears do_enquiry. That is why the NVMe
and async sets need the NULL checks (they can be absent while channels
are granted) and the SCSI set doesn't. The unguarded scsi->scrqs[i]
loops are unchanged from the base.

-Dave

  reply	other threads:[~2026-12-01 17:56 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 21:00 [PATCH v20 00/13] scsi: ibmvfc: make ibmvfc support FPIN messages Dave Marquardt
2026-11-30 21:00 ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 01/13] scsi: ibmvfc: fix IRQ leak and guard deregister on channel reg failure Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 02/13] scsi: ibmvfc: fix potential clobbering of rc after failed irq setup Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 03/13] scsi: ibmvfc: fix potential NULL pointer dereference on failed queue allocation Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:08   ` sashiko-bot
2026-11-30 22:54     ` Dave Marquardt
2026-11-30 21:00 ` [PATCH v20 04/13] scsi: ibmvfc: fix stale rc and IRQ mapping leak in ibmvfc_register_channel() Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 05/13] scsi: ibmvfc: fix resource leaks on partial queue allocation failure Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 06/13] scsi: ibmvfc: add basic FPIN support Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 07/13] scsi: ibmvfc: add NOOP command support Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 08/13] scsi: ibmvfc: add FPIN extended flag and async sub-CRQ queue handle Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 09/13] scsi: ibmvfc: extend async event handlers for async sub-CRQ events Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 10/13] scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 11/13] scsi: ibmvfc: extend channel registration for async sub-CRQ Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:00 ` [PATCH v20 12/13] scsi: ibmvfc: register and use asynchronous sub CRQ for events Dave Marquardt
2026-11-30 21:00   ` Dave Marquardt via B4 Relay
2026-11-30 21:23   ` sashiko-bot
2026-12-01 17:56     ` Dave Marquardt [this message]
2026-11-30 21:00 ` [PATCH v20 13/13] scsi: ibmvfc: handle extended FPIN events Dave Marquardt
2026-11-30 21:00   ` 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=87jyls995n.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 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.