Skip to contentSkip to conversation

amd iommu: Fix a xen crash after pci-attach

PATCH In review Wei Wang2 1 participant 2 messages Feb 1, 2011 – Feb 9, 2011

lore
Share & tools
lore

Wei Wang2

author
#0 lore raw

PATCH 1/1 amd iommu: Fix a xen crash after pci-attach

Keir,
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.
Thanks,
Wei

--
Advanced Micro Devices GmbH
Sitz: Dornach, Gemeinde Aschheim,
Landkreis München Registergericht München,
HRB Nr. 43632
WEEE-Reg-Nr: DE 12919551
Geschäftsführer:
Alberto Bozzo, Andrew Bowd

xen/drivers/passthrough/amd/pci_amd_iommu.c +5 -0
diff -r a69965e61ae9 xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -301,6 +301,11 @@ static int reassign_device( struct domai
     if ( target->max_pages > 0 )
         t->paging_mode = get_paging_mode(target->max_pages);
 
+    /* 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("Re-assign %02x:%02x.%x from domain %d to domain %d\n",
                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn),

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

author
#1 lore raw

Re: [osrc-patches] [PATCH] amd iommu: Fix a xen crash after pci-attach (backport)

Quoted 8 lines · On Tuesday 01 February 2011 17:27:16 Wei Wang2 wrote:

Keir,
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.
Thanks,
Wei

Quoted 8 lines

--
Advanced Micro Devices GmbH
Sitz: Dornach, Gemeinde Aschheim,
Landkreis München Registergericht München,
HRB Nr. 43632
WEEE-Reg-Nr: DE 12919551
Geschäftsführer:
Alberto Bozzo, Andrew Bowd

Keir,
I think this should also be back ported to 4.0, I found the same issue with xen-4.0.2-rc2-pre. Patch has been attached.
Thanks,
Wei

xen/drivers/passthrough/amd/pci_amd_iommu.c +6 -0
diff -r a8bc981ce9c7 xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -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",

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