]> xenbits.xensource.com Git - xen.git/commitdiff
amd iommu: reduce io page level for hvm guest (1/3)
authorWei Wang <wei.wang2@amd.com>
Thu, 27 Jan 2011 16:10:52 +0000 (16:10 +0000)
committerWei Wang <wei.wang2@amd.com>
Thu, 27 Jan 2011 16:10:52 +0000 (16:10 +0000)
Since in most case, 2 or 3 - level IO page tables are sufficient, this
patch updates page table level for device assignment to reduces
overhead of dma translation

Signed-off-by: Wei Wang <wei.wang2@amd.com>
xen/drivers/passthrough/amd/iommu_map.c
xen/drivers/passthrough/amd/pci_amd_iommu.c

index 536da0da849fe4b29e1b4c2fb885ba1664d33c99..d973a123ea33775a8e10a1ae78df42ab3596b8ca 100644 (file)
@@ -411,10 +411,14 @@ static u64 iommu_l2e_from_pfn(struct page_info *table, int level,
     void *pde = NULL;
     void *table_vaddr;
     u64 next_table_maddr = 0;
+    unsigned int lowest = 1;
 
-    BUG_ON( table == NULL || level == 0 );
+    BUG_ON( table == NULL || level < lowest );
 
-    while ( level > 1 )
+    if ( level == lowest )
+        return page_to_maddr(table);
+
+    while ( level > lowest )
     {
         offset = io_pfn >> ((PTE_PER_TABLE_SHIFT *
                              (level - IOMMU_PAGING_MODE_LEVEL_1)));
index 2442027fac9a9f6a9552c7e49b7c98dd5eb2b4ea..6a79efedb8c371f10e68c0258920f21b9cd58373 100644 (file)
@@ -190,10 +190,7 @@ static int get_paging_mode(unsigned long entries)
 {
     int level = 1;
 
-    BUG_ON(!max_page);
-
-    if ( entries > max_page )
-        entries = max_page;
+    BUG_ON( !entries );
 
     while ( entries > PTE_PER_TABLE_SIZE )
     {
@@ -278,6 +275,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);
@@ -300,6 +298,9 @@ static int reassign_device( struct domain *source, struct domain *target,
     list_move(&pdev->domain_list, &target->arch.pdev_list);
     pdev->domain = target;
 
+    if ( target->max_pages > 0 )
+        t->paging_mode = get_paging_mode(target->max_pages);
+
     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),