Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796445823; b=Fi/dKUYCmivpSWbM8yShhEhrajekDDAtyh/Z24VFQn7i1YZivIBVeJpwWKqUbV5irjGo YkqyLacTNW3qPIXFGwCsQxgeyTRJOOFmyxB8MZj6zJd7mTTixZNnIlFiuWTvdcEkUsnZK Dw8hfsdCG/omZZxl++tU9WR/luuRUAKZjAH+7q6vRQpzGRzmeZqwOW6VqYysy+w/1GnKw aYiSDtBsVRl5cMqsmk9LOT0I+k3wK5/u18h5sGYJCwDcm0VJnWJtSvtiQKftq89klFyyz rI1K4OuEYKWsTdYevj88eLUQuzdhypoi4uFwOP/Mi9UogXvWXwMTVHUhktnkE87ZVPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796445823; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=NpPTu7Og2MdARkI0BeCyd/wDC/hxwnNaXIl4+Y/BgLU=; b=IPdnnXkII5+WDYkKrDTkXVPHoMSmju2hLv25ZEh7b+RZpEzbXAs6x0a9t0+KZCwfQQXH L1dX79DhnkzGPGU+uXVzvlQGRBqWggzEPJU2K7sPCGtluUL7PLefy19zs83ktVT/1WPq/ e30OY9dZUcaGOV4f7JiQd52LoMy3w3HUT93Ivy9l1ExkdqbexFqNTJs7Bsw5sYnjAmovI nnJPH9/KpmaqM5JUmDVTAkNxeNYuISAZxDlLnzsTiA46JVg+/12p0tEQvRq9tUTeRq8Mh x4Fq1LhT2qCwmcT3rJOGGZzfCgiUYZ8HLtiOgxM8OsP1VFbTN2ttfUgcusBUpgbi7ZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=brIlffOj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95738606A322; Sat, 5 Dec 2026 04:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=brIlffOj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F7C71F00936; Sat, 5 Dec 2026 04:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796445823; bh=NpPTu7Og2MdARkI0BeCyd/wDC/hxwnNaXIl4+Y/BgLU=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=brIlffOj9a06hv6NM+qv/GAs3nX5iH/TISnwspWbyvzX76ztra/7BH/fkz2CadzAc 0VOePDJ3Xr2ui5s+S5LjVQ4v9kkgS/AceM9FQaWDFsEJpFlnjsJ28n3FcGspW7BuC+ fOImgMu8AxguCZx4Xnyh1waFYLbHADPfQSQuFRAPl/kWdVzstQhmnJGeFRHoTDZ4T+ +BAyQK6+O2a1epiQ2RHATPbcWTPi6BgX9TxCGxD30GencYiFTA8Z9OkRcRjw2Hoorn OZ6h2wnA+q/TYV2sx9+4+IuF9s6obKNA533WJp6ywDpILgxgTewq/G6RIrLA6RwbVD uz+HFR0PCu0RA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v18 14/19] PCI/CXL: Reject reset with unsafe function scope Reply-To: sashiko-reviews@lists.linux.dev To: "Srirangan Madhavan" , linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org In-Reply-To: <20261205041453.3946529-15-smadhavan@nvidia.com> References: <20261205041453.3946529-1-smadhavan@nvidia.com> <20261205041453.3946529-15-smadhavan@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:43:42 +0000 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [High] PCI/CXL: bus reset precedes cxl_bus and bypasses cxl_reset_bus_function() - [Medium] PCI/CXL: !probe ARI guard falsely advertises cxl_reset and cxl_bus - [Medium] PCI/CXL: unlocked list_is_singular() read of bus->devices without pci_bus_sem - [Medium] PCI/CXL: probe-time scope check misses fn > 0 with MFD=3D0 and ARI fn 0 in sysfs - [Low] PCI/CXL: unlocked pci_num_vf() read in reset_method_store() probe path - [Low] PCI/CXL: duplicated function-scope guard in cxl.c and pci.c - [Low] PCI/CXL: missing Fixes trailer for cxl_reset_bus_function() scope bug -- commit edf4c40d8768b9c15e4a2d492055de063f8458bf Author: Srirangan Madhavan > PCI/CXL: Reject reset with unsafe function scope > > The per-device PCI reset interface must not reset sibling functions. > Reject cxl_reset and cxl_bus for VFs, multifunction devices, including > function 0 of an ARI device that has other functions, and PFs with enabled > VFs. > > Suggested-by: Alex Williamson > Link: https://lore.kernel.org/linux-cxl/20260626160846.426e71b6@nvidia.co= m/ > Link: https://lore.kernel.org/linux-cxl/6a50441e2bb5e_3cabcb1003e@djbw-de= v.notmuch/ > Signed-off-by: Srirangan Madhavan > Acked-by: Bjorn Helgaas > Reviewed-by: Richard Cheng [Severity: Low] This fixes a pre-existing bug in cxl_reset_bus_function(), which could advertise cxl_bus and reset sibling functions on VFs, multifunction devices, or PFs with enabled VFs. Should this include: Fixes: 53c49b6e6dd2 ("PCI/CXL: Add 'cxl_bus' reset method for devices bel= ow CXL Ports") > diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c > index c90715c5a6d52..0c60f6d7bb4fa 100644 > --- a/drivers/pci/cxl.c > +++ b/drivers/pci/cxl.c > @@ -579,6 +579,16 @@ int cxl_reset_function(struct pci_dev *pdev, bool pr= obe) > u16 dvsec, cap, ctrl; > int rc; > =20 > + /* > + * ->multifunction is not set for function 0 of an ARI device, so look > + * for siblings on the bus. Skip this when probing: @pdev is not on the > + * bus list yet and its siblings are not enumerated. > + */ > + if (pdev->is_virtfn || pdev->multifunction || pci_num_vf(pdev) || > + (!probe && pci_ari_enabled(pdev->bus) && > + !list_is_singular(&pdev->bus->devices))) > + return -ENOTTY; > + > rc =3D cxl_pci_device_dvsec(pdev, &dvsec, &cap); > if (rc) > return rc; [Severity: Medium] Does gating the ARI sibling check on !probe cause cxl_reset and cxl_bus to be falsely advertised on Function 0 of an ARI multifunction device? Because !probe skips the check, pci_init_reset_methods() records cxl_reset and cxl_bus in dev->reset_methods[], and post-enumeration writes to sysfs reset_method still pass PCI_RESET_PROBE in reset_method_store() instead of returning -EINVAL. If no other reset method is available, pci_reset_function() then runs pci_dev_save_and_disable() (calling err_handler->reset_prepare(), forcing D0, and clearing PCI_COMMAND) before __pci_reset_function_locked() returns -ENOTTY. Checking PCI_ARI_CAP_NFN on ARI Function 0 (as next_ari_fn() does) and scanning bus->devices for any entry other than dev (as pci_parent_bus_reset() does) avoids the !probe bypass in both cxl_reset_function() and cxl_reset_bus_function(). [Severity: Medium] Can non-zero functions with PCI_HEADER_TYPE_MFD clear slip past this check during initial probe? In pci_scan_slot(), pci_scan_single_device() runs pci_device_add() -> pci_init_reset_methods() before dev->multifunction =3D 1 is set for fn > 0: drivers/pci/probe.c:pci_scan_slot() { ... dev =3D pci_scan_single_device(bus, devfn + fn); if (dev) { if (!pci_dev_is_added(dev)) nr++; if (fn > 0) dev->multifunction =3D 1; } ... } For ARI sibling functions (where PCI_HEADER_TYPE_MFD is 0) and conventional multifunction devices that leave PCI_HEADER_TYPE_MFD clear on fn > 0, dev->multifunction is still 0 during PCI_RESET_PROBE. Both cxl_reset_function() and cxl_reset_bus_function() then walk DVSEC config space unnecessarily and record unusable cxl_reset and cxl_bus methods in dev->reset_methods[]. Rejecting non-zero function numbers directly would catch this during initial enumeration. [Severity: Medium] Is list_is_singular(&pdev->bus->devices) safe without holding pci_bus_sem? pci_device_add() and pci_destroy_dev() mutate bus->devices under down_write(&pci_bus_sem) without taking device_lock on sibling functions, while callers of __pci_reset_function_locked() hold device_lock(&dev->dev) and not pci_bus_sem: CPU0 CPU1 pci_reset_function(fn0) device_lock(&fn0->dev) cxl_reset_function(fn0, false) list_is_singular(&bus->devices) <-- data race pci_scan_single_device(bus, fn1) pci_device_add(fn1) down_write(&pci_bus_sem) list_add_tail(..., &bus->devices) up_write(&pci_bus_sem) cxl_reset_execute(fn0, ...) <-- resets active sibling fn1 This is a data race on bus->devices in both cxl_reset_function() and cxl_reset_bus_function(), and also leaves a window during reset execution where a newly rescanned or hot-added ARI sibling can be reset while active. Taking down_read(&pci_bus_sem) around the bus->devices check is lock-order safe under device_lock, as pci_bridge_wait_for_secondary_bus() already does on the reset path. [Severity: Low] Can calling pci_num_vf() when probe is true race with sriov_numvfs_store()? reset_method_store() calls pci_init_reset_methods() and the reset probe callback without holding device_lock(&pdev->dev), whereas sriov_enable() and sriov_disable() write pdev->sriov->num_VFs under device_lock(&pdev->dev) (as documented in sriov_numvfs_show()). Gating the dynamic pci_num_vf() check on !probe, where __pci_reset_function_locked() holds device_lock, would avoid this data race in both cxl_reset_function() and cxl_reset_bus_function(). > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 7c6f2aba81443..5a8338340d232 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -5064,6 +5064,19 @@ static int cxl_reset_bus_function(struct pci_dev *= dev, bool probe) > u16 dvsec, reg, val; > int rc; > =20 > + /* > + * Reject VFs and multifunction devices before walking the bridge's > + * capabilities: every VF behind the same bridge would repeat the walk. > + * > + * ->multifunction is not set for function 0 of an ARI device, so look > + * for siblings on the bus. Skip this when probing: @dev is not on the > + * bus list yet and its siblings are not enumerated. > + */ > + if (dev->is_virtfn || dev->multifunction || pci_num_vf(dev) || > + (!probe && pci_ari_enabled(dev->bus) && > + !list_is_singular(&dev->bus->devices))) > + return -ENOTTY; > + > bridge =3D pci_upstream_bridge(dev); > if (!bridge) > return -ENOTTY; [Severity: Low] This isn't a bug, but this function-scope guard and comment are duplicated verbatim between cxl_reset_function() and cxl_reset_bus_function(). Extracting a small shared helper in drivers/pci/pci.h would keep both CXL reset methods in sync. [Severity: High] Can generic bus reset still bypass cxl_reset_bus_function() and these scope checks when SBR is already unmasked on the upstream CXL Port? In drivers/pci/pci.c, pci_reset_fn_methods[] places pci_reset_bus_function ahead of cxl_reset_bus_function, and pci_reset_bus_function() only returns -ENOTTY when cxl_sbr_masked() is true: drivers/pci/pci.c:pci_reset_bus_function() { ... if (bridge && pcie_is_cxl(bridge) && cxl_sbr_masked(bridge)) return -ENOTTY; ... } drivers/pci/pci.c:pci_reset_fn_methods[] { ... { pci_reset_bus_function, .name =3D "bus" }, { cxl_reset_bus_function, .name =3D "cxl_bus" }, } When PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR is already set (for example by firmware or an administrator), cxl_sbr_masked() returns false, so generic bus reset runs first and never reaches cxl_reset_bus_function(). That bypasses the scope checks added here, allowing hotplug slot resets of VFs, PFs with enabled VFs, and ARI Function 0 with siblings via pci_dev_reset_slot_function(), and also bypasses any CXL-specific reset handling in cxl_reset_bus_function(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205041453.3946= 529-1-smadhavan@nvidia.com?part=3D14