From: Ian Jackson Date: Mon, 23 Mar 2009 17:00:50 +0000 (+0000) Subject: Fix passthrough regression X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b6b661fde6697db5678b5bc1f8496c6573f098d0;p=xenclient%2Fioemu.git Fix passthrough regression pt_init() iterates through the PHP slots independantly of the assignment that occurs inside __insert_to_pci_slot which is called by register_real_device(). It assumes that vslots are assigned in order sarting at PHP_SLOT_START. This was valid before my change, although why it didn't take the simpler option of just checking what value had been assigned to pt_dev->dev.devfn in register_real_device() is a mystery to me [Simon]. Its also a mystery to what valid circumstance could lead to pt_init() using 0 (a.k.a. unknown?) as the vslot. My patch made one the assumptions that pt_init() made about slot numbers invalid. That is, they don't start at PHP_SLOT_START, they start wherever there is a free device. A simple solution seems to be to use the value assigned to pt_dev->dev.devfn in register_real_device(). Signed-off-by: Simon Horman --- diff --git a/hw/pass-through.c b/hw/pass-through.c index bb35af3c..5de35fd4 100644 --- a/hw/pass-through.c +++ b/hw/pass-through.c @@ -3880,7 +3880,7 @@ int power_off_php_slot(int php_slot) int pt_init(PCIBus *e_bus, const char *direct_pci) { - int seg, b, d, f, slot, status = -1; + int seg, b, d, f, status = -1; struct pt_dev *pt_dev; struct pci_access *pci_access; char *vslots; @@ -3916,9 +3916,7 @@ int pt_init(PCIBus *e_bus, const char *direct_pci) vslots = qemu_mallocz ( strlen(direct_pci) / 3 ); /* Assign given devices to guest */ - for ( slot = 0; - slot < NR_PCI_DEV && next_bdf(&direct_pci_p, &seg, &b, &d, &f, &opt); - slot++ ) + while ( next_bdf(&direct_pci_p, &seg, &b, &d, &f, &opt) ) { /* Register real device with the emulated bus */ pt_dev = register_real_device(e_bus, "DIRECT PCI", PT_VIRT_DEVFN_AUTO, @@ -3930,9 +3928,7 @@ int pt_init(PCIBus *e_bus, const char *direct_pci) } /* Record the virtual slot info */ - sprintf(slot_str, "0x%02x;", - dpci_infos.php_devs[slot].pt_dev == pt_dev ? slot : - AUTO_PHP_SLOT); + sprintf(slot_str, "0x%02x;", PCI_SLOT(pt_dev->dev.devfn)); strcat(vslots, slot_str); }