On Thu, 17 Sep 2026 00:05:25 +0530 <[email protected]> wrote: > From: Manish Honap <[email protected]> > > 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 <[email protected]> > --- > 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. > + 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; > + } > +}

