From: Vipin Sharma <[email protected]> Do not reset the device when a Live Update preserved vfio-pci device is retrieved and first enabled. vfio_pci_liveupdate_freeze() guarantees the device is reset prior to Live Update, so there's no reason to reset it again after Live Update.
Since VFIO normally uses the initial reset to detect if the device supports function resets, pass that from the previous kernel via struct vfio_pci_core_dev_ser. Signed-off-by: Vipin Sharma <[email protected]> Signed-off-by: David Matlack <[email protected]> --- drivers/vfio/pci/vfio_pci_core.c | 31 ++++++++++++++++++++++---- drivers/vfio/pci/vfio_pci_liveupdate.c | 4 ++++ include/linux/kho/abi/vfio_pci.h | 4 +++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index d7c472cf4729..849a3b57d56b 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -16,6 +16,7 @@ #include <linux/file.h> #include <linux/interrupt.h> #include <linux/iommu.h> +#include <linux/kho/abi/vfio_pci.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/notifier.h> @@ -494,6 +495,30 @@ static const struct dev_pm_ops vfio_pci_core_pm_ops = { NULL) }; +static int vfio_pci_core_probe_reset(struct vfio_pci_core_device *vdev) +{ + int ret; + + /* + * This device was preserved by the previous kernel across a Live + * Update, so it does not need to be reset and reset_works can be + * inherited from the previous kernel. + */ + if (vdev->liveupdate_incoming_state) { + vdev->reset_works = vdev->liveupdate_incoming_state->reset_works; + return 0; + } + + ret = pci_try_reset_function(vdev->pdev); + + /* Bail if the device lock cannot be acquired. */ + if (ret == -EAGAIN) + return ret; + + vdev->reset_works = !ret; + return 0; +} + int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; @@ -514,12 +539,10 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) if (ret) goto out_power; - /* If reset fails because of the device lock, fail this path entirely */ - ret = pci_try_reset_function(pdev); - if (ret == -EAGAIN) + ret = vfio_pci_core_probe_reset(vdev); + if (ret) goto out_disable_device; - vdev->reset_works = !ret; pci_save_state(pdev); vdev->pci_saved_state = pci_store_saved_state(pdev); if (!vdev->pci_saved_state) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c index 8d6681e1d328..874c821bf6eb 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -91,6 +91,9 @@ * kernel guarantees the these will not change across a kexec when a device * is preserved. * + * * Whether or not the device supports function resets. This is necessary to + * avoid resetting the device after kexec to probe for reset support. + * * Since the kernel is not yet prepared to preserve all parts of the device and * its dependencies (such as DMA mappings), VFIO currently resets and restores * preserved devices back into an idle state during kexec, before handing off @@ -162,6 +165,7 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) ser->bdf = pci_dev_id(pdev); ser->domain = pci_domain_nr(pdev->bus); + ser->reset_works = vdev->reset_works; args->serialized_data = virt_to_phys(ser); return 0; diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_pci.h index 876aaf81dd92..c057794a044f 100644 --- a/include/linux/kho/abi/vfio_pci.h +++ b/include/linux/kho/abi/vfio_pci.h @@ -26,7 +26,7 @@ * incrementing the version number in the VFIO_PCI_LUO_FH_COMPATIBLE string. */ -#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1" +#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v2" /** * struct vfio_pci_core_device_ser - Serialized state of a single VFIO PCI @@ -34,10 +34,12 @@ * * @domain: The device's PCI domain number (segment). * @bdf: The device's PCI bus, device, and function number. + * @reset_works: Non-zero if the device supports function resets. */ struct vfio_pci_core_device_ser { u32 domain; u16 bdf; + u8 reset_works; } __packed; #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ -- 2.53.0.983.g0bb29b3bc5-goog

