From: Tim Deegan Date: Tue, 23 Aug 2011 09:43:25 +0000 (+0100) Subject: IOMMU: only try to share IOMMU and HAP tables for domains with P2M. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~9944 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ce686e3169f5e3aaee650d2120962851d351c9e7;p=xen.git IOMMU: only try to share IOMMU and HAP tables for domains with P2M. This makes the check more precise, and brings VTd in line with AMD code. Signed-off-by: Tim Deegan --- diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthrough/amd/iommu_map.c index 9effc61c8f..6a8619c0ef 100644 --- a/xen/drivers/passthrough/amd/iommu_map.c +++ b/xen/drivers/passthrough/amd/iommu_map.c @@ -758,7 +758,7 @@ int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, BUG_ON( !hd->root_table ); - if ( iommu_hap_pt_share && is_hvm_domain(d) ) + if ( iommu_use_hap_pt(d) ) return 0; memset(pt_mfn, 0, sizeof(pt_mfn)); @@ -835,7 +835,7 @@ int amd_iommu_unmap_page(struct domain *d, unsigned long gfn) BUG_ON( !hd->root_table ); - if ( iommu_hap_pt_share && is_hvm_domain(d) ) + if ( iommu_use_hap_pt(d) ) return 0; memset(pt_mfn, 0, sizeof(pt_mfn)); @@ -935,7 +935,7 @@ void amd_iommu_share_p2m(struct domain *d) ASSERT( is_hvm_domain(d) && d->arch.hvm_domain.hap_enabled ); - if ( !iommu_hap_pt_share ) + if ( !iommu_use_hap_pt(d) ) return; pgd_mfn = pagetable_get_mfn(p2m_get_pagetable(p2m_get_hostp2m(d))); diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index 6af9477076..555ee0506d 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -388,7 +389,7 @@ static void deallocate_iommu_page_tables(struct domain *d) { struct hvm_iommu *hd = domain_hvm_iommu(d); - if ( iommu_hap_pt_share ) + if ( iommu_use_hap_pt(d) ) return; spin_lock(&hd->mapping_lock); diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 83ac344871..be5cb246bf 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -180,7 +180,7 @@ int assign_device(struct domain *d, u8 bus, u8 devfn) if ( has_arch_pdevs(d) && !need_iommu(d) ) { d->need_iommu = 1; - if ( !iommu_hap_pt_share ) + if ( !iommu_use_hap_pt(d) ) rc = iommu_populate_page_table(d); goto done; } diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index 3bcfe59602..c9557d12d5 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1613,7 +1613,7 @@ void iommu_domain_teardown(struct domain *d) if ( list_empty(&acpi_drhd_units) ) return; - if ( iommu_hap_pt_share ) + if ( iommu_use_hap_pt(d) ) return; spin_lock(&hd->mapping_lock); @@ -1635,7 +1635,7 @@ static int intel_iommu_map_page( int iommu_domid; /* Do nothing if VT-d shares EPT page table */ - if ( iommu_hap_pt_share ) + if ( iommu_use_hap_pt(d) ) return 0; /* do nothing if dom0 and iommu supports pass thru */ @@ -1760,7 +1760,7 @@ void iommu_set_pgd(struct domain *d) ASSERT( is_hvm_domain(d) && d->arch.hvm_domain.hap_enabled ); - if ( !iommu_hap_pt_share ) + if ( !iommu_use_hap_pt(d) ) return; pgd_mfn = pagetable_get_mfn(p2m_get_pagetable(p2m_get_hostp2m(d))); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index a8a60f9ae3..ade8690417 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -34,6 +34,9 @@ extern bool_t iommu_hap_pt_share; extern bool_t iommu_debug; extern bool_t amd_iommu_perdev_intremap; +/* Does this domain have a P2M table we can use as its IOMMU pagetable? */ +#define iommu_use_hap_pt(d) (paging_mode_hap(d) && iommu_hap_pt_share) + extern struct rangeset *mmio_ro_ranges; #define domain_hvm_iommu(d) (&d->arch.hvm_domain.hvm_iommu)