Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Alex Williamson <alex@shazbot.org>
To: <mhonap@nvidia.com>
Cc: <ankita@nvidia.com>, <satyanarayana.k.v.p@intel.com>,
	<kjaju@nvidia.com>, <kvm@vger.kernel.org>,
	<linux-cxl@vger.kernel.org>,
	alex@shazbot.org
Subject: Re: [PATCH 1/2] vfio/pci: Find the start of an abutting extended capability
Date: Thu, 3 Dec 2026 13:55:29 -0700	[thread overview]
Message-ID: <20261203135529.2f28ff30@shazbot.org> (raw)
In-Reply-To: <20261202091105.1674275-2-mhonap@nvidia.com>

On Wed, 2 Dec 2026 14:41:04 +0530
<mhonap@nvidia.com> wrote:

> From: Manish Honap <mhonap@nvidia.com>
> 
> vfio_find_cap_start() walks through pci_config_map while the bytes hold
> same capability ID. When two DVSEC's are back-to-back, we cannot
> correctly tell what is the start of second capability. Due to this
> the offset into the second capability resolves to the start of first
> capability.

Yes, but what issue results from that?  AIUI, it breaks virtualization
of the next cap offset, so we don't provide the capability chain we
intended to.  Config space outside a capability has direct access, and
so does the DVSEC capability, so the bug is that we've jumped from the
virtualized to the physical capability chain.
 
> For above case, walk the extended vconfig capability chain for
> determining the correct start of the abutting capabilities.
> 
> Standard capabilities keep the walk back through the map.

Why, it has the same problem and we're even ignoring the comment that
raises this exact question.  Standard config space has fewer options
where a capability can have multiple instances, but the vendor specific
capability is at least one that could generate the same issue.

Needs a Fixes: tag, probably pointing back to the original XXX comment
below 89e1f7d4c66d.

> Signed-off-by: Manish Honap <mhonap@nvidia.com>
> ---
>  drivers/vfio/pci/vfio_pci_config.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index 9914f3ac69ae..dd0b899fbdfd 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -1129,6 +1129,23 @@ int __init vfio_pci_init_perm_bits(void)
>  	return ret;
>  }
>  
> +static int vfio_find_ecap_start(struct vfio_pci_core_device *vdev, int pos)
> +{
> +	struct pci_dev *pdev = vdev->pdev;
> +	int loops = (pdev->cfg_size - PCI_CFG_SPACE_SIZE) / PCI_CAP_SIZEOF;
> +	int epos = PCI_CFG_SPACE_SIZE, start = PCI_CFG_SPACE_SIZE;
> +
> +	while (loops-- && epos >= PCI_CFG_SPACE_SIZE) {
> +		u32 header = le32_to_cpu(*(__le32 *)&vdev->vconfig[epos]);
> +
> +		if (epos <= pos && epos > start)
> +			start = epos;
> +		epos = PCI_EXT_CAP_NEXT(header);
> +	}
> +
> +	return start;
> +}
> +
>  static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)
>  {
>  	u8 cap;
> @@ -1139,6 +1156,10 @@ static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)
>  	if (cap == PCI_CAP_ID_BASIC)
>  		return 0;
>  
> +	/* Abutting DVSECs share one map ID */

Any abutting capability shares the same ID in the map.  Don't focus on
only the capability you're tripping on.

> +	if (pos >= PCI_CFG_SPACE_SIZE)
> +		return vfio_find_ecap_start(vdev, pos);
> +
>  	/* XXX Can we have to abutting capabilities of the same type? */
>  	while (pos - 1 >= base && vdev->pci_config_map[pos - 1] == cap)
>  		pos--;

Address this with a standard capability version of the same.  The loop
can then go away.

It might also be worth adding a WARN_ON_ONCE(cap >= PCI_CAP_ID_INVALID_VIRT)
prior to either since those dummy IDs live outside capability chains.
Thanks,

Alex

  parent reply	other threads:[~2026-12-03 20:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:11 [PATCH 0/2] vfio/pci: CXL DVSEC config space fixes mhonap
2026-12-02  9:11 ` [PATCH 1/2] vfio/pci: Find the start of an abutting extended capability mhonap
2026-12-02  9:21   ` sashiko-bot
2026-12-03 20:55   ` Alex Williamson [this message]
2026-12-02  9:11 ` [PATCH 2/2] vfio/pci: Make the CXL DVSEC read-only mhonap
2026-12-02  9:22   ` sashiko-bot
2026-12-03 20:55   ` Alex Williamson

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=20261203135529.2f28ff30@shazbot.org \
    --to=alex@shazbot.org \
    --cc=ankita@nvidia.com \
    --cc=kjaju@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=mhonap@nvidia.com \
    --cc=satyanarayana.k.v.p@intel.com \
    /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