]> xenbits.xensource.com Git - xen.git/commitdiff
amd iommu: Fix a xen crash after pci-attach
authorKeir Fraser <keir@xen.org>
Thu, 10 Feb 2011 09:04:05 +0000 (09:04 +0000)
committerKeir Fraser <keir@xen.org>
Thu, 10 Feb 2011 09:04:05 +0000 (09:04 +0000)
pci-detach triggers IO page table deallocation if the last passthru
device has been removed from pdev list, and this will result a BUG on
amd systems for next pci-attach. This patch fixes this issue.

Signed-off-by: Wei Wang <wei.wang2@amd.com>
xen-unstable changeset:   22872:cba9a84d32fb
xen-unstable date:        Sun Feb 06 16:54:01 2011 +0000

xen/drivers/passthrough/amd/pci_amd_iommu.c

index d4e06ffc864c52d15dddb7a80f006e11109d26e4..fb29e209c6bfde589061f81f5e1549f8a5053b93 100644 (file)
@@ -277,6 +277,7 @@ static int reassign_device( struct domain *source, struct domain *target,
     struct pci_dev *pdev;
     struct amd_iommu *iommu;
     int bdf;
+    struct hvm_iommu *t = domain_hvm_iommu(target);
 
     ASSERT(spin_is_locked(&pcidevs_lock));
     pdev = pci_get_pdev_by_domain(source, bus, devfn);
@@ -298,6 +299,11 @@ static int reassign_device( struct domain *source, struct domain *target,
     list_move(&pdev->domain_list, &target->arch.pdev_list);
     pdev->domain = target;
 
+    /* IO page tables might be destroyed after pci-detach the last device
+     * In this case, we have to re-allocate root table for next pci-attach.*/
+    if ( t->root_table == NULL )
+        allocate_domain_resources(t);
+
     amd_iommu_setup_domain_device(target, iommu, bdf);
     AMD_IOMMU_DEBUG("reassign %x:%x.%x domain %d -> domain %d\n",
                  bus, PCI_SLOT(devfn), PCI_FUNC(devfn),