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=1796446094; b=rxDmQdvMMQ1RWZWShIK0tmzwn7/XfW8FgnF+s6avm08iS+8BnHJDBgtZqQTYXBUd1TEX 6w5lbvMHqISxrxoCOc96/PVI4Xo/ZK25spsEneGTxs3UtiHkBlo1oV7E/oxw6i36g/k+a 69ZRK8K9DXww2M2MPio48muya+dneLZ1CKGkU4umIYLjxWNyTkkFYhY1Shdsp9ocECMwv n4Up1JuPIrzMSdAtZhoyHr+YzgH/e0vnW8Dn5Oy+UuwvguNWzaeys6AL/xGGmgeYiOTmx XgBFCbAd1576jhg8vrvGiqmetcDJCKzDl9A/E43M2KfDrjkeCxREfXC1XPUPG9n4fTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796446094; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8vqbXaHOJ4YLt4JoV82nOukJYEdAs5SsNVJcgIVl1UI=; b=L/Lr1qVlRTWHEStsb83Nem9c0oZhucDibr6IOlFwkHrH8U2GNjbVz4nCKYEEADjE5bZM n+8iadbrkzAfDK6mKvXgAvhsCdSpzFbsrUfiNlfnGT1OeFiaSKUkTeGQzVwtltBMGOOmO R+dIvilzeuvriAcm2rG9+7W6+LkP1fUpLWHV305DuI/iYqaqEW4FfTGza4n9PdKfgm4mB /noPka5zhvd3p4kEE3jGawRKGtJPFBju6u3nnzbxydAdOcQj4hLJxgtm8Lf7+jxvCA+ls qSMZsrfCAvb90Bou4HlIOkZshUBoTdf1XnSI0etl3k7CDE+NoXo4uuhmsZiAwBjuHHA== 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=SADimyAl; 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 D15E1606A330; Sat, 5 Dec 2026 04:48:14 +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=SADimyAl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D6F71F00936; Sat, 5 Dec 2026 04:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796446094; bh=8vqbXaHOJ4YLt4JoV82nOukJYEdAs5SsNVJcgIVl1UI=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=SADimyAltP/dXJxoXdAf6qVy5lhkZv9KSMNN+IPQfje6HZbE0ICQ6CMGpiEkBD9zA wpGhY36SHTqnkgzcBVqHh+e5A3Sb5+4geCwLosV24AnFRsn/u5dsT2Bm1MBRAv8Msi 7yVfFf0t5Rye/2wxxGJl4Ek1Uet0wZTA0CKKTIUlinasWodF0SAEKeIp1wgoo5X7Nc zMbK27q+X87o+hUpGbZMQjjffiB3wqlWByCdIO4vpACOdlXahJtkpWYBB2gnc7//Z+ XsRNP8sh217cjKDbSXd9F8oEfuQ86p3BF1tKKV5/CuGQEn03o3/wf3OM6a6PTCJ2lw 0a0/040Pz/Idg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v18 16/19] PCI/CXL: Expose CXL Reset as a PCI reset method 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-17-smadhavan@nvidia.com> References: <20261205041453.3946529-1-smadhavan@nvidia.com> <20261205041453.3946529-17-smadhavan@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:48:14 +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 11 potential issues to consider: - [High] PCI/CXL: cxl_reset_function() omits cxl_reset when enabled after probe - [High] PCI/CXL: cxl_reset_function() falls back to FLR with single CXL protocol - [High] PCI/CXL: VFIO guest can clear DVSEC control to bypass cxl_reset_function() - [High] PCI/CXL: cxl_reset_function() can run before Normalized Addressing discovery - [High] PCI/CXL: cxl_reset_function() state_saved check breaks raw reset callers - [Medium] cxl: devm_cxl_enable_hdm() fails to update cached global_ctrl - [Medium] pci/cxl: cxl_reset_wait_cache_wbi() omits final status poll after timeout - [Medium] PCI/CXL: cxl_reset_execute() writes stale dvsec_ctrl after cxl_port unbind - [Medium] PCI/CXL: unlocked bus->devices check and TOCTOU race in cxl_reset_function() - [Medium] PCI/CXL: cxl_port probe/unbind races with cxl_reset_function() - [Medium] PCI/CXL: cxl_reset_hdm_unmark() runs before state cleanup and HPA release -- commit 3a501efb8899451afa7458cc7065fa2f49abb4dc Author: Srirangan Madhavan PCI/CXL: Expose CXL Reset as a PCI reset method This commit registers cxl_reset_function() in pci_reset_fn_methods[] ahead of FLR, adjusts its probe error returns to -ENOTTY, and rejects execution when pdev->state_saved is false. > diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c > index 1053aa2f66071..cc2d5a4f67df5 100644 > --- a/drivers/pci/cxl.c > +++ b/drivers/pci/cxl.c [ ... ] > @@ -823,7 +823,7 @@ int cxl_reset_function(struct pci_dev *pdev, bool pro= be) > =20 > rc =3D cxl_pci_read_config_word(pdev, dvsec + PCI_DVSEC_CXL_CTRL, &ctrl= ); > if (rc) > - return rc; > + return probe ? -ENOTTY : rc; > if (!(ctrl & PCI_DVSEC_CXL_CACHE_ENABLE) || > !(ctrl & PCI_DVSEC_CXL_MEM_ENABLE)) > return -ENOTTY; [Severity: High] Does checking PCI_DVSEC_CXL_CTRL before the probe early-return permanently exclude cxl_reset when firmware leaves CXL.mem or CXL.cache disabled at boot? pci_init_reset_methods() runs once in pci_init_capabilities() before any driver binds, and nothing refreshes dev->reset_methods[] when cxl_hdm_decode_init() -> devm_cxl_enable_mem() later enables PCI_DVSEC_CXL_MEM_ENABLE. Any subsequent PCI reset then skips cxl_reset and runs FLR instead, leaving active CXL protocol state unreset and CXL memory uncleared. Should the probe path check only static PCI_DVSEC_CXL_CAP bits and defer the dynamic PCI_DVSEC_CXL_CTRL checks until reset execution? [Severity: High] Can returning -ENOTTY when only one of CXL.cache or CXL.mem is enabled cause __pci_reset_function_locked() to fall through to FLR while the other CXL protocol is still active? For example, cxl_pci only sets PCI_DVSEC_CXL_MEM_ENABLE, and a failed CXL reset that keeps caching off also leaves MEM_ENABLE set with CACHE_ENABLE cleared. Because cxl_reset sits immediately ahead of flr, returning -ENOTTY lets the next reset execute FLR without resetting the active CXL protocol or clearing CXL memory. Should -ENOTTY be returned only when neither protocol is enabled, with a non--ENOTTY error if single-protocol states cannot be reset? [Severity: High] Can a VFIO guest bypass cxl_reset by clearing PCI_DVSEC_CXL_CACHE_ENABLE or PCI_DVSEC_CXL_MEM_ENABLE in hardware config space? vfio_pci_init_perm_bits() sets ecap_perms[PCI_EXT_CAP_ID_DVSEC].writefn to vfio_raw_config_write, passing guest DVSEC writes directly to hardware. If a guest clears either bit before device release, cxl_reset_function() reads the live register and returns -ENOTTY, letting __pci_reset_function_locked() fall through to FLR. FLR then succeeds and vfio_pci_core_disable() clears vdev->needs_reset, leaving guest CXL memory and protocol state uncleared across reassignment. > @@ -831,5 +831,11 @@ int cxl_reset_function(struct pci_dev *pdev, bool pr= obe) > if (probe) > return 0; > =20 > + /* Raw reset callers may not have saved the PCI state needed for restor= e. */ > + if (!pdev->state_saved) { > + pci_err(pdev, "CXL reset requires saved PCI state\n"); > + return -EINVAL; > + } [Severity: High] Does rejecting !pdev->state_saved with -EINVAL break raw callers of __pci_reset_function_locked()? __pci_reset_function_locked() does not require callers to save PCI state beforehand, and returning -EINVAL aborts its loop without trying any later reset method. In xen-pciback, pcistub_init_device() clears dev->state_saved via pci_restore_state(), and pcistub_put_pci_dev() and pcistub_device_release() later call pcistub_reset_device_state() -> __pci_reset_function_locked() before reloading saved state. Because pcistub_reset_device_state() ignores the return value, the device is left completely unreset on guest release and unbind, letting guest state and CXL memory persist across domain handoff. > + > return cxl_reset_execute(pdev, dvsec, cap); > } [Severity: Medium] Can cxl_reset_wait_cache_wbi() return a spurious -ETIMEDOUT if the task is preempted past the deadline? cxl_reset_wait_cache_wbi() checks while (time_before(jiffies, deadline)) before sleeping and reading PCI_DVSEC_CXL_STATUS2, with no final status read after the loop exits (unlike cxl_reset_wait_done()). If the thread is delayed past the 100 ms deadline while hardware has already set PCI_DVSEC_CXL_CACHE_INV, the reset aborts with -ETIMEDOUT instead of succeeding. [Severity: Medium] Can cxl_reset_enable_cache() re-enable PCI_DVSEC_CXL_MEM_ENABLE after a concurrent cxl_port unbind has disabled it? pci_reset_function() holds device_lock(&pdev->dev) rather than device_lock(&endpoint->dev), and drops cxl_rwsem.region after cxl_reset_hdm_restore() re-enables MSE: CPU0 (pci_reset_function) CPU1 (cxl_port unbind) cxl_reset_hdm_restore() /* MSE on, CACHE_ENABLE off */ drop cxl_rwsem.region clear_mem_enable() cxl_set_mem_enable(cxlds, 0) cxl_hdm_cache_set_dvsec_ctrl() disable_hdm() /* clears HDM_DECODER_ENABLE */ cxl_reset_enable_cache() write snapshot->dvsec_ctrl <-- re-enables MEM_ENABLE Hardware is left with MEM_ENABLE set and CXL_HDM_DECODER_ENABLE cleared while pdev->hdm->dvsec_ctrl records both MEM_ENABLE and CACHE_ENABLE as cleared, causing a subsequent cxl_port rebind to fail with -ENXIO in cxl_hdm_decode_init(). Note that commit "PCI/CXL: Restore CXL state after CXL bus reset" refreshes decoder settings but still leaves snapshot->dvsec_ctrl stale. [Severity: Medium] Does calling cxl_reset_hdm_unmark() before state cleanup and cxl_hdm_quiesce_destroy() unblock concurrent decoder commits and teardowns too early? cxl_decoder_commit() and cxl_decoder_reset() rely on reset_pending and regs_offline under cxl_rwsem.region, not device_lock(&pdev->dev): CPU0 (__cxl_reset_execute) CPU1 (commit_store) cxl_reset_hdm_unmark(pdev) /* clears reset_pending */ cxl_decoder_commit() /* reset_pending is false */ if (rc) cxl_reset_save_disabled_state() /* clears PCI_COMMAND_MEMORY */ HDM MMIO access <-- BAR disabled On failure paths this allows HDM MMIO while PCI_COMMAND_MEMORY is being cleared (or already off), producing Unsupported Requests and -EIO. On success paths it also lets a newly committed region fail devm_request_mem_region() with -EBUSY before cxl_hdm_quiesce_destroy() releases the cxl_reset HPA reservation. > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 5a8338340d232..9ab647719c9f3 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -5204,6 +5204,7 @@ const struct pci_reset_fn_method pci_reset_fn_metho= ds[] =3D { > { }, > { pci_dev_specific_reset, .name =3D "device_specific" }, > { pci_dev_acpi_reset, .name =3D "acpi" }, > + { cxl_reset_function, .name =3D "cxl_reset" }, > { pcie_reset_flr, .name =3D "flr" }, > { pci_af_flr, .name =3D "af_flr" }, > { pci_pm_reset, .name =3D "pm" }, [Severity: High] As reported by Alison Schofield on v17 [1], can cxl_reset execute before CXL endpoint and region discovery resolve Normalized Addressing? pci_bus_add_device() runs pci_save_state() and pci_cxl_hdm_cache_init() from raw HDM registers before CXL drivers bind, whereas CXL_DECODER_F_NORMALIZED_ADDRESSING is only recorded into pdev->hdm later in cxl_add_to_region() -> cxl_hdm_cache_set_normalized(). If a reset runs before region discovery completes (or while CXL drivers are unbound), cxl_hdm_ranges_collect() misses the flag instead of returning -EOPNOTSUPP and passes the raw normalized base to request_mem_region() and cpu_cache_invalidate_memregion(). cxl_clear_memory() then clears device memory without flushing the true host SPA cachelines, risking silent data corruption or machine checks. [Severity: Medium] Does devm_cxl_enable_hdm() forget to update cached global_ctrl via cxl_hdm_cache_set_global_ctrl()? Unlike disable_hdm() right above it, devm_cxl_enable_hdm() writes CXL_HDM_DECODER_ENABLE to hardware without updating pdev->hdm->global_ctrl, while devm_cxl_enable_mem() immediately updates dvsec_ctrl with PCI_DVSEC_CXL_MEM_ENABLE. A CXL reset racing during the 20 ms cxl_settle_decoders() sleep in devm_cxl_enumerate_decoders() then sees MEM_ENABLE set with CXL_HDM_DECODER_ENABLE clear, causing cxl_hdm_snapshot_is_dvsec_decoded() to return true and cxl_reset_hdm_prepare() to fail with -EOPNOTSUPP. [Severity: Medium] Is the list_is_singular(&pdev->bus->devices) check in cxl_reset_function() missing pci_bus_sem and pci_rescan_remove_lock? pci_device_add() and pci_destroy_dev() mutate bus->devices under pci_bus_sem and pci_rescan_remove_lock without taking device_lock(&pdev->dev), so reading bus->devices here is a data race and leaves an ARI TOCTOU window across cxl_reset_execute(): CPU0 (cxl_reset_function) CPU1 (dev_rescan_store) list_is_singular(&bus->devices) /* true, unlocked */ pci_lock_rescan_remove() pci_rescan_bus(pdev->bus) pci_device_add(sib) down_write(&pci_bus_sem) list_add_tail(&sib->bus_list, ...) up_write(&pci_bus_sem) /* binds driver to sib */ cxl_reset_execute(pdev, ...) cxl_clear_memory(...) <-- resets active ARI sibling If a previously removed ARI sibling is rescanned after list_is_singular() passes, CXL Reset resets the active sibling without saving its PCI state or quiescing its driver. [Severity: Medium] Can concurrent cxl_port probe or unbind issue config and HDM MMIO accesses during the CXL Reset quiet period? pci_reset_function() holds device_lock(&pdev->dev) and pci_cfg_access_lock(pdev), which neither blocks kernel pci_{read,write}_config_*() calls nor serializes against device_lock(&port->dev) on the endpoint cxl_port: CPU0 (__cxl_reset_execute) CPU1 (cxl_endpoint_port_probe) cxl_reset_regs_offline(pdev) cxl_clear_memory(pdev, ..., true) cxl_reset_wait_done(...) /* 100 ms - 100 s quiet period, MSE off, no cxl_rwsem.region */ device_lock(&port->dev) read_cdat_data() <-- DOE config access devm_cxl_endpoint_decoders_setup() /* DVSEC config & HDM MMIO */ Neither cxl_endpoint_port_probe() nor cxl_port unbind (clear_mem_enable() and disable_hdm()) checks regs_offline or reset_pending. Running during cxl_reset_wait_done() issues non-Status2 config and HDM MMIO accesses while MSE is cleared, risking PCIe Unsupported Requests, AER errors, and stale pdev->hdm cache updates. [1] https://lore.kernel.org/r/avyQ2sXKfvdz9SVs@aschofie-mobl2.lan --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205041453.3946= 529-1-smadhavan@nvidia.com?part=3D16