From: Manish Honap <[email protected]>

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 write through the BAR could uncommit or move an unlocked
decoder that the host relies on.

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 <[email protected]>
---
 drivers/vfio/pci/cxl/vfio_cxl_core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/vfio/pci/cxl/vfio_cxl_core.c 
b/drivers/vfio/pci/cxl/vfio_cxl_core.c
index 4a8aaa765a98..68e898ee1985 100644
--- a/drivers/vfio/pci/cxl/vfio_cxl_core.c
+++ b/drivers/vfio/pci/cxl/vfio_cxl_core.c
@@ -614,6 +614,22 @@ static int vfio_cxl_open_device(struct 
vfio_pci_core_device *vdev)
        struct vfio_cxl_state *cxl = vdev->cxl;
        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 write
+        * through the BAR could uncommit or move an unlocked decoder that the
+        * host relies on. 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, cxl->hdm->hdm_bar,
+                                              cxl->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 frees all dynamic regions on close and on a failed
         * open, so register them here per open rather than at bind.
-- 
2.53.0


Reply via email to