Re: [RFC v2 06/15] vfio/cxl: introduce vfio-cxl core preludes

Jonathan Cameron
2025-12-22T13:54:05Z

On Tue, 9 Dec 2025 22:20:10 +0530
mhonap@nvidia.com wrote:

> From: Manish Honap <mhonap@nvidia.com>
>
> In VFIO, common functions that used by VFIO variant drivers are managed
> in a set of "core" functions. E.g. the vfio-pci-core provides the common
> functions used by VFIO variant drviers to support PCI device
> passhthrough.
>
> Although the CXL type-2 device has a PCI-compatible interface for device
> configuration and programming, they still needs special handlings when
> initialize the device:
>
> - Probing the CXL DVSECs in the configuration.
> - Probing the CXL register groups implemented by the device.
> - Configuring the CXL device state required by the kernel CXL core.
> - Create the CXL region.
> - Special handlings of the CXL MMIO BAR.
>
> Introduce vfio-cxl core preludes to hold all the common functions used
> by VFIO variant drivers to support CXL device passthrough.
>
> Co-developed-by: Zhi Wang <zhiw@nvidia.com>
> Signed-off-by: Zhi Wang <zhiw@nvidia.com>
> Signed-off-by: Manish Honap <mhonap@nvidia.com>

One trivial thing from a first look.

> diff --git a/drivers/vfio/pci/vfio_cxl_core.c b/drivers/vfio/pci/vfio_cxl_core.c
> new file mode 100644
> index 000000000000..cf53720c0cb7
> --- /dev/null
> +++ b/drivers/vfio/pci/vfio_cxl_core.c
> @@ -0,0 +1,238 @@

> +
> +int vfio_cxl_core_create_cxl_region(struct vfio_cxl_core_device *cxl, u64 size)
> +{
> + struct cxl_region *region;
> + struct range range;
> + int ret;
> + struct vfio_cxl *cxl_core = cxl->cxl_core;
> +
> + if (WARN_ON(cxl_core->region.region))
> + return -EEXIST;
> +
> + ret = get_hpa_and_request_dpa(cxl, size);
> + if (ret)
> + return ret;
> +
> + region = cxl_create_region(cxl_core->cxlrd, &cxl_core->cxled, true);
> + if (IS_ERR(region)) {
> + ret = PTR_ERR(region);
> + cxl_dpa_free(cxl_core->cxled);
> + return ret;

Trivial but might as well do:

return PTR_ERR(region);

and save a line.

> + }
> +
> + cxl_get_region_range(region, &range);
> +
> + cxl_core->region.addr = range.start;
> + cxl_core->region.size = size;
> + cxl_core->region.region = region;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(vfio_cxl_core_create_cxl_region);