ia64/xen-unstable

changeset 17536:2ab9f85f221f

VT-d: Separate VT-d page table from P2M table

Signed-off-by: Weidong Han <weidong.han@intel.com>
Signed-off-by: Anthony Xu <anthony.xu@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu May 01 09:53:26 2008 +0100 (2008-05-01)
parents eb111919e8e0
children 931932f5fc6d
files tools/python/xen/xend/XendDomainInfo.py xen/arch/x86/mm/p2m.c xen/drivers/passthrough/vtd/iommu.c
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu May 01 09:50:58 2008 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu May 01 09:53:26 2008 +0100
     1.3 @@ -2135,8 +2135,13 @@ class XendDomainInfo:
     1.4              # set memory limit
     1.5              xc.domain_setmaxmem(self.domid, maxmem)
     1.6  
     1.7 +            # Reserve 1 page per MiB of RAM for separate VT-d page table.
     1.8 +            vtd_mem = 4 * (self.info['memory_static_max'] / 1024 / 1024)
     1.9 +            # Round vtd_mem up to a multiple of a MiB.
    1.10 +            vtd_mem = ((vtd_mem + 1023) / 1024) * 1024
    1.11 +
    1.12              # Make sure there's enough RAM available for the domain
    1.13 -            balloon.free(memory + shadow)
    1.14 +            balloon.free(memory + shadow + vtd_mem)
    1.15  
    1.16              # Set up the shadow memory
    1.17              shadow_cur = xc.shadow_mem_control(self.domid, shadow / 1024)
     2.1 --- a/xen/arch/x86/mm/p2m.c	Thu May 01 09:50:58 2008 +0100
     2.2 +++ b/xen/arch/x86/mm/p2m.c	Thu May 01 09:53:26 2008 +0100
     2.3 @@ -259,18 +259,10 @@ p2m_set_entry(struct domain *d, unsigned
     2.4  
     2.5      if ( iommu_enabled && is_hvm_domain(d) )
     2.6      {
     2.7 -        if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
     2.8 -        {
     2.9 -            if ( (p2mt == p2m_mmio_direct) )
    2.10 -                iommu_flush(d, gfn, (u64*)p2m_entry);
    2.11 -        }
    2.12 -        else if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD )
    2.13 -        {
    2.14 -            if ( p2mt == p2m_ram_rw )
    2.15 -                iommu_map_page(d, gfn, mfn_x(mfn));
    2.16 -            else
    2.17 -                iommu_unmap_page(d, gfn);
    2.18 -        }
    2.19 +        if ( p2mt == p2m_ram_rw )
    2.20 +            iommu_map_page(d, gfn, mfn_x(mfn));
    2.21 +        else
    2.22 +            iommu_unmap_page(d, gfn);
    2.23      }
    2.24  
    2.25      /* Success */
    2.26 @@ -529,11 +521,6 @@ int p2m_alloc_table(struct domain *d,
    2.27              goto error;
    2.28      }
    2.29  
    2.30 -#if CONFIG_PAGING_LEVELS >= 3
    2.31 -    if (vtd_enabled && is_hvm_domain(d))
    2.32 -        iommu_set_pgd(d);
    2.33 -#endif
    2.34 -
    2.35      P2M_PRINTK("p2m table initialised (%u pages)\n", page_count);
    2.36      p2m_unlock(p2m);
    2.37      return 0;
     3.1 --- a/xen/drivers/passthrough/vtd/iommu.c	Thu May 01 09:50:58 2008 +0100
     3.2 +++ b/xen/drivers/passthrough/vtd/iommu.c	Thu May 01 09:53:26 2008 +0100
     3.3 @@ -671,13 +671,26 @@ void dma_pte_free_pagetable(struct domai
     3.4      }
     3.5  
     3.6      /* free pgd */
     3.7 -    if ( start == 0 && end == ((((u64)1) << addr_width) - 1) )
     3.8 +    if ( start == 0 && end >= ((((u64)1) << addr_width) - 1) )
     3.9      {
    3.10          free_pgtable_maddr(hd->pgd_maddr);
    3.11          hd->pgd_maddr = 0;
    3.12      }
    3.13  }
    3.14  
    3.15 + /* free all VT-d page tables when shut down or destroy domain. */
    3.16 +static void iommu_free_pagetable(struct domain *domain)
    3.17 +{
    3.18 +    struct hvm_iommu *hd = domain_hvm_iommu(domain);
    3.19 +    int addr_width = agaw_to_width(hd->agaw);
    3.20 +    u64 start, end;
    3.21 +
    3.22 +    start = 0;
    3.23 +    end = (((u64)1) << addr_width) - 1;
    3.24 +
    3.25 +    dma_pte_free_pagetable(domain, start, end);
    3.26 +}
    3.27 +
    3.28  static int iommu_set_root_entry(struct iommu *iommu)
    3.29  {
    3.30      u32 cmd, sts;
    3.31 @@ -1472,9 +1485,9 @@ void iommu_domain_teardown(struct domain
    3.32      if ( list_empty(&acpi_drhd_units) )
    3.33          return;
    3.34  
    3.35 +    iommu_free_pagetable(d);
    3.36 +    return_devices_to_dom0(d);
    3.37      iommu_domid_release(d);
    3.38 -    iommu_free_pgd(d);
    3.39 -    return_devices_to_dom0(d);
    3.40  }
    3.41  
    3.42  static int domain_context_mapped(struct pci_dev *pdev)