From: <mhonap@nvidia.com>
To: <alex@shazbot.org>, <ankita@nvidia.com>, <satyanarayana.k.v.p@intel.com>
Cc: <kjaju@nvidia.com>, <mhonap@nvidia.com>, <kvm@vger.kernel.org>,
<linux-cxl@vger.kernel.org>
Subject: [PATCH 1/2] vfio/pci: Find the start of an abutting extended capability
Date: Wed, 2 Dec 2026 14:41:04 +0530 [thread overview]
Message-ID: <20261202091105.1674275-2-mhonap@nvidia.com> (raw)
In-Reply-To: <20261202091105.1674275-1-mhonap@nvidia.com>
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.
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.
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 */
+ 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--;
--
2.53.0
next prev parent reply other threads:[~2026-12-02 9:11 UTC|newest]
Thread overview: 5+ 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 ` mhonap [this message]
2026-12-02 9:21 ` [PATCH 1/2] vfio/pci: Find the start of an abutting extended capability sashiko-bot
2026-12-02 9:11 ` [PATCH 2/2] vfio/pci: Make the CXL DVSEC read-only mhonap
2026-12-02 9:22 ` sashiko-bot
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=20261202091105.1674275-2-mhonap@nvidia.com \
--to=mhonap@nvidia.com \
--cc=alex@shazbot.org \
--cc=ankita@nvidia.com \
--cc=kjaju@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.