Skip to contentSkip to conversation

failover: fix unplug pending detection

PATCH Superseded Laurent Vivier 2 participants 5 messages Sep 30, 2021 – Oct 1, 2021

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 failover: fix unplug pending detection

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

    17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

---
 hw/acpi/pcihp.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/acpi/pcihp.c +6 -0
index f610a25d2ef9..a2d27a3c4763 100644
@@ -366,6 +366,11 @@ void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
     trace_acpi_pci_unplug(PCI_SLOT(pdev->devfn),
                           acpi_pcihp_get_bsel(pci_get_bus(pdev)));
 
+    if (pdev->partially_hotplugged) {
+        pdev->qdev.pending_deleted_event = false;
+        return;
+    }
+
     /*
      * clean up acpi-index so it could reused by another device
      */
@@ -396,6 +401,7 @@ void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
         return;
     }
 
+    pdev->qdev.pending_deleted_event = true;
     s->acpi_pcihp_pci_status[bsel].down |= (1U << slot);
     acpi_send_event(DEVICE(hotplug_dev), ACPI_PCI_HOTPLUG_STATUS);
 }
Signature · 1 line
2.31.1
#1 lore raw
Quoted 16 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

    17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

Quoted 2 lines

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Ok so I have a basic question about partially_hotplugged flag in the device struct (there were no comments added in a99c4da9fc2a39847 explaining it). It seems we return early from pcie_unplug_device() when this flag is set from failover_unplug_primary() in virtio-net. What is the purpose of this flag? It seems we are not doing a full unplug of the primary device?

Quoted 34 lines
---
 hw/acpi/pcihp.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/acpi/pcihp.c +6 -1
index f610a25d2ef9..a2d27a3c4763 100644
@@ -366,6 +366,11 @@ void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
     trace_acpi_pci_unplug(PCI_SLOT(pdev->devfn),
                           acpi_pcihp_get_bsel(pci_get_bus(pdev)));
 
+    if (pdev->partially_hotplugged) {
+        pdev->qdev.pending_deleted_event = false;
+        return;
+    }
+
     /*
      * clean up acpi-index so it could reused by another device
      */
@@ -396,6 +401,7 @@ void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
         return;
     }
 
+    pdev->qdev.pending_deleted_event = true;
     s->acpi_pcihp_pci_status[bsel].down |= (1U << slot);
     acpi_send_event(DEVICE(hotplug_dev), ACPI_PCI_HOTPLUG_STATUS);
 }
--

2.31.1

#2 lore raw
Quoted 23 lines · Ani Sinha
Quoted 16 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in pcie_unplug_device().

But since

     17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

Quoted 2 lines

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Quoted 6 lines

Ok so I have a basic question about partially_hotplugged flag in the device struct (there were no comments added in a99c4da9fc2a39847 explaining it). It seems we return early from pcie_unplug_device() when this flag is set from failover_unplug_primary() in virtio-net. What is the purpose of this flag? It seems we are not doing a full unplug of the primary device?

Yes, to be able to plug it back in case of migration failure we must keep all the data structures.

But reading the code again it seems this part should be in acpi_pcihp_eject_slot() rather than in acpi_pcihp_device_unplug_cb() to prevent the hotplug_handler_unplug()/object_unparent() rather than the qdev_unrealize() (to be like in pcie.c).

Thanks,
Laurent

#3 lore raw
Quoted 34 lines · Laurent Vivier
Quoted 26 lines · Ani Sinha
Quoted 19 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in
pcie_unplug_device().

But since

     17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on

Q35")
we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any
problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

Quoted 2 lines

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Quoted 6 lines

Ok so I have a basic question about partially_hotplugged flag in the device struct (there were no comments added in a99c4da9fc2a39847 explaining it). It seems we return early from pcie_unplug_device() when this flag is set from failover_unplug_primary() in virtio-net. What is the purpose of this flag? It seems we are not doing a full unplug of the primary device?

Quoted 2 lines

Yes, to be able to plug it back in case of migration failure we must keep all the data structures.

Ok so two things here:
(a) could you please add a comment to PCIDevice struct in pci.h to clarify what the flag actually means, why it is there and what it is supposed to do.

(b) the naming of the variable could be something like do_partial_unplug or some such. This could be a separate patch.

Quoted 5 lines

But reading the code again it seems this part should be in acpi_pcihp_eject_slot() rather than in acpi_pcihp_device_unplug_cb() to prevent the hotplug_handler_unplug()/object_unparent() rather than the qdev_unrealize() (to be like in pcie.c).

Correct. You need to place the check earlier so as to be equivalent to what the native hotplug code does.

#4 lore raw
Quoted 38 lines · Ani Sinha
Quoted 34 lines · Laurent Vivier
Quoted 32 lines · Ani Sinha
Quoted 19 lines · Laurent Vivier

Failover needs to detect the end of the PCI unplug to start migration after the VFIO card has been unplugged.

To do that, a flag is set in pcie_cap_slot_unplug_request_cb() and reset in
pcie_unplug_device().

But since

      17858a169508 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on

Q35")
we have switched to ACPI unplug and these functions are not called anymore and the flag not set. So failover migration is not able to detect if card is really unplugged and acts as it's done as soon as it's started. So it doesn't wait the end of the unplug to start the migration. We don't see any
problem when we test that because ACPI unplug is faster than PCIe native hotplug and when the migration really starts the unplug operation is already done.

Quoted 2 lines

See c000a9bd06ea ("pci: mark device having guest unplug request pending")
a99c4da9fc2a ("pci: mark devices partially unplugged")

Ok so I have a basic question about partially_hotplugged flag in the device struct (there were no comments added in a99c4da9fc2a39847 explaining it). It seems we return early from pcie_unplug_device() when this flag is set from failover_unplug_primary() in virtio-net. What is the purpose of this flag? It seems we are not doing a full unplug of the primary device?

Quoted 7 lines
Quoted 2 lines

Yes, to be able to plug it back in case of migration failure we must keep all the data structures.

Ok so two things here:
(a) could you please add a comment to PCIDevice struct in pci.h to clarify what the flag actually means, why it is there and what it is supposed to do.

Will be in v3.

Quoted 2 lines

(b) the naming of the variable could be something like do_partial_unplug or some such. This could be a separate patch.

OK, I'll do that on a separate patch: I'm already working on a patch series moving most of the failover code to PCI files (hotplug is a PCI feature not a virtio one).

https://patchew.org/QEMU/[email protected]/

Quoted 9 lines
Quoted 5 lines

But reading the code again it seems this part should be in acpi_pcihp_eject_slot() rather than in acpi_pcihp_device_unplug_cb() to prevent the hotplug_handler_unplug()/object_unparent() rather than the qdev_unrealize() (to be like in pcie.c).

Correct. You need to place the check earlier so as to be equivalent to what the native hotplug code does.

Thanks,
Laurent