diff -r a8bc981ce9c7 xen/drivers/passthrough/amd/pci_amd_iommu.c --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c Mon Feb 07 10:01:19 2011 +0000 +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c Wed Feb 09 16:03:59 2011 +0100 @@ -277,6 +277,7 @@ static int reassign_device( struct domai 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); @@ -297,6 +298,11 @@ static int reassign_device( struct domai 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",