From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147815; b=4GlQ4ch2MtJ8Mn01dqrx/UXfMeIG62+JboC33XOjOFe+iYfX6odfiRQhbDwWgUQd7Xc9 aZOKbc+uWcAYHJ/oz8AU2wwsKNtwMzTk5D9ouDLV5HeDsQCfW7IPL2+KvTmFscQ0nEdnD WP9yCCY4XlVt6ZofsGmIF/dFJ2+zmYROLeroUePYg+T1u6+VXQu5fr3gUdIzx5/Qp8MTo pqYTuMRUoxPOYEyL37BBnPXgG5eoOwt/jRsAg7EL3sOXG1986iGjoosl+YfT/x9Sm9xA5 ol9rVPIGHPBaZ92I8QBmIPilG8ZxLmwyO5aCQwnsFlEdDKsqEeYkL/JNy60PpYH0Sdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147815; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:User-Agent:MIME-Version:Content-Type: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=rn5X4junqhT96mGopn3xpWcELUkSFnBrrmHLJiWsWr4=; b=fFEiGRSZeX01CBbUpIyMCjE5gFz7c/XQr2AZSB3dy34argd8yR49KIa08K2FVN8WRFcp GJfZtcBBkJU08m5HSM3uoQSezb+1GoxWx5VbUArBYavIlg8O8qK4C6cKTnOL5R9Ua22x9 SjAu8zqeL7L01K6AuYxD97lW915b97OrAiWUkIaEqjTXgiWEhJinZNc+s5yNn3afVdbh5 nkMpyFoCzMjZQkXe2wftQnP2KvkKSSf9n7fDalgMXvUmEOnOjwWwCQKHFH+Jj1H50iOCo J4d4RHDw+kH/G8qKGLLba/yBpN7G3pKZ5/urJejgCEO/pV7Bkd+IUFJuFlmusapidPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b="o/tKRsdm"; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 303CC606A31A; Tue, 1 Dec 2026 17:56:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 303CC606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=o/tKRsdm Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1F5vQ62082445; Tue, 1 Dec 2026 17:56:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=rn5X4j unqhT96mGopn3xpWcELUkSFnBrrmHLJiWsWr4=; b=o/tKRsdm2SVULCxft7ICuA xGBoNA6Y5tWdn3oFFb5Yz7TYLyc+iwHNMYVY5xFMHR+gY/HBx6/VW+Hf3jng0/g0 Q0HksHz76sEcAGZI8c5T+DLcwBkSR/V7Tzm54llyENFFqor6Sg0o6O5R8SAnxrlq oSFJO3A9cTGpKqsXruNhIcWfUR7Ija+Aif9w/kdZ6XlVfH74WSLLSoEMl1G1MJ2J hgCFWIfWcLVXKvoW99y4nd5/NUQiLFcpOK9DqaLjEXew1ESESUJvtu33khtSLppL ySFxgOdB1HBV8uX5MhQ/h663awYwTWSYphUAZZE3fmDndYBUM91MdeOnqm2PEPiQ == Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7mckdqcv-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 17:56:53 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1Hf8MI3003907; Tue, 1 Dec 2026 17:56:53 GMT Received: from smtprelay05.dal12v.mail.ibm.com ([172.16.1.7]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ja2uv026t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 17:56:53 +0000 (GMT) Received: from smtpav04.dal12v.mail.ibm.com (smtpav04.dal12v.mail.ibm.com [10.241.53.103]) by smtprelay05.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B1Huq0119399226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 17:56:52 GMT Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B940E58069; Tue, 1 Dec 2026 17:56:52 +0000 (GMT) Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 97C9258063; Tue, 1 Dec 2026 17:56:52 +0000 (GMT) Received: from e (unknown [9.16.46.225]) by smtpav04.dal12v.mail.ibm.com (Postfix) with ESMTPS; Tue, 1 Dec 2026 17:56:52 +0000 (GMT) From: Dave Marquardt 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 In-Reply-To: References: <20261130-ibmvfc-fpin-support-v20-0-50beb6e4b62a@linux.ibm.com> <20261130-ibmvfc-fpin-support-v20-12-50beb6e4b62a@linux.ibm.com> Date: Tue, 01 Dec 2026 11:56:52 -0600 Message-ID: <87jyls995n.fsf@linux.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA3MCBTYWx0ZWRfXwLPsACwMJ8DG Z22Z08tCyCQeXPFggFzVHm4DM/sJo8yDujFrfjAZbNsDPdSXOVMgStY/Uvr8Gwhr8yrufCyLoJc EYbJg2WBEbZJwXD302bUtESsMKG1G4A= X-Authority-Analysis: v=2.4 cv=MtfHeGae c=1 sm=1 tr=0 ts=6b0f0a65 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=s1q6AjveH8Oajvicn8MA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA3MCBTYWx0ZWRfX86JUAt3wjZrZ +/g9VU45OXi/tie5RoeK9NO/m4BKplX0KhOE71VrvNeAWzMKrGfvr1ywn9ofog+dtZKhgIjyqAI 4Q6zQkKJzrQeBnojC7XQykSS3Nkz+2OJjGEXGh6i6iCmTUvzdzFYNEoGrTb40pEHhzcXgG1Nj0i 2nN47Tm2s9uCbaeQxZqkMrg48q4CUUgswBoVp28Y4M9QbHfxsDUkDxtk6FgFU8QyUOgD+SToJ77 x8IzXBN0MxIgMQFp9A3z/VcG2fjxlOccmGVEyuOD9hKV2rCJOvqdSOTjqtuJzpR0OwSsNEKr5mA SjYxYScOsq+DtHRyGnHeiNSkzX+YXY2ewyMYB0clnRvbkloD2vbD6XI6DUAFxPv/m08ow/IEb0O F6S8tcoNy+TM1zcITCT33fCUBMPBYDIol6cPmwzqFQzaVoEtQdlrH3+FB1rIuDGi2/rSApCRSPm gz0GxSHzmNWBZF9idYA== X-Proofpoint-GUID: nC_IuUESCP6oc8XVh4TA-eZrqVQyy4EN X-Proofpoint-ORIG-GUID: nC_IuUESCP6oc8XVh4TA-eZrqVQyy4EN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_03,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010070 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 > > 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); >>=20=20 >> - 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 =3D 0; >> + vhost->mq_enabled =3D 0; >> + vhost->async_scrqs.active_queues =3D 0; >> + vhost->scsi_scrqs.active_queues =3D 0; >> + vhost->nvme_scrqs.active_queues =3D 0; >> + spin_unlock_irqrestore(&vhost->host->host_lock, flags); >> + } >>=20=20 >> 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 = =3D 0 > under host_lock, but only zero active_queues if ibmvfc_reg_sub_crqs() > fails. While vhost->using_channels is 0=E2=80=94or permanently after mig= ration to > a VIOS that does not advertise IBMVFC_CAN_SUPPORT_CHANNELS=E2=80=94caller= s 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 =3D 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 =3D 0 causes the error block to be > skipped, leaving vhost->do_enquiry =3D 1 with no sub-CRQs allocated or > registered. > > Resetting active_queues alongside vhost->using_channels =3D 0 and setting > vhost->do_enquiry =3D 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 =3D 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 =3D=3D 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 ibm= vfc_event *evt) >> ibmvfc_dbg(vhost, "Channel Setup succeeded\n"); >> flags =3D be32_to_cpu(setup->flags); >> vhost->do_enquiry =3D 0; >> - scsi->active_queues =3D be32_to_cpu(setup->num_scsi_subq_channels); >> - nvme->active_queues =3D be32_to_cpu(setup->num_nvme_subq_channels); >> + scsi->active_queues =3D min(be32_to_cpu(setup->num_scsi_subq_channels= ), >> + scsi->max_queues); >> + nvme->active_queues =3D nvme->scrqs ? >> + min(be32_to_cpu(setup->num_nvme_subq_channels), >> + nvme->max_queues) : 0; >> + async->active_queues =3D (async->scrqs && setup->async_sub_crq_handle= ) ? 1 : 0; >>=20=20 >> if (flags & IBMVFC_CHANNELS_CANCELED) { >> ibmvfc_dbg(vhost, "Channels Canceled\n"); >> vhost->using_channels =3D 0; >> + scsi->active_queues =3D 0; >> + nvme->active_queues =3D 0; >> + async->active_queues =3D 0; >> break; >> } >>=20=20 >> @@ -5942,6 +5978,8 @@ static void ibmvfc_channel_setup_done(struct ibmvf= c_event *evt) >> for (i =3D 0; i < nvme->active_queues; i++) >> nvme->scrqs[i].vios_cookie =3D >> be64_to_cpu(setup->channel_handles[scsi->active_queues + i]); >> + for (i =3D 0; i < async->active_queues; i++) >> + async->scrqs[i].vios_cookie =3D be64_to_cpu(setup->async_sub_crq_han= dle); >>=20=20 >> ibmvfc_dbg(vhost, "Using %u SCSI channels\n", >> scsi->active_queues); >> @@ -5976,10 +6014,11 @@ static void ibmvfc_channel_setup(struct ibmvfc_h= ost *vhost) >> struct ibmvfc_event *evt =3D ibmvfc_get_reserved_event(&vhost->crq); >> struct ibmvfc_channels *scsi =3D &vhost->scsi_scrqs; >> struct ibmvfc_channels *nvme =3D &vhost->nvme_scrqs; >> + struct ibmvfc_channels *async =3D &vhost->async_scrqs; >> unsigned int scsi_channels =3D >> min(scsi->desired_queues, vhost->max_vios_scsi_channels); >> - unsigned int nvme_channels =3D >> - min(nvme->desired_queues, vhost->max_vios_nvme_channels); >> + unsigned int nvme_channels =3D nvme->scrqs ? >> + min(nvme->desired_queues, vhost->max_vios_nvme_channels) : 0; >> int level =3D IBMVFC_DEFAULT_LOG_LEVEL; >> int i; >>=20=20 >> @@ -6003,6 +6042,9 @@ static void ibmvfc_channel_setup(struct ibmvfc_hos= t *vhost) >> cpu_to_be64(nvme->scrqs[i].cookie); >> } >>=20=20 >> + if (async->scrqs) >> + setup_buf->async_sub_crq_handle =3D cpu_to_be64(async->scrqs[0].cooki= e); > > [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 =3D=3D 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