From: Wei Wang2 Subject: [PATCH 3/3] AMD IOMMU: Invalidate all pages on domain destruction Date: Wed, 3 Dec 2008 16:18:41 +0100 Message-ID: <1228317521.20236.302.camel@gran.amd.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-nBLR8v18FaaJBBdmZzUM" Return-path: 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 Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org --=-nBLR8v18FaaJBBdmZzUM Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Attached patch adds support to invalidate all pages associated with the sam= e domain ID on domain destruction. -Wei Signed-off-by: Wei Wang -- AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Gesch=C3=A4ftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplement=C3=A4r: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Gesch=C3=A4ftsf=C3=BChrer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy --=-nBLR8v18FaaJBBdmZzUM Content-Disposition: attachment; filename="flush_all.patch" Content-Type: text/x-patch; name="flush_all.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit diff -r ab0c1bdede53 xen/drivers/passthrough/amd/iommu_map.c --- a/xen/drivers/passthrough/amd/iommu_map.c Wed Nov 26 11:14:26 2008 +0000 +++ b/xen/drivers/passthrough/amd/iommu_map.c Wed Dec 03 11:50:45 2008 +0100 @@ -580,3 +580,47 @@ out: spin_unlock_irqrestore(&hd->mapping_lock, flags); return 0; } + +void invalidate_all_iommu_pages(struct domain *d) +{ + u32 cmd[4], entry; + unsigned long flags; + struct amd_iommu *iommu; + int domain_id = d->domain_id; + u64 addr_lo = 0x7FFFFFFFFFFFF000ULL & DMA_32BIT_MASK; + u64 addr_hi = 0x7FFFFFFFFFFFF000ULL >> 32; + + set_field_in_reg_u32(domain_id, 0, + IOMMU_INV_IOMMU_PAGES_DOMAIN_ID_MASK, + IOMMU_INV_IOMMU_PAGES_DOMAIN_ID_SHIFT, &entry); + set_field_in_reg_u32(IOMMU_CMD_INVALIDATE_IOMMU_PAGES, entry, + IOMMU_CMD_OPCODE_MASK, IOMMU_CMD_OPCODE_SHIFT, + &entry); + cmd[1] = entry; + + set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, 0, + IOMMU_INV_IOMMU_PAGES_S_FLAG_MASK, + IOMMU_INV_IOMMU_PAGES_S_FLAG_SHIFT, &entry); + set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, entry, + IOMMU_INV_IOMMU_PAGES_PDE_FLAG_MASK, + IOMMU_INV_IOMMU_PAGES_PDE_FLAG_SHIFT, &entry); + set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, entry, + IOMMU_INV_IOMMU_PAGES_ADDR_LOW_MASK, + IOMMU_INV_IOMMU_PAGES_ADDR_LOW_SHIFT, &entry); + cmd[2] = entry; + + set_field_in_reg_u32((u32)addr_hi, 0, + IOMMU_INV_IOMMU_PAGES_ADDR_HIGH_MASK, + IOMMU_INV_IOMMU_PAGES_ADDR_HIGH_SHIFT, &entry); + cmd[3] = entry; + + cmd[0] = 0; + + for_each_amd_iommu ( iommu ) + { + spin_lock_irqsave(&iommu->lock, flags); + send_iommu_command(iommu, cmd); + flush_command_buffer(iommu); + spin_unlock_irqrestore(&iommu->lock, flags); + } +} diff -r ab0c1bdede53 xen/drivers/passthrough/amd/pci_amd_iommu.c --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c Wed Nov 26 11:14:26 2008 +0000 +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c Wed Dec 03 11:50:45 2008 +0100 @@ -389,6 +389,7 @@ static void amd_iommu_domain_destroy(str static void amd_iommu_domain_destroy(struct domain *d) { deallocate_iommu_page_tables(d); + invalidate_all_iommu_pages(d); } static int amd_iommu_return_device( diff -r ab0c1bdede53 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h Wed Nov 26 11:14:26 2008 +0000 +++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h Wed Dec 03 11:50:45 2008 +0100 @@ -63,6 +63,7 @@ int amd_iommu_reserve_domain_unity_map(s int amd_iommu_reserve_domain_unity_map(struct domain *domain, unsigned long phys_addr, unsigned long size, int iw, int ir); int amd_iommu_sync_p2m(struct domain *d); +void invalidate_all_iommu_pages(struct domain *d); /* device table functions */ void amd_iommu_set_dev_table_entry(u32 *dte, u64 root_ptr, u64 intremap_ptr, --=-nBLR8v18FaaJBBdmZzUM 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 --=-nBLR8v18FaaJBBdmZzUM--