Skip to contentSkip to conversation

libxl_pci: Don't hold QMP connection while waiting

PATCH In review Anthony PERARD 5 participants 5 messages Oct 31, 2019 – Nov 18, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl_pci: Don't hold QMP connection while waiting

After sending the 'device_del' command for a PCI passthrough device, we wait until QEMU has effectively deleted the device, this involves executing more QMP commands. While waiting, libxl hold the connection.

It isn't necessary to hold the connection and it prevents others from making progress, so this patch releases the QMP connection.

For background:
e.g., when a guest is created with several pci passthrough attached, on xl destroy all the devices needs to be detach, and this is usually what happens:
- 'device_del' called for the 1st pci device
- 'query-pci' checking if pci still there, it is
- wait 1s
- 'query-pci' checking again, and it's gone
-> now the same can be done for the second pci device, so plenty of waiting on others when pci detach can be done in parallel.

On shutdown, libxl usually keeps waiting because QEMU never releases the device because the guest kernel never responds QEMU's unplug queries. So detaching of the 1st device waits until a timeout stops it, and since the same timeout is setup at the same time for the other devices to detach, the 'device_del' command is never sent for those.

---
 tools/libxl/libxl_pci.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_pci.c +2 -0
index b5444d15523a..3262c2952baa 100644
@@ -2061,6 +2061,8 @@ static void pci_remove_qmp_query_cb(libxl__egc *egc,
 
     if (rc) goto out;
 
+    libxl__ev_qmp_dispose(gc, qmp);
+
     asked_id = GCSPRINTF(PCI_PT_QDEV_ID,
                          pcidev->bus, pcidev->dev, pcidev->func);
 
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 19 lines · Anthony PERARD

After sending the 'device_del' command for a PCI passthrough device, we wait until QEMU has effectively deleted the device, this involves executing more QMP commands. While waiting, libxl hold the connection.

It isn't necessary to hold the connection and it prevents others from making progress, so this patch releases the QMP connection.

For background:
e.g., when a guest is created with several pci passthrough attached, on xl destroy all the devices needs to be detach, and this is usually what happens:
- 'device_del' called for the 1st pci device
- 'query-pci' checking if pci still there, it is
- wait 1s
- 'query-pci' checking again, and it's gone
-> now the same can be done for the second pci device, so plenty of waiting on others when pci detach can be done in parallel.

Quoted 8 lines

On shutdown, libxl usually keeps waiting because QEMU never releases the device because the guest kernel never responds QEMU's unplug queries. So detaching of the 1st device waits until a timeout stops it, and since the same timeout is setup at the same time for the other devices to detach, the 'device_del' command is never sent for those.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 27 lines · Jürgen Groß
Quoted 26 lines · Anthony PERARD

After sending the 'device_del' command for a PCI passthrough device, we wait until QEMU has effectively deleted the device, this involves executing more QMP commands. While waiting, libxl hold the connection.

It isn't necessary to hold the connection and it prevents others from making progress, so this patch releases the QMP connection.

For background:
e.g., when a guest is created with several pci passthrough attached, on xl destroy all the devices needs to be detach, and this is usually what happens:
- 'device_del' called for the 1st pci device
- 'query-pci' checking if pci still there, it is
- wait 1s
- 'query-pci' checking again, and it's gone
-> now the same can be done for the second pci device, so plenty of waiting on others when pci detach can be done in parallel.

On shutdown, libxl usually keeps waiting because QEMU never releases the device because the guest kernel never responds QEMU's unplug queries. So detaching of the 1st device waits until a timeout stops it, and since the same timeout is setup at the same time for the other devices to detach, the 'device_del' command is never sent for those.

Quoted 6 lines
Quoted 1 line

Juergen

Hi Juergen,

Since a lot more recent patches have been committed, but these don't seem to.
I was wondering if this one fell through the cracks.

--
Sander

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 1/1
#3 lore raw
In reply to Anthony PERARD

Anthony PERARD writes ("[XEN PATCH for-4.13] libxl_pci: Don't hold QMP connection while waiting"):

Quoted 3 lines

After sending the 'device_del' command for a PCI passthrough device, we wait until QEMU has effectively deleted the device, this involves executing more QMP commands. While waiting, libxl hold the connection.

I just read the code here. It seems to poll on a timer. How ugly.

Quoted 2 lines

It isn't necessary to hold the connection and it prevents others from making progress, so this patch releases the QMP connection.

Right.

tools/libxl/libxl_pci.c static void pci_remove_qmp_query_cb(libxl__egc *egc, · line 2066

Quoted 5 lines
     if (rc) goto out;
tools/libxl/libxl_pci.c +2 -0
+    libxl__ev_qmp_dispose(gc, qmp);
+
     asked_id = GCSPRINTF(PCI_PT_QDEV_ID,

It's not it entirely clear to me why you dispose this before the error exit, but I think it doesn't matter. If it does matter then please explain :-).

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 18 lines · Ian Jackson

Anthony PERARD writes ("[XEN PATCH for-4.13] libxl_pci: Don't hold QMP connection while waiting"):

Quoted 3 lines

After sending the 'device_del' command for a PCI passthrough device, we wait until QEMU has effectively deleted the device, this involves executing more QMP commands. While waiting, libxl hold the connection.

I just read the code here. It seems to poll on a timer. How ugly.

Quoted 2 lines

It isn't necessary to hold the connection and it prevents others from making progress, so this patch releases the QMP connection.

Right.

tools/libxl/libxl_pci.c static void pci_remove_qmp_query_cb(libxl__egc *egc, · line 2066

Quoted 5 lines
     if (rc) goto out;
tools/libxl/libxl_pci.c +2 -0
+    libxl__ev_qmp_dispose(gc, qmp);
+
     asked_id = GCSPRINTF(PCI_PT_QDEV_ID,
Quoted 5 lines

It's not it entirely clear to me why you dispose this before the error exit, but I think it doesn't matter. If it does matter then please explain :-).

PUshed.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel