RE: [PATCH v5 11/27] vfio/pci: Virtualize the CXL DVSEC in vfio_pci_config.c

From: Manish Honap

Date: Fri Oct 09 2026 - 02:25:12 EST



> -----Original Message-----
> From: Alex Williamson <alex@xxxxxxxxxxx>
> Sent: Tuesday, September 22, 2026 7:45 AM
> To: Manish Honap <mhonap@xxxxxxxxxx>
> Cc: jgg@xxxxxxxx; Ankit Agrawal <ankita@xxxxxxxxxx>; jic23@xxxxxxxxxx;
> dave.jiang@xxxxxxxxx; alejandro.lucero-palau@xxxxxxx; Srirangan
> Madhavan <smadhavan@xxxxxxxxxx>; corbet@xxxxxxx;
> skhan@xxxxxxxxxxxxxxxxxxx; dave@xxxxxxxxxxxx; alison.schofield@xxxxxxxxx;
> vishal.l.verma@xxxxxxxxx; iweiny@xxxxxxxxxx; ming.li@xxxxxxxxxxxx; Yishai
> Hadas <yishaih@xxxxxxxxxx>; Shameer Kolothum Thodi
> <skolothumtho@xxxxxxxxxx>; kevin.tian@xxxxxxxxx; bhelgaas@xxxxxxxxxx;
> dmatlack@xxxxxxxxxx; kees@xxxxxxxxxx; gustavoars@xxxxxxxxxx; Neo Jia
> <cjia@xxxxxxxxxx>; Krishnakant Jaju <kjaju@xxxxxxxxxx>; Vikram Sethi
> <vsethi@xxxxxxxxxx>; Zhi Wang <zhiw@xxxxxxxxxx>; linux-
> doc@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; kvm@xxxxxxxxxxxxxxx;
> linux-cxl@xxxxxxxxxxxxxxx; linux-pci@xxxxxxxxxxxxxxx; linux-
> kselftest@xxxxxxxxxxxxxxx; linux-hardening@xxxxxxxxxxxxxxx; alex@xxxxxxxxxxx
> Subject: Re: [PATCH v5 11/27] vfio/pci: Virtualize the CXL DVSEC in
> vfio_pci_config.c
>
> External email: Use caution opening links or attachments
>
>
> On Thu, 17 Sep 2026 00:05:24 +0530
> <mhonap@xxxxxxxxxx> 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,

Yes, I will remove this in v6.

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