Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com>
Cc: linux-pci@vger.kernel.org, linux-cxl@vger.kernel.org
Subject: Re: [PATCH v2 10/13] PCI/CXL: Clear ACS SV across an SBR of a CXL DPort
Date: Tue, 25 Aug 2026 02:40:42 +0000	[thread overview]
Message-ID: <20260825024043.3DDA31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825022628.3651434-11-fabio.m.de.francesco@linux.intel.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Unsynchronized access to the global `cxl_sbr_region_ops` struct pointer can result in a NULL pointer dereference or a Use-After-Free crash if the CXL core module unloads concurrently.
- [High] Missing link training wait for nested bridges during subordinate configuration space restoration.
- [High] Restoring the standard configuration space of subordinate devices re-enables Bus Master and Memory Space before their PCIe capabilities are restored, risking Malformed TLP fatal errors.
- [High] The completion function attempts to access the configuration space and memory regions of downstream devices even if the secondary bus reset fails.
- [Medium] The polling loop in `cxl_port_pm_init_is_complete()` can miss a successful completion if scheduling delays cause `msleep()` to overshoot the timeout.
--

--- Patch [10]: [PATCH v2 10/13] PCI/CXL: Clear ACS SV across an SBR of a CXL DPort ---
commit fae09a9aaf20d6e342f823e3752512b2c39cdd95
Author: Fabio M. De Francesco <fabio.m.de.francesco@linux.intel.com>

PCI/CXL: Clear ACS SV across an SBR of a CXL DPort

A Secondary Bus Reset (SBR) of a CXL Downstream Port clears the
Downstream Component's (DPort) captured Bus Number. This patch
clears ACS Source Validation and Bus Master Enable across the reset
so that Port Power Management Initialization completes at link-up.

> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 417b6b44473e5..f3781d1e8f6e1 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
[ ... ]
> +static int cxl_sbr_prepare(struct pci_dev *bridge, u16 dvsec,
> +			   struct cxl_sbr_ctx *ctx)
> +{
> +	int rc;
> +
> +	/* Abort before touching hardware if the regions cannot be disabled. */
> +	if (cxl_sbr_region_ops) {
> +		rc = cxl_sbr_region_ops->disable_regions(bridge);
> +		if (rc)
> +			return rc;
> +	}

[Severity: High]
Could accessing cxl_sbr_region_ops here result in a use-after-free or NULL
pointer dereference?

If a secondary bus reset is initiated via sysfs concurrently with the
cxl_core module unloading, the pointer might be cleared or freed before
disable_regions() is called. There does not appear to be any lock or RCU
protection here.

[ ... ]
> +static bool cxl_port_pm_init_is_complete(struct pci_dev *bridge, u16 dvsec)
> +{
> +	unsigned long start = jiffies;
> +	unsigned long timeout = start + msecs_to_jiffies(100);
> +	u16 status;
> +
> +	do {
> +		pci_read_config_word(bridge,
> +				     dvsec + PCI_DVSEC_CXL_PORT_EXT_STATUS,
> +				     &status);
> +		if (!PCI_POSSIBLE_ERROR(status) &&
> +		    (status & PCI_DVSEC_CXL_PORT_EXT_STATUS_PM_INIT_COMP)) {
> +			pci_dbg(bridge, "%s: PM Init Complete set after %u ms, ext status %#06x\n",
> +				__func__, jiffies_to_msecs(jiffies - start), status);
> +			return true;
> +		}
> +		msleep(10);
> +	} while (time_before(jiffies, timeout));
> +
> +	pci_warn(bridge, "%s: PM Init Complete not set after %u ms, ext status %#06x\n",

[Severity: Medium]
Will this loop miss successful completions if scheduling delays cause
msleep() to overshoot the timeout?

If the sleep significantly exceeds 10ms and crosses the 100ms timeout
boundary, the loop terminates and returns false without a final status
read. This might lead to spurious warnings and premature restoration of
ACS Source Validation, causing the Port to reject bus 0 traffic.

[ ... ]
> +static int cxl_sbr_restore_config_space(struct pci_dev *dev, void *userdata)
> +{
> +	pci_restore_config_space(dev);
> +	pci_dbg(dev, "%s: config space restored\n", __func__);
> +
> +	return 0;
> +}

[Severity: High]
Does this unconditionally re-enable Bus Master and Memory Space before
PCIe capabilities are restored?

When pci_restore_config_space() writes the first 64 bytes, it restores
PCI_COMMAND while the Max Payload Size (MPS) remains at its hardware
reset default of 128 bytes. This might trigger Malformed TLP fatal errors
if the device interacts with a host configured for a larger MPS during
this window.

[ ... ]
> +static void cxl_sbr_restore_subordinate(struct pci_dev *bridge)
> +{
> +	if (!bridge->subordinate)
> +		return;
> +
> +	/* Parents before children: a child answers once its parent forwards. */
> +	pci_walk_bus(bridge->subordinate, cxl_sbr_restore_config_space, NULL);
> +}

[Severity: High]
Does pci_walk_bus() safely handle nested PCI-to-PCI bridges on the
subordinate bus?

It seems to restore the nested bridge's standard configuration and then
immediately traverse to the grandchildren without waiting for the nested
bridge's secondary link to retrain. This means configuration writes might
be sent to deeper endpoints while their link is still down.

[ ... ]
>  int pci_bridge_secondary_bus_reset(struct pci_dev *dev)
>  {
> +	struct cxl_sbr_ctx ctx = {};
> +	u16 dvsec = 0;
> +	int rc;
> +
>  	if (!dev->block_cfg_access)
>  		pci_warn_once(dev, "unlocked secondary bus reset via: %pS\n",
>  			      __builtin_return_address(0));
> +
> +	if (is_cxl_dport(dev))
> +		dvsec = cxl_port_dvsec(dev);
> +	if (dvsec) {
> +		rc = cxl_sbr_prepare(dev, dvsec, &ctx);
> +		if (rc)
> +			return rc;
> +	}
> +
>  	pcibios_reset_secondary_bus(dev);
>  
> -	return pci_bridge_wait_for_secondary_bus(dev, "bus reset");
> +	rc = pci_bridge_wait_for_secondary_bus(dev, "bus reset");
> +
> +	if (dvsec)
> +		cxl_sbr_complete(dev, dvsec, &ctx);
> +
> +	return rc;
>  }

[Severity: High]
Is it safe to call cxl_sbr_complete() when
pci_bridge_wait_for_secondary_bus() times out or returns a non-zero error?

Accessing the configuration space and memory regions of downstream devices
while the secondary link is physically down might generate uncorrectable
PCIe AER errors like Unsupported Requests or Completion Timeouts.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260825022628.3651434-1-fabio.m.de.francesco@linux.intel.com?part=10

  reply	other threads:[~2026-08-25  2:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  2:26 [PATCH v2 00/13] Make SBR work for CXL Downstream Ports Fabio M. De Francesco
2026-08-25  2:26 ` [PATCH v2 01/13] cxl/pci: Make the HDM and Mem_Enable writes callable from CXL Fabio M. De Francesco
2026-08-25  2:37   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 02/13] cxl/hdm: Add function to restore one HDM decoder Fabio M. De Francesco
2026-08-25  2:41   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 03/13] cxl/hdm: Add function to restore CXL.mem decode Fabio M. De Francesco
2026-08-25  2:45   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 04/13] cxl/hdm: Reprogram the HDM Decoders below a CXL Port Fabio M. De Francesco
2026-08-25  2:58   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 05/13] cxl/core: Restore the HDM decoders below DPort Fabio M. De Francesco
2026-08-25  2:43   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 06/13] drivers/base/memory: Add cxl_offline_memory() to offline a physical range Fabio M. De Francesco
2026-08-25  2:40   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 07/13] cxl/core: Add region disable and enable for a DPort SBR Fabio M. De Francesco
2026-08-25  2:44   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 08/13] cxl/core: Collect the regions routed through a DPort Fabio M. De Francesco
2026-08-25  2:41   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 09/13] PCI/CXL: Disable and re-enable CXL regions Fabio M. De Francesco
2026-08-25  2:39   ` sashiko-bot
2026-08-26  9:04   ` Richard Cheng
2026-08-25  2:26 ` [PATCH v2 10/13] PCI/CXL: Clear ACS SV across an SBR of a CXL DPort Fabio M. De Francesco
2026-08-25  2:40   ` sashiko-bot [this message]
2026-08-26  8:47   ` Richard Cheng
2026-08-25  2:26 ` [PATCH v2 11/13] PCI/DPC: Unbind regions for DPC recovery Fabio M. De Francesco
2026-08-25  2:51   ` sashiko-bot
2026-08-26  8:54   ` Richard Cheng
2026-08-25  2:26 ` [PATCH v2 12/13] PCI/CXL: Add a sysfs entry to unmask SBR Fabio M. De Francesco
2026-08-25  2:51   ` sashiko-bot
2026-08-25  2:26 ` [PATCH v2 13/13] PCI/CXL: Refuse an SBR of a CXL DPort unless authorized Fabio M. De Francesco
2026-08-25  2:59   ` sashiko-bot
2026-08-26  9:21 ` [PATCH v2 00/13] Make SBR work for CXL Downstream Ports Richard Cheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260825024043.3DDA31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fabio.m.de.francesco@linux.intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox