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 2/2] vfio/pci: Make the CXL DVSEC read-only
Date: Wed, 2 Dec 2026 14:41:05 +0530 [thread overview]
Message-ID: <20261202091105.1674275-3-mhonap@nvidia.com> (raw)
In-Reply-To: <20261202091105.1674275-1-mhonap@nvidia.com>
From: Manish Honap <mhonap@nvidia.com>
Since commit 6467d0740a2b ("vfio/pci: Add DVSEC PCI Extended Config
Capability to user visible list."), vfio-pci passes user writes to
every DVSEC through to the device. Before that commit DVSECs were
hidden.
For a function that is CXL.cache and CXL.mem capable, the user can then:
- clear Cache_Enable or Mem_Enable in DVSEC Control,
- set Initiate CXL Reset or Initiate Cache Writeback and Invalidation
in DVSEC Control2, which the host does not see or handle,
- write the DVSEC Range registers,
- set Config Lock, after which the host cannot change the locked
registers.
This change keeps the CXL Device DVSEC visible and makes it read-only:
reads return the device values and writes are dropped. The capability is
matched by its start, so a CXL DVSEC that directly follows another DVSEC
relies on the earlier patch to correctly calculate start of abutting
capabilities.
Fixes: 6467d0740a2b ("vfio/pci: Add DVSEC PCI Extended Config Capability to user visible list.")
Signed-off-by: Manish Honap <mhonap@nvidia.com>
---
drivers/vfio/pci/vfio_pci_config.c | 23 +++++++++++++++++++++++
include/linux/vfio_pci_core.h | 1 +
2 files changed, 24 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index dd0b899fbdfd..2bc0c7cbc4b7 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -1746,6 +1746,23 @@ static int vfio_ecap_init(struct vfio_pci_core_device *vdev)
return 0;
}
+static u16 vfio_pci_cxl_dvsec(struct pci_dev *pdev)
+{
+ u16 dvsec, cap;
+
+ dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
+ PCI_DVSEC_CXL_DEVICE);
+ if (!dvsec ||
+ pci_read_config_word(pdev, dvsec + PCI_DVSEC_CXL_CAP, &cap))
+ return 0;
+
+ if (!(cap & PCI_DVSEC_CXL_CACHE_CAPABLE) ||
+ !(cap & PCI_DVSEC_CXL_MEM_CAPABLE))
+ return 0;
+
+ return dvsec;
+}
+
/*
* Nag about hardware bugs, hopefully to have vendors fix them, but at least
* to collect a list of dependencies for the VF INTx pin quirk below.
@@ -1863,6 +1880,8 @@ int vfio_config_init(struct vfio_pci_core_device *vdev)
if (ret)
goto out;
+ vdev->cxl_dvsec = vfio_pci_cxl_dvsec(vdev->pdev);
+
return 0;
out:
@@ -1953,6 +1972,10 @@ ssize_t vfio_pci_config_rw_single(struct vfio_pci_core_device *vdev,
perm = &ecap_perms[cap_id];
cap_start = vfio_find_cap_start(vdev, *ppos);
+
+ if (cap_id == PCI_EXT_CAP_ID_DVSEC &&
+ cap_start == vdev->cxl_dvsec)
+ perm = &direct_ro_perms;
} else {
WARN_ON(cap_id > PCI_CAP_ID_MAX);
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 2f3fa2787737..dc25f737fe93 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -109,6 +109,7 @@ struct vfio_pci_core_device {
u8 *pci_config_map;
u8 *vconfig;
struct perm_bits *msi_perm;
+ u16 cxl_dvsec;
spinlock_t irqlock;
struct mutex igate;
struct xarray ctx;
--
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 ` [PATCH 1/2] vfio/pci: Find the start of an abutting extended capability mhonap
2026-12-02 9:21 ` sashiko-bot
2026-12-02 9:11 ` mhonap [this message]
2026-12-02 9:22 ` [PATCH 2/2] vfio/pci: Make the CXL DVSEC read-only 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-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox