Skip to content

Commit 728c2ed

Browse files
jandryukjgross1
authored andcommitted
xen-pcifront: Handle missed Connected state
An HVM guest with linux stubdomain and 2 PCI devices failed to start as libxl timed out waiting for the PCI devices to be added. It happens intermittently but with some regularity. libxl wrote the two xenstore entries for the devices, but then timed out waiting for backend state 4 (Connected) - the state stayed at 7 (Reconfiguring). (PCI passthrough to an HVM with stubdomain is PV passthrough to the stubdomain and then HVM passthrough with the QEMU inside the stubdomain.) The stubdomain kernel never printed "pcifront pci-0: Installing PCI frontend", so it seems to have missed state 4 which would have called pcifront_try_connect() -> pcifront_connect_and_init_dma() Have pcifront_detach_devices() special-case state Initialised and call pcifront_connect_and_init_dma(). Don't use pcifront_try_connect() because that sets the xenbus state which may throw off the backend. After connecting, skip the remainder of detach_devices since none have been initialized yet. When the backend switches to Reconfigured, pcifront_attach_devices() will pick them up again. Signed-off-by: Jason Andryuk <[email protected]> Reviewed-by: Juergen Gross <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 4fe89d0 commit 728c2ed

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/pci/xen-pcifront.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,13 +981,26 @@ static int pcifront_detach_devices(struct pcifront_device *pdev)
981981
{
982982
int err = 0;
983983
int i, num_devs;
984+
enum xenbus_state state;
984985
unsigned int domain, bus, slot, func;
985986
struct pci_dev *pci_dev;
986987
char str[64];
987988

988-
if (xenbus_read_driver_state(pdev->xdev->nodename) !=
989-
XenbusStateConnected)
989+
state = xenbus_read_driver_state(pdev->xdev->nodename);
990+
if (state == XenbusStateInitialised) {
991+
dev_dbg(&pdev->xdev->dev, "Handle skipped connect.\n");
992+
/* We missed Connected and need to initialize. */
993+
err = pcifront_connect_and_init_dma(pdev);
994+
if (err && err != -EEXIST) {
995+
xenbus_dev_fatal(pdev->xdev, err,
996+
"Error setting up PCI Frontend");
997+
goto out;
998+
}
999+
1000+
goto out_switch_state;
1001+
} else if (state != XenbusStateConnected) {
9901002
goto out;
1003+
}
9911004

9921005
err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, "num_devs", "%d",
9931006
&num_devs);
@@ -1048,6 +1061,7 @@ static int pcifront_detach_devices(struct pcifront_device *pdev)
10481061
domain, bus, slot, func);
10491062
}
10501063

1064+
out_switch_state:
10511065
err = xenbus_switch_state(pdev->xdev, XenbusStateReconfiguring);
10521066

10531067
out:

0 commit comments

Comments
 (0)