From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jean Guyader Subject: [PATCH 1/6] vtd: Refactor iotlb flush code Date: Thu, 10 Nov 2011 08:43:59 +0000 Message-ID: <1320914644-4357-2-git-send-email-jean.guyader@eu.citrix.com> References: <1320914644-4357-1-git-send-email-jean.guyader@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------true" Return-path: In-Reply-To: <1320914644-4357-1-git-send-email-jean.guyader@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: tim@xen.org, allen.m.kay@intel.com, keir@xen.org, Jean Guyader , JBeulich@suse.com List-Id: xen-devel@lists.xenproject.org --------------true Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: 8bit Factorize the iotlb flush code from map_page and unmap_page into it's own function. Signed-off-by: Jean Guyader Acked-by: Allen M Kay --- xen/drivers/passthrough/vtd/iommu.c | 86 +++++++++++++++++----------------- 1 files changed, 43 insertions(+), 43 deletions(-) --------------true Content-Type: text/x-patch; name="0001-vtd-Refactor-iotlb-flush-code.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-vtd-Refactor-iotlb-flush-code.patch" diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index 7717ab4..5a5b6be 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -578,16 +578,53 @@ static void iommu_flush_all(void) } } +static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, + int dma_old_pte_present, unsigned int page_count) +{ + struct hvm_iommu *hd = domain_hvm_iommu(d); + struct acpi_drhd_unit *drhd; + struct iommu *iommu; + int flush_dev_iotlb; + int iommu_domid; + + /* + * No need pcideves_lock here because we have flush + * when assign/deassign device + */ + for_each_drhd_unit ( drhd ) + { + iommu = drhd->iommu; + + if ( !test_bit(iommu->index, &hd->iommu_bitmap) ) + continue; + + flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0; + iommu_domid= domain_iommu_domid(d, iommu); + if ( iommu_domid == -1 ) + continue; + + if ( page_count > 1 || gfn == -1 ) + { + if ( iommu_flush_iotlb_dsi(iommu, iommu_domid, + 0, flush_dev_iotlb) ) + iommu_flush_write_buffer(iommu); + } + else + { + if ( iommu_flush_iotlb_psi(iommu, iommu_domid, + (paddr_t)gfn << PAGE_SHIFT_4K, 0, + !dma_old_pte_present, flush_dev_iotlb) ) + iommu_flush_write_buffer(iommu); + } + } +} + /* clear one page's page table */ static void dma_pte_clear_one(struct domain *domain, u64 addr) { struct hvm_iommu *hd = domain_hvm_iommu(domain); - struct acpi_drhd_unit *drhd; - struct iommu *iommu; struct dma_pte *page = NULL, *pte = NULL; u64 pg_maddr; - int flush_dev_iotlb; - int iommu_domid; struct mapped_rmrr *mrmrr; spin_lock(&hd->mapping_lock); @@ -613,21 +650,7 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr) spin_unlock(&hd->mapping_lock); iommu_flush_cache_entry(pte, sizeof(struct dma_pte)); - /* No need pcidevs_lock here since do that on assign/deassign device*/ - for_each_drhd_unit ( drhd ) - { - iommu = drhd->iommu; - if ( test_bit(iommu->index, &hd->iommu_bitmap) ) - { - flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0; - iommu_domid= domain_iommu_domid(domain, iommu); - if ( iommu_domid == -1 ) - continue; - if ( iommu_flush_iotlb_psi(iommu, iommu_domid, addr, - 0, 0, flush_dev_iotlb) ) - iommu_flush_write_buffer(iommu); - } - } + __intel_iommu_iotlb_flush(domain, addr >> PAGE_SHIFT_4K , 0, 1); unmap_vtd_domain_page(page); @@ -1677,12 +1700,8 @@ static int intel_iommu_map_page( unsigned int flags) { struct hvm_iommu *hd = domain_hvm_iommu(d); - struct acpi_drhd_unit *drhd; - struct iommu *iommu; struct dma_pte *page = NULL, *pte = NULL, old, new = { 0 }; u64 pg_maddr; - int flush_dev_iotlb; - int iommu_domid; /* Do nothing if VT-d shares EPT page table */ if ( iommu_use_hap_pt(d) ) @@ -1724,26 +1743,7 @@ static int intel_iommu_map_page( spin_unlock(&hd->mapping_lock); unmap_vtd_domain_page(page); - /* - * No need pcideves_lock here because we have flush - * when assign/deassign device - */ - for_each_drhd_unit ( drhd ) - { - iommu = drhd->iommu; - - if ( !test_bit(iommu->index, &hd->iommu_bitmap) ) - continue; - - flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0; - iommu_domid= domain_iommu_domid(d, iommu); - if ( iommu_domid == -1 ) - continue; - if ( iommu_flush_iotlb_psi(iommu, iommu_domid, - (paddr_t)gfn << PAGE_SHIFT_4K, 0, - !dma_pte_present(old), flush_dev_iotlb) ) - iommu_flush_write_buffer(iommu); - } + __intel_iommu_iotlb_flush(d, gfn, dma_pte_present(old), 1); return 0; } --------------true Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------true--