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=1796445524; b=lVUxPtIH3lZVoV0d3wVi/mv20N42NRtkRgy3qMBqHTdcHvoj8I3gmJyCciWFzJHughJ1 XaWt5vRbhKG1bSmo7S8JYn2DGqtnvmCew1z4wEi2ZZ1DW1e3Q7Q0vDtLiZuiLCAcvATTk i40eA2LMqZQDf5nSNTmpP/fFrhMXM/pd5A7vDSK5zWBUgZhXDAsv0CGYhFYC+wNTxXChx 8wkJhfSupqCPX3Ccr0zW5GPu4LOCOZ1gG1/bCGfab0eFvu+0/I8Eas5+z80W23AldXOgt VLieaZdpxfPZmchfXUtarWsBZm4OTmeXcwbTfrLcz6GilN84dMW2TleQDwfEyWUA7Ag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796445524; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=UZMPJwgf8XIs6h3d1CXvoHUl+Fdoh7/UPsKSnZuFNuE=; b=HLtXWa5yqnCu51qivA418opMLZJVrVaXNnbi+Tz0dTX+GhCUV6tjjqBG546sjGeMJdtP DmCcELpmNwOSdSKAHp0hEKbbdYWaoWUIaFkfJzfENcjsWeceqYa1H2Q3fF0fvAhZp+uBm 2t41rJN3qmasqA44y/Xztw3WfzZ9sNx71tSFjr8z/qQE/O1zdNEWszTArs4nVV5fBT1vB Oe+TX/nnbLl3/U3t4D33FOT3hd7f1C1WmhgjJoX2xbC71kOKcEyMkc04B1njTHx+IMkAR bWG/vWJSn4oxuk+sPoZKgasFat/l47eGF4LgV+GtQFvjgM+QT6Lwpi7f1/XWNLMotjg== 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=nnrdwzVM; 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 99ABD606A322; Sat, 5 Dec 2026 04:38:44 +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=nnrdwzVM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 297CC1F0092B; Sat, 5 Dec 2026 04:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796445524; bh=UZMPJwgf8XIs6h3d1CXvoHUl+Fdoh7/UPsKSnZuFNuE=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=nnrdwzVMQ7ssNDMVYelBpZ1l+vRDBO+3CGWIFn8d0b0ai/bJ1t9MoIvlB4UGN1dEq lYQJeGirkOI7ckOBNQou+mMevSjMFQUrSuR6N2UFrkT6KWXN70xkZqBkVPPFejvlsF XD1kcpzFIIgLmWth3oNpY2UrbDTmD6HUD0d9qVqM7AF+LW5YXczo2zQwtIWh+/TToE HJo39Mj+Yh2AyMDu0hxvmiYproaoP26B25FriGRC4UxZh0eOHACFPRt8kGWvv/A7oa viPEC9oaabmrTasByysXx53/IyDzxFZlwFRijsRLJhZsxnhDc+vzs6ites0VRYib/u PyYsP2npR73xw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v18 09/19] cxl: Refresh cached PCI HDM decoder settings 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-10-smadhavan@nvidia.com> References: <20261205041453.3946529-1-smadhavan@nvidia.com> <20261205041453.3946529-10-smadhavan@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:38:43 +0000 X-Mailing-List: linux-pci@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 4 potential issues to consider: - [Medium] cxl: stale PCI HDM cache after cxl_endpoint_decoder_clear_reset_flags() - [Medium] cxl: stale emulated flag in devm_cxl_enumerate_decoders() caches DVSEC state - [Medium] cxl: TOCTOU race on cxled->skip in cxl_decoder_commit() cache refresh - [Low] cxl: unnecessary CXL export of cxl_hdm_check_decoder_count() -- commit 4920baebe7a19ee7d660630b38e29f5630e4ed37 Author: Srirangan Madhavan cxl: Refresh cached PCI HDM decoder settings This commit adds the struct cxl_hdm_info cache to struct pci_dev under CONFIG_CXL_RESET and refreshes cached endpoint decoder settings when decoders are enumerated, committed, or reset. > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c > index 1fabbd4a63a3f..f884181775824 100644 > --- a/drivers/cxl/core/hdm.c > +++ b/drivers/cxl/core/hdm.c [ ... ] > @@ -830,6 +848,7 @@ static int cxl_decoder_commit(struct cxl_decoder *cxl= d) > } > port->commit_end++; > cxld->config.flags |=3D CXL_DECODER_F_ENABLE; > + cxl_hdm_refresh_decoder(cxlhdm, cxld); > =20 > return 0; > } [Severity: Medium] Can cxl_hdm_refresh_decoder() cache a zeroed cxled->skip after hardware committed a non-zero skip? CPU0 CPU1 commit_store() -> __commit() down_write(&cxl_rwsem.region) cxl_decoder_commit() down_read(&cxl_rwsem.dpa) setup_hw_decoder() // skip !=3D 0 up_read(&cxl_rwsem.dpa) cxld_await_commit() // sleeps device_unbind_cleanup(&port->dev) cxl_dpa_release(cxled) down_write(&cxl_rwsem.dpa) cxled->skip =3D 0; up_write(&cxl_rwsem.dpa) cxld->config.flags |=3D ...ENABLE cxl_hdm_refresh_decoder() down_write(&cxl_rwsem.dpa) settings->skip =3D cxled->skip <-- caches 0 while HW has skip !=3D 0 cxl_dpa_alloc() registers cxl_dpa_release() on &port->dev after cxl_decoder_autoremove() registers cxld_unregister(), so LIFO devres teardown on port unbind runs cxl_dpa_release() first without holding cxl_rwsem.region. If a PCI or CXL reset then restores from pdev->hdm->settings[id] (or permanently if CXL_REGION_F_LOCK prevents reset teardown), hardware is reprogrammed with skip =3D 0 instead of the committed DPA offset. Passing the snapshot captured under cxl_rwsem.dpa in setup_hw_decoder() to the cache refresh helper would avoid re-reading a mutated cxled->skip. > @@ -902,6 +921,7 @@ static void cxl_decoder_reset(struct cxl_decoder *cxl= d) > writel(0, hdm + CXL_HDM_DECODER0_BASE_LOW_OFFSET(id)); > =20 > cxld->config.flags &=3D ~CXL_DECODER_F_ENABLE; > + cxl_hdm_refresh_decoder(cxlhdm, cxld); > =20 > /* Userspace is now responsible for reconfiguring this decoder */ > if (is_endpoint_decoder(&cxld->dev)) { [Severity: Medium] Does pdev->hdm->settings[id] stay stale when cxl_endpoint_decoder_clear_reset_flags() clears CXL_DECODER_F_ENABLE? When an SBR wipes active HDM decoders, cxl_reset_done() in drivers/cxl/pci.c calls cxl_endpoint_decoder_clear_reset_flags(), which clears CXL_DECODER_F_RESET_MASK (including CXL_DECODER_F_ENABLE) on cxled->cxld.config.flags without refreshing pdev->hdm. When the region is later torn down, cxl_decoder_reset() sees CXL_DECODER_F_ENABLE already cleared and returns early before reaching cxl_hdm_refresh_decoder(). The stale enabled decoder and HPA range remain in pdev->hdm->settings[id], so a subsequent CXL or PCI reset can try to reserve the old HPA range or reprogram a torn-down decoder. > @@ -1121,6 +1141,8 @@ static int devm_cxl_enumerate_decoders(struct cxl_h= dm *cxlhdm, > { > void __iomem *hdm =3D cxlhdm->regs.hdm_decoder; > struct cxl_port *port =3D cxlhdm->port; > + /* DVSEC-emulated decoders do not describe the cached HDM registers. */ > + bool emulated =3D should_emulate_decoders(info); > u64 dpa_base =3D 0; > int i, rc; [ ... ] > @@ -1182,6 +1210,8 @@ static int devm_cxl_enumerate_decoders(struct cxl_h= dm *cxlhdm, > put_device(&cxld->dev); > return rc; > } > + if (!emulated) > + cxl_hdm_refresh_decoder(cxlhdm, cxld); > rc =3D add_hdm_decoder(port, cxld); > if (rc) { > dev_warn(&port->dev, [Severity: Medium] Can a concurrent PCI reset cause devm_cxl_enumerate_decoders() to write DVSEC-emulated decoder state into pdev->hdm? CPU0 CPU1 devm_cxl_enumerate_decoders() emulated =3D should_emulate_decoders() // false (HDM enabled) cxl_settle_decoders() // sleeps up to 20ms pci_try_reset_bridge() SBR clears HDM global ctrl to 0 init_hdm_decoder() should_emulate_decoders() // now true cxl_setup_hdm_decoder_from_dvsec() cxld->config.flags |=3D ENABLE | LOCK if (!emulated) // still false cxl_hdm_refresh_decoder() <-- caches DVSEC range & LOCK in pdev->hdm devm_cxl_enumerate_decoders() does not hold device_lock(&pdev->dev) or cxl_rwsem.region, and init_hdm_decoder() re-evaluates should_emulate_decoders(info) on each decoder after cxl_settle_decoders(). If a reset clears CXL_HDM_DECODER_ENABLE in between, init_hdm_decoder() falls back to cxl_setup_hdm_decoder_from_dvsec(), while the stale emulated =3D=3D false still lets cxl_hdm_refresh_decoder() record the DVSEC-emulated range, CXL_DECODER_F_LOCK, and zeroed global_ctrl into pdev->hdm. Passing emulated into init_hdm_decoder() (or gating the refresh on whether init_hdm_decoder() actually initialized a hardware decoder) would avoid this mismatch. > diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c > index 63dc3f39b5d80..d0da38763b4bc 100644 > --- a/drivers/cxl/core/pci.c > +++ b/drivers/cxl/core/pci.c [ ... ] > +int cxl_hdm_check_decoder_count(struct cxl_hdm *cxlhdm) > +{ > + struct pci_dev *pdev __free(pci_dev_put) =3D > + cxl_port_get_uport_pci_dev(cxlhdm->port); > + > + if (!pdev) > + return 0; > + > + if (!cxl_hdm_cache_decoder_count_match(pdev, cxlhdm->decoder_count)) > + return -ENXIO; > + > + return 0; > +} > +EXPORT_SYMBOL_NS_GPL(cxl_hdm_check_decoder_count, "CXL"); [Severity: Low] Does cxl_hdm_check_decoder_count() need to be exported? Its declaration lives only in the cxl_core-private drivers/cxl/core/core.h and its only caller is devm_cxl_enumerate_decoders() in drivers/cxl/core/hdm.c, which is linked into the same module. Dropping the export (or making it a static helper alongside cxl_hdm_refresh_decoder() in drivers/cxl/core/hdm.c) avoids widening the CXL module ABI unnecessarily. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205041453.3946= 529-1-smadhavan@nvidia.com?part=3D9