From: Manish Honap <[email protected]> A CXL Type-2 device must quiesce its coherent link before any reset and restore its HDM decoder state afterward, or a reset can leave the device mastering the bus over decoders that are no longer valid. This has to happen around every reset the PCI core drives for the device, not only the ones VFIO issues directly.
Add reset_prepare and reset_done to the CXL ops and register the matching pci_error_handlers callbacks. Assisted-by: LLM Signed-off-by: Manish Honap <[email protected]> --- drivers/vfio/pci/vfio_pci_core.c | 18 ++++++++++++++++++ include/linux/vfio_pci_core.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 2f593b2721a1..a91e07181847 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -2794,8 +2794,26 @@ int vfio_pci_core_sriov_configure(struct vfio_pci_core_device *vdev, } EXPORT_SYMBOL_GPL(vfio_pci_core_sriov_configure); +static void vfio_pci_core_reset_prepare(struct pci_dev *pdev) +{ + struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); + + if (vdev->cxl_ops) + vdev->cxl_ops->reset_prepare(vdev); +} + +static void vfio_pci_core_reset_done(struct pci_dev *pdev) +{ + struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); + + if (vdev->cxl_ops) + vdev->cxl_ops->reset_done(vdev); +} + const struct pci_error_handlers vfio_pci_core_err_handlers = { .error_detected = vfio_pci_core_aer_err_detected, + .reset_prepare = vfio_pci_core_reset_prepare, + .reset_done = vfio_pci_core_reset_done, }; EXPORT_SYMBOL_GPL(vfio_pci_core_err_handlers); diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index 643f32c2141f..6ebf9a26275e 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -72,6 +72,8 @@ struct vfio_cxl_ops { void (*release)(struct vfio_pci_core_device *vdev); int (*open_device)(struct vfio_pci_core_device *vdev); void (*close_device)(struct vfio_pci_core_device *vdev); + void (*reset_prepare)(struct vfio_pci_core_device *vdev); + void (*reset_done)(struct vfio_pci_core_device *vdev); /* Pinned per bound CXL device so vfio-cxl cannot unload under usage */ struct module *owner; }; -- 2.25.1

