Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nirmoy Das" <nirmoyd@nvidia.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v3] PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum
Date: Wed, 25 Nov 2026 13:35:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-233493@kernel.org> (raw)
In-Reply-To: <20261125131838.1272907-1-nirmoyd@nvidia.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] PCI: broken BAR readback check in
  pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror()
- [Medium] PCI: stale firmware BAR mirrored in
  pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror()
--

commit aff9cc8487ab3357c2581d1e1130b4ea710052d7
Author: Nirmoy Das <nirmoyd@nvidia.com>

PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum

This commit adds final and early-resume PCI fixups to mirror the upstream
port's BAR 0 (and BAR 1 if 64-bit) into Port 4 on Pericom PI7C9X3G606GPC
switches when CDEP is disabled.

> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> index 7f1f47ea2ee41..2d3f677d0d4d2 100644
> --- a/drivers/pci/quirks.c
> +++ b/drivers/pci/quirks.c
> @@ -6443,6 +6443,95 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_PERICOM, 0x2608,
>  DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_PERICOM, 0x2608,
>  			 pci_fixup_pericom_acs_store_forward);
>  
> +#define PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC	0xc008
> +
> +/*
> + * With CDEP disabled, Port 4 exposes no BAR or MSI-X capability, but its
> + * internal MSI-X Table/PBA address check remains active. Mirror the
> + * upstream BAR 0 to keep these addresses in MMIO space assigned to the
> + * switch.
> + *
> + * Port 4 is device 4, function 0 below the upstream port. Its BAR 0
> + * accepts writes but reads as zero, so BAR sizing clears the mirror.
> + * Reapply it after resource assignment and during early resume, after
> + * PCI state restoration.
> + */
> +static void pci_fixup_pericom_pi7c9x3g606gpc_bar0_mirror(struct pci_dev *pdev)
> +{
> +	struct pci_dev *upstream;
> +	bool bar0_64, disable_mem;
> +	u16 cmd = 0;
> +	u32 bar = 0, bar1 = 0, upstream_bar = 0, upstream_bar1 = 0;
> +
> +	if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM)
> +		return;
> +
> +	if (PCI_SLOT(pdev->devfn) != 4 || PCI_FUNC(pdev->devfn))
> +		return;
> +
> +	upstream = pci_upstream_bridge(pdev);
> +	if (!upstream || upstream->vendor != PCI_VENDOR_ID_PERICOM ||
> +	    upstream->device != PCI_DEVICE_ID_PERICOM_PI7C9X3G606GPC ||
> +	    pci_pcie_type(upstream) != PCI_EXP_TYPE_UPSTREAM)
> +		return;
> +
> +	pci_read_config_dword(upstream, PCI_BASE_ADDRESS_0, &upstream_bar);
> +	if (upstream_bar & PCI_BASE_ADDRESS_SPACE_IO)
> +		return;
> +
> +	bar0_64 = (upstream_bar & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
> +		  PCI_BASE_ADDRESS_MEM_TYPE_64;
> +	if (bar0_64)
> +		pci_read_config_dword(upstream, PCI_BASE_ADDRESS_1,
> +				      &upstream_bar1);
> +
> +	if (!(upstream_bar & PCI_BASE_ADDRESS_MEM_MASK) &&
> +	    (!bar0_64 || !upstream_bar1)) {
> +		pci_warn(pdev, "skipping PI7C9X3G606GPC BAR 0 mirror workaround because upstream BAR 0 is unassigned\n");
> +		return;
> +	}

[Severity: Medium]
Can this check miss an unassigned upstream BAR 0 when firmware left a stale
address in PCI_BASE_ADDRESS_0?

During BAR sizing, __pci_size_bars() saves and restores the firmware value in
PCI_BASE_ADDRESS_0.  If claiming or reassigning upstream->resource[0] fails,
the resource is marked IORESOURCE_UNSET or cleared by reset_resource(), and
pci_std_update_resource() never writes to config space:

drivers/pci/setup-res.c:pci_std_update_resource() {
	...
	if (!res->flags)
		return;

	if (res->flags & IORESOURCE_UNSET)
		return;
	...
}

Because PCI_BASE_ADDRESS_0 still holds the firmware address, this check passes
and mirrors the stale address into Port 4.  If Linux assigned that MMIO range
to a bridge window for downstream devices, Port 4's BAR 0 + 0x7f000 and
BAR 0 + 0x7f080 address check will reject accesses to those addresses with
Unsupported Request completions.  Checking upstream->resource[0].flags for
IORESOURCE_MEM and !IORESOURCE_UNSET would ensure the upstream BAR is actually
assigned.

> +
> +	pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &bar);
> +	if (bar0_64) {
> +		pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1, &bar1);
> +		if (bar == upstream_bar && bar1 == upstream_bar1)
> +			return;
> +	} else {
> +		if (bar == upstream_bar)
> +			return;
> +	}

[Severity: Medium]
What is this readback check intended to guard against?

As the comment above notes, Port 4 BAR 0 always reads back as zero when CDEP
is disabled, while the check just before this guarantees upstream_bar (or
upstream_bar1) is non-zero.  As a result, bar == upstream_bar is always false
when CDEP is disabled, so every pci_fixup_resume_early call (including runtime
resume) will toggle PCI_COMMAND_MEMORY for 64-bit BARs, rewrite BAR 0/1, and
log a pci_info() message.  Conversely, if Port 4 ever exposes a valid non-zero
BAR of its own, bar != upstream_bar will not bail out and the fixup will
overwrite Port 4's BAR with upstream_bar.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125131838.1272907-1-nirmoyd@nvidia.com?part=1

      reply	other threads:[~2026-11-25 13:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 13:18 [PATCH v3] PCI: Work around Pericom PI7C9X3G606GPC Port 4 BAR erratum Nirmoy Das
2026-11-25 13:35 ` sashiko-bot [this message]

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=sashiko-outbox-233493@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=nirmoyd@nvidia.com \
    --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