From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796445849; b=OsPPet8AzJfKR05ixUx2FwQAeEZ2JNBxWjnOYI/LY5ChDonX/oEchfN32FMf6Das1fH/ ffCft7C7O2hkRHADDzmcEHyp5UrFHKwN74xPmfQPTE2Ef98/Hm2M/WshaKTwwjuWPEtUi omkXzxmUQCcQmUSVHWY3HN8DeRTdPKODJZA3y4kJ9o9Dep9ydblMmH39lW89VDdEx05Lf tdsqY7xszBuUOKrubAqMfMUz6Z4/+/EHU2cDQNA+4Ksny52YIyjvbmo8hBLGah1PIRRuK SaEcl/VfyAgL0TA+xuLu2U1ZJsIwtjS8qsDFtGiWL6lZHFd2j+JT2n77/oouCQ53Vpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796445849; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=MFSkQbVxmWJ41b6zY2O0wq9w8TV/jAgCd79VvPDvvl4=; b=Mhqpe7QbLStUb/3XLW9B2GaUyHuPRxRhvCcLR54prvyr6I03eGNQKCLalcWSKVEc7eFJ QxvaB5eImDk5MyCcQtRrIYlljTIOn+TcT3A/sgTz0yxSW29V4lalPQLC3V1/OycRwKRae QpebvycALJGMZC/N/f/4mzwOWNyujTxx4qqNghx9uuPYPPZOFkMTt/icjtYfTLYZnxBjM V2z0Q6Xl+MLqknBQL+y2LHu8OLDlJKYDIegpErar4xLLaFENpkhd/SdweoSfxfj4vpNbQ ztFhVxZd2f8yfYO+hQqxQBrkp3rHxh7HsrVv4Bw2vzAyh1i1Bbqx+mbPmtZgl/sgLNw== 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=YkiVz+PZ; 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 AEB5A606A322; Sat, 5 Dec 2026 04:44:09 +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=YkiVz+PZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ECDB1F0092B; Sat, 5 Dec 2026 04:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796445849; bh=MFSkQbVxmWJ41b6zY2O0wq9w8TV/jAgCd79VvPDvvl4=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=YkiVz+PZDrt4y8k26bnKS1VgcfRcfC/y45TZ3cTW90og3Z1tExTwu0nQM21+IIN6d aPqFdABoSNi1Ipqh/rhxKR4a00ZxHJrbhkA+ZpFZfOdTNr28f4BrdzOWDYI9L7BJJ9 atsvJPOzzHO8Lh0BVFdn4OZNxS6WoADaHqjhlYbus9Z5ES2iRm0RSpoXCt8+0EqFdf sESykhGCz3jzUygcMKLBTtejN+NJSs9l1iiwUHT1nOLUyw6ZELASYJWiro2mgBPtfR vfQ2IVmSAzeTmQ6i9MpqrTuIJcDl7J7Kz7PkRaB08Ymkj8wsLLCisFFQCXUAlNoqtL +liVUm89Xhj/A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v18 11/19] PCI/CXL: Cache endpoint HDM state during PCI enumeration 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-12-smadhavan@nvidia.com> References: <20261205041453.3946529-1-smadhavan@nvidia.com> <20261205041453.3946529-12-smadhavan@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:44:08 +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: pci_cxl_hdm_cache_init() runs before x86 BAR survey and assignment - [High] PCI/CXL: cxl_pci_hdm_read_info() skips upstream bridge memory enablement - [High] PCI/CXL: HDM cache enables reset before Normalized Addressing discovery - [Medium] PCI/CXL: out-of-bounds MMIO read in cxl_pci_hdm_map_regs() - [Medium] cxl: devm_cxl_enable_hdm() omits cxl_hdm_cache_set_global_ctrl() update - [Medium] cxl/pci: disable_hdm() leaves stale HDM enable in cache on U32_MAX read - [Medium] PCI/CXL: __pci_cxl_hdm_cache_init() excludes CXL.mem-only devices -- commit cd94cb85d3b6b7e41ad48b2c419445f63d976837 Author: Srirangan Madhavan PCI/CXL: Cache endpoint HDM state during PCI enumeration This commit caches endpoint HDM decoder and DVSEC state in pci_dev->hdm during PCI enumeration and updates the cache when CXL enables or disables memory and HDM decode. > diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c > index d0da38763b4bc..a9d33357d095a 100644 > --- a/drivers/cxl/core/pci.c > +++ b/drivers/cxl/core/pci.c [ ... ] > @@ -266,13 +275,20 @@ static int dvsec_range_allowed(struct device *dev, = const void *arg) > =20 > static void disable_hdm(void *_cxlhdm) > { > - u32 global_ctrl; > struct cxl_hdm *cxlhdm =3D _cxlhdm; > void __iomem *hdm =3D cxlhdm->regs.hdm_decoder; > + struct pci_dev *pdev __free(pci_dev_put) =3D > + cxl_port_get_uport_pci_dev(cxlhdm->port); > + u32 global_ctrl; > =20 > global_ctrl =3D readl(hdm + CXL_HDM_DECODER_CTRL_OFFSET); > writel(global_ctrl & ~CXL_HDM_DECODER_ENABLE, > hdm + CXL_HDM_DECODER_CTRL_OFFSET); > + > + /* Keep the reset cache up to date. */ > + if (pdev && global_ctrl !=3D U32_MAX) > + cxl_hdm_cache_set_global_ctrl(pdev, > + global_ctrl & ~CXL_HDM_DECODER_ENABLE); [Severity: Medium] Does skipping cxl_hdm_cache_set_global_ctrl() when readl() returns U32_MAX leave a stale CXL_HDM_DECODER_ENABLE bit in pdev->hdm->global_ctrl? When cxl_error_detected() unbinds the memdev on a frozen PCIe channel, disable_hdm() runs while MMIO reads return U32_MAX. Leaving the enable bit set in the cache causes a later reset to restore HDM global enable on hardware even though the driver unbound and disabled it. Clearing CXL_HDM_DECODER_ENABLE in the cached global_ctrl on a U32_MAX read would keep the cache consistent. > } > =20 > static int devm_cxl_enable_hdm(struct device *host, struct cxl_hdm *cxlh= dm) [Severity: Medium] Should devm_cxl_enable_hdm() also call cxl_hdm_cache_set_global_ctrl() after enabling CXL_HDM_DECODER_ENABLE? The kerneldoc for cxl_hdm_cache_set_global_ctrl() notes that it tracks enabling HDM on bind as well as disabling it on unbind, but devm_cxl_enable_hdm() does not update pdev->hdm->global_ctrl. During cxl_endpoint_port_probe(), devm_cxl_enable_mem() updates cached dvsec_ctrl with PCI_DVSEC_CXL_MEM_ENABLE set, and devm_cxl_enumerate_decoders() then sleeps 20 ms in cxl_settle_decoders() before refreshing global_ctrl: CPU0 CPU1 cxl_endpoint_port_probe() devm_cxl_enable_hdm() writel(... | ENABLE) devm_cxl_enable_mem() cache dvsec_ctrl (MEM_ENABLE=3D1) cxl_settle_decoders() msleep(20) pci_reset_function() cxl_reset_hdm_prepare() snapshot sees MEM_ENABLE=3D1, HDM_ENABLE=3D0 <-- -EOPNOTSUPP A concurrent reset during that window either fails with -EOPNOTSUPP or, if it lands before devm_cxl_enable_mem(), restores CXL_HDM_DECODER_ENABLE cleared to hardware. [ ... ] > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > index 655ed53436d3e..aad567fb7c560 100644 > --- a/drivers/pci/bus.c > +++ b/drivers/pci/bus.c > @@ -359,6 +359,7 @@ void pci_bus_add_device(struct pci_dev *dev) > =20 > /* Save config space for error recoverability */ > pci_save_state(dev); > + pci_cxl_hdm_cache_init(dev); [Severity: High] As reported by Richard Cheng on v8 [1], can pci_cxl_hdm_cache_init() run safely here before x86 BAR resource survey and assignment? During x86 ACPI boot, acpi_pci_root_add() calls pci_bus_add_devices() during subsys_initcall(acpi_init), before pcibios_resource_survey() and fs_initcall(pcibios_assign_resources). If firmware left the component BAR unassigned or requiring relocation, cxl_pci_bar_assigned() fails and cache initialization is never retried, leaving pdev->hdm permanently NULL and breaking post-reset HDM restoration. In addition, cxl_pci_bar_assigned() does not check res->parent, so a conflicting firmware BAR that has not yet been surveyed can be temporarily enabled with PCI_COMMAND_MEMORY and ioremapped before resource survey clears the conflict. > diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c > new file mode 100644 > index 0000000000000..56119e3fd03a6 > --- /dev/null > +++ b/drivers/pci/cxl.c [ ... ] > +static void __iomem *cxl_pci_hdm_map_regs(struct pci_dev *pdev, > + struct cxl_register_map *map, > + resource_size_t *hdm_offset, > + int *decoder_count) > +{ > + struct cxl_reg_map *hdm_map =3D &map->component_map.hdm_decoder; > + void __iomem *hdm; > + int rc; > + > + /* cxl_setup_regs() populates hdm_map, including its valid bit. */ > + rc =3D cxl_setup_regs(map); > + if (rc) > + return ERR_PTR(rc); > + if (!hdm_map->valid) > + return ERR_PTR(-ENODEV); > + if (hdm_map->offset > map->max_size || > + hdm_map->size > map->max_size - hdm_map->offset) > + return ERR_PTR(-ENXIO); [Severity: Medium] Can cxl_setup_regs() read past the end of the ioremap() window if map->max_size is smaller than the component register block? cxl_decode_regblock() allows map->max_size down to 0, and cxl_map_regblock() maps only map->max_size bytes. Before the bounds check here runs, cxl_probe_component_regs() unconditionally advances base by CXL_CM_OFFSET (0x1000) and reads the capability header and capability offsets without checking map->max_size, which will fault on an unmapped vmalloc guard page for a non-conforming device with a small BAR. [ ... ] > + if (!(command & PCI_COMMAND_MEMORY)) { > + rc =3D pci_write_config_word(pdev, PCI_COMMAND, > + command | PCI_COMMAND_MEMORY); > + if (rc) > + return ERR_PTR(pcibios_err_to_errno(rc)); > + } > + > + info =3D __cxl_pci_hdm_read_info(pdev, map, dvsec); [Severity: High] Does setting PCI_COMMAND_MEMORY only on pdev work when upstream PCIe bridges do not yet have memory decoding enabled? During boot enumeration in subsys_initcall(acpi_init), pcieport has not bound yet (pcie_portdrv_init() is a device_initcall) and __pci_setup_bridge() does not set PCI_COMMAND_MEMORY on bridges. If any upstream Root Port or Switch Port has memory forwarding disabled, the MMIO reads in __cxl_pci_hdm_read_info() receive Unsupported Request responses (0xffffffff) and cache initialization fails silently, leaving pdev->hdm permanently NULL. [ ... ] > + if (!(cap & PCI_DVSEC_CXL_CACHE_CAPABLE) || > + !(cap & PCI_DVSEC_CXL_MEM_CAPABLE) || > + !(cap & PCI_DVSEC_CXL_RST_CAPABLE) || > + !(cap & PCI_DVSEC_CXL_RST_MEM_CLR_CAPABLE) || > + !cxl_dvsec_hdm_count_valid(FIELD_GET(PCI_DVSEC_CXL_HDM_COUNT, cap))) > + return 0; [Severity: Medium] As reported by Jonathan Cameron on v12 [2], should this require PCI_DVSEC_CXL_CACHE_CAPABLE? Gating cache initialization on PCI_DVSEC_CXL_CACHE_CAPABLE excludes CXL.mem-only endpoints (such as non-class-code-matching Type 3 devices) from ever populating pdev->hdm, so they miss HDM range synchronization and post-reset HDM restoration on CXL bus reset even though the reset helpers in commit "PCI/CXL: Flush host and device caches for CXL bus reset" check PCI_DVSEC_CXL_CACHE_CAPABLE dynamically. [ ... ] > + read_info =3D cxl_pci_hdm_read_info(pdev, &map, dvsec); > + if (IS_ERR(read_info)) > + return PTR_ERR(read_info); > + > + pdev->hdm =3D read_info; [Severity: High] As reported by Alison Schofield on v17 [3], does publishing pdev->hdm here allow CXL reset to run before Normalized Addressing has been discovered? Normalized Addressing cannot be determined from endpoint HDM registers alone; CXL_DECODER_F_NORMALIZED_ADDRESSING is only recorded later during cxl_add_to_region() when CXL endpoint discovery runs. Without a gate checking whether discovery has verified address translation, resetting a device without a bound CXL driver (or before region discovery completes) causes request_mem_region() and cpu_cache_invalidate_memregion() to operate on raw normalized endpoint addresses rather than the translated System Physical Addresses, which can bypass region exclusivity and wipe actively used CXL memory or flush the wrong host cache range. [1] https://lore.kernel.org/r/akyNQjte2TmeLhE8@MWDK4CY14F [2] https://lore.kernel.org/r/20260912022617.47860862@jic23-hlaptop [3] https://lore.kernel.org/r/avyPB4YCEKUDtT19@aschofie-mobl2.lan --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205041453.3946= 529-1-smadhavan@nvidia.com?part=3D11