On Thu, 17 Sep 2026 00:05:24 +0530
<[email protected]> wrote:
> +/* Virtualize the CXL DVSEC so a guest cannot reprogram the device through 
> it. */
> +static int vfio_cxl_dvsec_init(struct vfio_pci_core_device *vdev)
> +{
> +     struct pci_dev *pdev = vdev->pdev;
> +     u32 dword;
> +     u16 dvsec;
> +     int len, ret;
> +
> +     dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
> +                                       PCI_DVSEC_CXL_DEVICE);
> +     if (!dvsec)
> +             return 0;
> +
> +     ret = pci_read_config_dword(pdev, dvsec + PCI_DVSEC_HEADER1, &dword);
> +     if (ret)
> +             return pcibios_err_to_errno(ret);
> +     len = PCI_DVSEC_HEADER1_LEN(dword);
> +
> +     /*
> +      * The virtualization writes fixed DVSEC offsets up to Status2 (the 
> reset
> +      * doorbell stamps it). A device that reports a shorter DVSEC is not a
> +      * usable Type-2 function; leave it as plain vfio-pci rather than index 
> the
> +      * device-length-sized perm allocation past its end.
> +      */
> +     if (len < PCI_DVSEC_CXL_STATUS2 + 2)
> +             return 0;
> +
> +     vdev->cxl_perm = kmalloc_obj(struct perm_bits, GFP_KERNEL_ACCOUNT);
> +     if (!vdev->cxl_perm)
> +             return -ENOMEM;
> +
> +     ret = init_cxl_dvsec_perm(vdev->cxl_perm, len);
> +     if (ret) {
> +             kfree(vdev->cxl_perm);
> +             vdev->cxl_perm = NULL;
> +             return ret;
> +     }
> +
> +     vdev->cxl_dvsec = dvsec;
> +     vdev->cxl_dvsec_len = len;

cxl_dvsec_len is never used here or elsewhere in the series.  Thanks,

Alex

> +
> +     return 0;
> +}
> +

Reply via email to