[PATCH v6 20/31] vfio/cxl: Own the whole component register BAR

From: mhonap

Date: Fri Oct 16 2026 - 12:53:09 EST


From: Manish Honap <mhonap@xxxxxxxxxx>

devm_cxl_probe_mem() maps the component registers through the CXL core,
which by default claims each HDM and RAS sub-block. That collides with
the full-BAR request vfio-pci-core makes when the guest opens the device.

After the component registers are discovered, declare the containing BAR
owned with cxl_reg_map_set_owned_resource(). The core then ioremaps the
sub-blocks without requesting them, so vfio-pci-core owns the whole BAR
and the requests do not collide.

Assisted-by: LLM
Signed-off-by: Manish Honap <mhonap@xxxxxxxxxx>
---
drivers/vfio/pci/cxl/vfio_cxl_core.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/pci/cxl/vfio_cxl_core.c b/drivers/vfio/pci/cxl/vfio_cxl_core.c
index ef1fc715020e..052be27bc46f 100644
--- a/drivers/vfio/pci/cxl/vfio_cxl_core.c
+++ b/drivers/vfio/pci/cxl/vfio_cxl_core.c
@@ -33,8 +33,9 @@ struct vfio_cxl_state {
* Create the CXL device state and join the device to the CXL topology. The
* caller groups these devres allocations, so return on the first error.
*/
-static struct vfio_cxl_state *vfio_cxl_create_memdev(struct pci_dev *pdev,
- u64 hdm_size)
+static struct vfio_cxl_state *
+vfio_cxl_create_memdev(struct pci_dev *pdev, const struct cxl_hdm_info *hdm,
+ u64 hdm_size)
{
struct vfio_cxl_state *cxl;
struct cxl_memdev *cxlmd;
@@ -59,6 +60,17 @@ static struct vfio_cxl_state *vfio_cxl_create_memdev(struct pci_dev *pdev,
return ERR_PTR(ret);
}

+ /*
+ * vfio-pci-core requests the whole component-register BAR when the
+ * guest opens the device. Declare that BAR owned so the CXL core
+ * ioremaps the HDM and RAS sub-blocks without claiming them, and the
+ * full-BAR request does not collide.
+ */
+ ret = cxl_reg_map_set_owned_resource(&cxl->cxlds.reg_map,
+ pci_resource_n(pdev, hdm->hdm_bar));
+ if (ret)
+ return ERR_PTR(ret);
+
if (!cxl->cxlds.reg_map.component_map.hdm_decoder.valid) {
pci_err(pdev, "vfio-cxl: HDM decoder registers not found\n");
return ERR_PTR(-ENODEV);
@@ -133,7 +145,7 @@ static int vfio_cxl_init_device(struct vfio_pci_core_device *vdev)
if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
return -ENOMEM;

- cxl = vfio_cxl_create_memdev(pdev, hdm_size);
+ cxl = vfio_cxl_create_memdev(pdev, hdm, hdm_size);
if (IS_ERR(cxl)) {
devres_release_group(&pdev->dev, NULL);
return PTR_ERR(cxl);
--
2.53.0