RE: [PATCH v5 12/27] vfio/pci: Call the CXL open and close hooks around device use
From: Manish Honap
Date: Fri Oct 09 2026 - 02:22:44 EST
> -----Original Message-----
> From: Jonathan Cameron <jic23@xxxxxxxxxx>
> Sent: Saturday, September 26, 2026 3:48 AM
> To: Manish Honap <mhonap@xxxxxxxxxx>
> Cc: alex@xxxxxxxxxxx; jgg@xxxxxxxx; Ankit Agrawal <ankita@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
> Subject: Re: [PATCH v5 12/27] vfio/pci: Call the CXL open and close hooks
> around device use
>
> External email: Use caution opening links or attachments
>
>
> On Thu, 17 Sep 2026 00:05:25 +0530
> <mhonap@xxxxxxxxxx> wrote:
>
> > From: Manish Honap <mhonap@xxxxxxxxxx>
> >
> > Volatile CXL register state must be sampled from live hardware when
> > the guest opens the device, not at bind, because a low-power
> > transition between bind and open can leave the bind-time values stale.
> >
> > Add open and close to the CXL ops and call them from the common enable
> > and close paths. A failed open unwinds the enable in reverse order:
> > unmap the BARs, drop the excluded ranges, then free the virtual config.
> >
> > Factor the BAR unmap out of vfio_pci_core_disable() into a helper so
> > the enable failure path and the disable path share it.
> >
> > Assisted-by: LLM
> > Signed-off-by: Manish Honap <mhonap@xxxxxxxxxx>
> > ---
> > drivers/vfio/pci/vfio_pci_core.c | 40 +++++++++++++++++++++++++-------
> > include/linux/vfio_pci_core.h | 2 ++
> > 2 files changed, 33 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/vfio/pci/vfio_pci_core.c
> > b/drivers/vfio/pci/vfio_pci_core.c
> > index c5b7a59a4548..2f593b2721a1 100644
> > --- a/drivers/vfio/pci/vfio_pci_core.c
> > +++ b/drivers/vfio/pci/vfio_pci_core.c
> > @@ -591,6 +591,21 @@ static const struct dev_pm_ops
> > vfio_pci_core_pm_ops = {
> >
> > static void vfio_pci_free_excluded_ranges(struct vfio_pci_core_device
> > *vdev);
> >
> > +static void vfio_pci_core_unmap_bars(struct vfio_pci_core_device
> > +*vdev) {
> > + struct pci_dev *pdev = vdev->pdev;
> > + int i, bar;
> > +
> > + for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> for (int i = 0; i < PCI_STD_NUM_BARS; i++)
> int bar = i + PCI_STD_RESOURCES;
>
> Nice to keep things tightly scoped where we can.
Agreed; I will change this in v6.
>
> > + bar = i + PCI_STD_RESOURCES;
> > + if (IS_ERR_OR_NULL(vdev->barmap[bar]))
> > + continue;
> > + pci_iounmap(pdev, vdev->barmap[bar]);
> > + pci_release_selected_regions(pdev, 1 << bar);
> > + vdev->barmap[bar] = NULL;
> > + }
> > +}
>