Skip to contentSkip to conversation

libxl: fix cold plugged PCI devices with stubdomains

PATCH In review Ian Campbell 3 participants 7 messages Dec 9, 2011 – Dec 13, 2011 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 libxl: fix cold plugged PCI devices with stubdomains

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1323432076 0
# Node ID 9c1b223e152eaaa3861f9b6132590de0b4f6cb7e # Parent d8c390192ad1147d7202cf04be090478f1810a5d
libxl: fix cold plugged PCI devices with stubdomains

Since 23565:72eafe80ebc1 the xenstore entries for the stubdomain's PCI were never created and therefore the stubdom ends up waiting forever for the devices which it has been asked to insert to show up.

Since the stubdomain is already running when we call the libxl_device_pci_add loop in do_domain_create we should treat it as if "starting == 0".

tools/libxl/libxl_pci.c +2 -1
diff -r d8c390192ad1 -r 9c1b223e152e tools/libxl/libxl_pci.c
@@ -819,7 +819,8 @@ int libxl__device_pci_add(libxl__gc *gc,
     stubdomid = libxl_get_stubdom_id(ctx, domid);
     if (stubdomid != 0) {
         libxl_device_pci pcidev_s = *pcidev;
-        rc = do_pci_add(gc, stubdomid, &pcidev_s, starting);
+        /* stubdomain is always running by now, even at create time */
+        rc = do_pci_add(gc, stubdomid, &pcidev_s, 0);
         if ( rc )
             goto out;
     }
#2 lore raw
Quoted 7 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1323432076 0
# Node ID 9c1b223e152eaaa3861f9b6132590de0b4f6cb7e # Parent d8c390192ad1147d7202cf04be090478f1810a5d
libxl: fix cold plugged PCI devices with stubdomains

Quoted 8 lines

Since 23565:72eafe80ebc1 the xenstore entries for the stubdomain's PCI were never created and therefore the stubdom ends up waiting forever for the devices which it has been asked to insert to show up.

Since the stubdomain is already running when we call the libxl_device_pci_add loop in do_domain_create we should treat it as if "starting == 0".

Acked

Quoted 19 lines

diff -r d8c390192ad1 -r 9c1b223e152e tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +2 -1
@@ -819,7 +819,8 @@ int libxl__device_pci_add(libxl__gc *gc,
     stubdomid = libxl_get_stubdom_id(ctx, domid);
     if (stubdomid != 0) {
         libxl_device_pci pcidev_s = *pcidev;
-        rc = do_pci_add(gc, stubdomid, &pcidev_s, starting);
+        /* stubdomain is always running by now, even at create time */
+        rc = do_pci_add(gc, stubdomid, &pcidev_s, 0);
         if ( rc )
             goto out;
     }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Acked-by on v1 1/1
#3 lore raw
In reply to Ian Campbell

Ian Campbell writes ("[PATCH 1 of 2] libxl: fix cold plugged PCI devices with stubdomains"):

Quoted 9 lines

libxl: fix cold plugged PCI devices with stubdomains

Since 23565:72eafe80ebc1 the xenstore entries for the stubdomain's PCI were never created and therefore the stubdom ends up waiting forever for the devices which it has been asked to insert to show up.

Since the stubdomain is already running when we call the libxl_device_pci_add loop in do_domain_create we should treat it as if "starting == 0".

That sounds plausible.

Ian.

#4 lore raw

PATCH 1/1 mini-os: do not wait for pci backend in pcifront_scan

In reply to a message not in the archive

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1323432077 0
# Node ID d50241faddf372f2262627b9b2071d2a077e8151 # Parent 9c1b223e152eaaa3861f9b6132590de0b4f6cb7e
mini-os: do not wait for pci backend in pcifront_scan

This blocks the main thread indefinitely if there is no PCI backend present in xenstore.

Even in the case where there are passthrough devices configured libxl creates the stubdom and waits for it to startup _before_ adding the backend. Since the stub domains main thread is blocked before it can write the "running" state to xenstore the toolstack eventually times out and kills everything.

There is already a separate pcifront thread which waits for the backend to appear and calls init_pcifront at the appropriate time should a backend ever appear.

Unfortunately I don't have any free test boxes with VT-d so I haven't been able to test the cases where PCI deivces are passed through but I obviously have tested that I can now start an HVM domain with stub qemu without PCI devices passed through which I couldn't do before so this is an improvement. This stuff is a bit like pushing the lump around the carpet :-/

extras/mini-os/kernel.c +1 -0
diff -r 9c1b223e152e -r d50241faddf3 extras/mini-os/kernel.c
@@ -448,6 +448,7 @@ static void print_pcidev(unsigned int do
 
 static void pcifront_thread(void *p)
 {
+    pcifront_watches(NULL);
     pci_dev = init_pcifront(NULL);
     if (!pci_dev)
         return;
extras/mini-os/pcifront.c +3 -12
diff -r 9c1b223e152e -r d50241faddf3 extras/mini-os/pcifront.c
@@ -280,23 +280,14 @@ void pcifront_scan(struct pcifront_dev *
 {
     char *path;
     int i, n, len;
-    char *s, *msg = NULL, *err = NULL;
+    char *s, *msg = NULL;
     unsigned int domain, bus, slot, fun;
 
     if (!dev)
         dev = pcidev;
     if (!dev) {
-        xenbus_event_queue events = NULL;
-        char *fe_state = "device/pci/0/state";
-        xenbus_watch_path_token(XBT_NIL, fe_state, fe_state, &events);
-        while ((err = xenbus_read(XBT_NIL, fe_state, &msg)) != NULL || msg[0] != '4') {
-            free(msg);
-            free(err);
-            printk("pcifront_scan: waiting for pcifront to become ready\n");
-            xenbus_wait_for_watch(&events);
-        }
-        xenbus_unwatch_path_token(XBT_NIL, fe_state, fe_state);
-        dev = pcidev;
+	printk("pcifront_scan: device or bus\n");
+	return;
     }
 
     len = strlen(dev->backend) + 1 + 5 + 10 + 1;
Acked-by on v1 1/1
#5 lore raw

Re: [PATCH 2 of 2] mini-os: do not wait for pci backend in pcifront_scan

Ian Campbell writes ("[PATCH 2 of 2] mini-os: do not wait for pci backend in pcifront_scan"):

Quoted 9 lines

Even in the case where there are passthrough devices configured libxl creates the stubdom and waits for it to startup _before_ adding the backend. Since the stub domains main thread is blocked before it can write the "running" state to xenstore the toolstack eventually times out and kills everything.

There is already a separate pcifront thread which waits for the backend to appear and calls init_pcifront at the appropriate time should a backend ever appear.

Quoted 6 lines

Unfortunately I don't have any free test boxes with VT-d so I haven't been able to test the cases where PCI deivces are passed through but I obviously have tested that I can now start an HVM domain with stub qemu without PCI devices passed through which I couldn't do before so this is an improvement. This stuff is a bit like pushing the lump around the carpet :-/

Right. The worry would be, surely, that this somehow breaks by unpausing the guest before everything has been set up by the stubdom.

But I'm happy to ack this patch on the basis that it seemed to improve things for you and should be harmless for the non-stubdom case.

(Not applying it yet as the patch floodgate is still closed pending a test pass.)

Ian.

#6 lore raw

Re: [PATCH 2 of 2] mini-os: do not wait for pci backend in pcifront_scan

Quoted 17 lines · Ian Jackson

Ian Campbell writes ("[PATCH 2 of 2] mini-os: do not wait for pci backend in pcifront_scan"):

Quoted 9 lines

Even in the case where there are passthrough devices configured libxl creates the stubdom and waits for it to startup _before_ adding the backend. Since the stub domains main thread is blocked before it can write the "running" state to xenstore the toolstack eventually times out and kills everything.

There is already a separate pcifront thread which waits for the backend to appear and calls init_pcifront at the appropriate time should a backend ever appear.

Quoted 6 lines

Unfortunately I don't have any free test boxes with VT-d so I haven't been able to test the cases where PCI deivces are passed through but I obviously have tested that I can now start an HVM domain with stub qemu without PCI devices passed through which I couldn't do before so this is an improvement. This stuff is a bit like pushing the lump around the carpet :-/

Quoted 2 lines

Right. The worry would be, surely, that this somehow breaks by unpausing the guest before everything has been set up by the stubdom.

Yes. I was a bit unclear how this ever worked though...

We could potentially add something to libxl__create_pci_backend which interlocks against the stubdom pcifront but without a system with an IOMMU I'm not really in a position to test such a patch.

Quoted 2 lines

But I'm happy to ack this patch on the basis that it seemed to improve things for you and should be harmless for the non-stubdom case.

Thanks.

Quoted 4 lines

(Not applying it yet as the patch floodgate is still closed pending a test pass.)

Sure.

Ian.