All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yang, Xiaowei" <xiaowei.yang@intel.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH] VTd: Fix VTd page table teardown on domain destroy
Date: Mon, 02 Jun 2008 14:26:41 +0800	[thread overview]
Message-ID: <1212388001.695.5.camel@ip6-localhost> (raw)

[-- Attachment #1: Type: text/plain, Size: 71 bytes --]


Signed-off-by: Xiaowei Yang <xiaowei.yang@intel.com>

Thanks,
Xiaowei

[-- Attachment #2: vtd_pagetable_teardown.patch --]
[-- Type: text/x-patch, Size: 2572 bytes --]

diff -r 6e688d5a936b xen/drivers/passthrough/vtd/iommu.c
--- a/xen/drivers/passthrough/vtd/iommu.c	Fri May 30 19:31:18 2008 +0100
+++ b/xen/drivers/passthrough/vtd/iommu.c	Sun Jun 01 10:09:25 2008 +0800
@@ -587,50 +587,32 @@ static void dma_pte_clear_range(struct d
     }
 }
 
-static void iommu_free_next_pagetable(u64 pt_maddr, unsigned long index,
-                                      int level)
-{
-    unsigned long next_index;
-    struct dma_pte *pt_vaddr, *pde;
-    int next_level;
+static void iommu_free_pagetable(u64 pt_maddr, int level)
+{
+    int i;
+    struct dma_pte *pt_vaddr, *pte;
+    int next_level = level - 1;
 
     if ( pt_maddr == 0 )
         return;
 
     pt_vaddr = (struct dma_pte *)map_vtd_domain_page(pt_maddr);
-    pde = &pt_vaddr[index];
-    if ( dma_pte_addr(*pde) == 0 )
-        goto out;
-
-    next_level = level - 1;
-    if ( next_level > 1 )
-    {
-        for ( next_index = 0; next_index < PTE_NUM; next_index++ )
-            iommu_free_next_pagetable(pde->val, next_index, next_level);
-    }
-
-    dma_clear_pte(*pde);
-    iommu_flush_cache_entry(pde);
-    free_pgtable_maddr(pde->val);
-
- out:
+
+    for ( i = 0; i < PTE_NUM; i++ )
+    {
+        pte = &pt_vaddr[i];
+        if ( !dma_pte_present(*pte) )
+            continue;
+
+        if ( next_level >= 1 )
+            iommu_free_pagetable(dma_pte_addr(*pte), next_level);
+
+        dma_clear_pte(*pte);
+        iommu_flush_cache_entry(pte);
+    }
+
     unmap_vtd_domain_page(pt_vaddr);
-}
-
-/* free all VT-d page tables when shut down or destroy domain. */
-static void iommu_free_pagetable(struct domain *domain)
-{
-    struct hvm_iommu *hd = domain_hvm_iommu(domain);
-    int i, total_level = agaw_to_level(hd->agaw);
-
-    if ( hd->pgd_maddr == 0 )
-        return;
-
-    for ( i = 0; i < PTE_NUM; i++ )
-        iommu_free_next_pagetable(hd->pgd_maddr, i, total_level + 1);
-
-    free_pgtable_maddr(hd->pgd_maddr);
-    hd->pgd_maddr = 0;
+    free_pgtable_maddr(pt_maddr);
 }
 
 static int iommu_set_root_entry(struct iommu *iommu)
@@ -1456,11 +1438,14 @@ void return_devices_to_dom0(struct domai
 
 void iommu_domain_teardown(struct domain *d)
 {
+    struct hvm_iommu *hd = domain_hvm_iommu(d);
+
     if ( list_empty(&acpi_drhd_units) )
         return;
 
-    iommu_free_pagetable(d);
     return_devices_to_dom0(d);
+    iommu_free_pagetable(hd->pgd_maddr, agaw_to_level(hd->agaw));
+    hd->pgd_maddr = 0;
     iommu_domid_release(d);
 }
 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

                 reply	other threads:[~2008-06-02  6:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1212388001.695.5.camel@ip6-localhost \
    --to=xiaowei.yang@intel.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.