Skip to contentSkip to conversation

xend: call xc_assign_device for all the devices to hotplug

PATCH New Stefano Stabellini 1 participant 1 message Nov 13, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xend: call xc_assign_device for all the devices to hotplug

Hi all,
this patch fixes a couple of issues with pci passthrough in xend, previously reported by Cui Dexuan.
The main problem is that xc_assign_device is called only for the first device hotplugged into the guest and not the followings.

---

tools/python/xen/xend/XendDomainInfo.py +4 -1
diff -r 247e02819273 tools/python/xen/xend/XendDomainInfo.py
@@ -766,6 +766,10 @@
             bdf_str = "%s@%02x%s" % (pci_dict_to_bdf_str(new_dev),
                                      int(new_dev['vdevfn'], 16), opts)
             log.debug("XendDomainInfo.hvm_pci_device_insert_dev: %s" % bdf_str)
+            bdf = xc.assign_device(self.domid, pci_dict_to_xc_str(new_dev))
+            if bdf > 0:
+                raise VmError("Failed to assign device to IOMMU (%s)" % bdf_str)
+            log.debug("pci: assign device %s" % bdf_str)
             self.image.signalDeviceModel('pci-ins', 'pci-inserted', bdf_str)
 
             vdevfn = xstransact.Read("/local/domain/0/device-model/%i/parameter"
@@ -921,7 +925,6 @@
             existing_pci_conf = self.info['devices'][existing_dev_uuid][1]
             devid = self._createDevice('pci', existing_pci_conf)
             self.info['devices'][existing_dev_uuid][1]['devid'] = devid
-            return True
 
         if self.domid is not None:
             # use DevController.reconfigureDevice to change device config
tools/python/xen/xend/server/pciif.py +7 -14
diff -r 247e02819273 tools/python/xen/xend/server/pciif.py
@@ -444,15 +444,7 @@
         # For hvm guest, (from c/s 19679 on) assigning device statically and
         # dynamically both go through reconfigureDevice(), so HERE the
         # setupOneDevice() is not necessary.
-        if self.vm.info.is_hvm():
-            for pci_dev in pci_dev_list:
-                # Setup IOMMU device assignment
-                bdf = xc.assign_device(self.getDomid(), pci_dict_to_xc_str(pci_dev))
-                pci_str = pci_dict_to_bdf_str(pci_dev)
-                if bdf > 0:
-                    raise VmError("Failed to assign device to IOMMU (%s)" % pci_str)
-                log.debug("pci: assign device %s" % pci_str)
-        else :
+        if not self.vm.info.is_hvm():
             for d in pci_dev_list:
                 self.setupOneDevice(d)
         wPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid())
@@ -492,11 +484,12 @@
         dev.do_FLR(self.vm.info.is_hvm(),
             xoptions.get_pci_dev_assign_strict_check())
 
-        bdf = xc.deassign_device(fe_domid, pci_dict_to_xc_str(pci_dev))
-        pci_str = pci_dict_to_bdf_str(pci_dev)
-        if bdf > 0:
-            raise VmError("Failed to deassign device from IOMMU (%s)" % pci_str)
-        log.debug("pci: Deassign device %s" % pci_str)
+        if not self.vm.info.is_stubdom() :
+            bdf = xc.deassign_device(fe_domid, pci_dict_to_xc_str(pci_dev))
+            pci_str = pci_dict_to_bdf_str(pci_dev)
+            if bdf > 0:
+                raise VmError("Failed to deassign device from IOMMU (%s)" % pci_str)
+            log.debug("pci: Deassign device %s" % pci_str)
 
         for (start, size) in dev.ioports:
             log.debug('pci: disabling ioport 0x%x/0x%x'%(start,size))