[PATCH v5 21/27] vfio/cxl: Exclude the HDM decoder registers from direct BAR access
From: mhonap
Date: Wed Sep 16 2026 - 15:13:01 EST
From: Manish Honap <mhonap@xxxxxxxxxx>
The HDM decoder register block lives in the component BAR that vfio-pci
owns. The guest reads the decoder only through the trapped, read-only
decoder region; it must not reach the physical registers through the BAR
directly, and a host read of the range through a kernel mapping could
abort as a fatal host SError.
Add the block to the generic excluded-range list with
VFIO_PCI_EXCLUDE_MMAP | VFIO_PCI_EXCLUDE_READ | VFIO_PCI_EXCLUDE_WRITE
similar to the MSI-X exclusion.
Assisted-by: LLM
Signed-off-by: Manish Honap <mhonap@xxxxxxxxxx>
---
drivers/vfio/pci/cxl/vfio_cxl_core.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/vfio/pci/cxl/vfio_cxl_core.c b/drivers/vfio/pci/cxl/vfio_cxl_core.c
index da04776356e4..37e8a3b54cfb 100644
--- a/drivers/vfio/pci/cxl/vfio_cxl_core.c
+++ b/drivers/vfio/pci/cxl/vfio_cxl_core.c
@@ -435,8 +435,25 @@ static int vfio_cxl_add_region(struct vfio_pci_core_device *vdev, u32 subtype,
static int vfio_cxl_open_device(struct vfio_pci_core_device *vdev)
{
struct vfio_cxl_state *cxl = vdev->cxl;
+ struct pci_dev *pdev = vdev->pdev;
int ret;
+ /*
+ * Keep the HDM decoder block out of the guest's direct BAR access: the
+ * guest reaches it only through the trapped decoder region, and a host
+ * read of the range through a kernel mapping could abort as an SError.
+ * Exclude it from mmap, fill reads with -1 and drop writes. The list is
+ * cleared on close, so re-add it per open.
+ */
+ ret = vfio_pci_core_add_excluded_range(vdev, pdev->hdm->hdm_bar,
+ pdev->hdm->hdm_offset,
+ cxl->hdm_len,
+ VFIO_PCI_EXCLUDE_MMAP |
+ VFIO_PCI_EXCLUDE_READ |
+ VFIO_PCI_EXCLUDE_WRITE);
+ if (ret)
+ return ret;
+
/*
* vfio_pci_core_disable() frees all dynamic regions on close, so register
* them here per open rather than at bind. A failed first open never
--
2.25.1