Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Josh Triplett" <josh@joshtriplett.org>, linux-pci@vger.kernel.org
Subject: Re: [PATCH v2] pci: Prefer MMCONFIG for all config space accesses if available
Date: Tue, 01 Dec 2026 05:49:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-242637@kernel.org> (raw)
In-Reply-To: <4b37c09a330f78db0ac3265a9b8e278d1d7d6f1c.1796103197.git.josh@joshtriplett.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] x86/pci: 32-bit pci_mmcfg preference adds fixmap TLB flushes
  under lock
--

commit ed763afa39424e0a8e5b03379200b33b56222587
Author: Josh Triplett <josh@joshtriplett.org>

pci: Prefer MMCONFIG for all config space accesses if available

This commit updates raw_pci_read() and raw_pci_write() on x86 to prefer
MMCONFIG (pci_mmcfg) even for the first 256 bytes of PCI config space,
with a quirk disabling this on AMD K8 systems and a pci=no_prefer_mmconf
boot parameter.

> diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
> index 63105b29fbf54..5ad2f108686ec 100644
> --- a/arch/x86/pci/common.c
> +++ b/arch/x86/pci/common.c
[ ... ]
> @@ -40,9 +43,20 @@ const struct pci_raw_ops *__read_mostly raw_pci_ext_ops;
>  int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
>  						int reg, int len, u32 *val)
>  {
> +	bool tried_mmconf = false;
> +
> +#ifdef CONFIG_PCI_MMCONFIG
> +	if (!pci_no_prefer_mmconf && raw_pci_ext_ops == &pci_mmcfg) {
> +		int ret = raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
> +
> +		if (ret != -EINVAL)
> +			return ret;
> +		tried_mmconf = true;
> +	}
> +#endif
>  	if (domain == 0 && reg < 256 && raw_pci_ops)
>  		return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
> -	if (raw_pci_ext_ops)
> +	if (!tried_mmconf && raw_pci_ext_ops)
>  		return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
>  	return -EINVAL;
>  }
> @@ -50,9 +64,20 @@ int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
>  int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
>  						int reg, int len, u32 val)
>  {
> +	bool tried_mmconf = false;
> +
> +#ifdef CONFIG_PCI_MMCONFIG
> +	if (!pci_no_prefer_mmconf && raw_pci_ext_ops == &pci_mmcfg) {
> +		int ret = raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
> +
> +		if (ret != -EINVAL)
> +			return ret;
> +		tried_mmconf = true;
> +	}
> +#endif
>  	if (domain == 0 && reg < 256 && raw_pci_ops)
>  		return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
> -	if (raw_pci_ext_ops)
> +	if (!tried_mmconf && raw_pci_ext_ops)
>  		return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
>  	return -EINVAL;
>  }

[Severity: Medium]
Should preferring pci_mmcfg for base config space be restricted to 64-bit
x86?

On 32-bit x86, pci_mmcfg is not lockless and does not keep ECAM regions
permanently mapped.  Instead, pci_mmcfg_read() and pci_mmcfg_write() walk
pci_mmcfg_list under RCU, take pci_config_lock, and multiplex a single
FIX_PCIE_MCFG fixmap slot across all devices and CPUs:

arch/x86/pci/mmconfig_32.c:pci_exp_set_dev_base() {
	u32 dev_base = base | PCI_MMCFG_BUS_OFFSET(bus) | (devfn << 12);
	int cpu = smp_processor_id();
	if (dev_base != mmcfg_last_accessed_device ||
	    cpu != mmcfg_last_accessed_cpu) {
		mmcfg_last_accessed_device = dev_base;
		mmcfg_last_accessed_cpu = cpu;
		set_fixmap_nocache(FIX_PCIE_MCFG, dev_base);
	}
}

During PCI enumeration or interleaved config accesses across devices or
CPUs on CONFIG_X86_32, routing reg < 256 through pci_mmcfg still
serializes on pci_config_lock while adding a PTE write and TLB flush via
set_fixmap_nocache() whenever the target device or CPU changes.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/4b37c09a330f78db0ac3265a9b8e278d1d7d6f1c.1796103197.git.josh@joshtriplett.org?part=1

      reply	other threads:[~2026-12-01  5:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  5:35 [PATCH v2] pci: Prefer MMCONFIG for all config space accesses if available Josh Triplett
2026-12-01  5:49 ` 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-242637@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=josh@joshtriplett.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