All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dave Marquardt" <davemarq@linux.ibm.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v20 12/13] scsi: ibmvfc: register and use asynchronous sub CRQ for events
Date: Mon, 30 Nov 2026 21:23:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-241983@kernel.org> (raw)
In-Reply-To: <20261130-ibmvfc-fpin-support-v20-12-50beb6e4b62a@linux.ibm.com>

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.

[ ... ]

> @@ -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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-ibmvfc-fpin-support-v20-0-50beb6e4b62a@linux.ibm.com?part=12

  reply	other threads:[~2026-11-30 21:23 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 via B4 Relay
2026-11-30 21:00 ` Dave Marquardt
2026-11-30 21:00 ` [PATCH v20 01/13] scsi: ibmvfc: fix IRQ leak and guard deregister on channel reg failure Dave Marquardt via B4 Relay
2026-11-30 21:00   ` Dave Marquardt
2026-11-30 21:00 ` [PATCH v20 02/13] scsi: ibmvfc: fix potential clobbering of rc after failed irq setup Dave Marquardt via B4 Relay
2026-11-30 21:00   ` Dave Marquardt
2026-11-30 21:00 ` [PATCH v20 03/13] scsi: ibmvfc: fix potential NULL pointer dereference on failed queue allocation Dave Marquardt via B4 Relay
2026-11-30 21:00   ` Dave Marquardt
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 via B4 Relay
2026-11-30 21:00   ` Dave Marquardt
2026-11-30 21:00 ` [PATCH v20 05/13] scsi: ibmvfc: fix resource leaks on partial queue allocation failure Dave Marquardt via B4 Relay
2026-11-30 21:00   ` Dave Marquardt
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 [this message]
2026-12-01 17:56     ` Dave Marquardt
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=sashiko-outbox-241983@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=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.