This is a note to let you know that I've just added the patch titled

    intel-iommu: Free old page tables before creating superpage

to the 3.0-stable tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     intel-iommu-free-old-page-tables-before-creating-superpage.patch
and it can be found in the queue-3.0 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.


>From 6491d4d02893d9787ba67279595990217177b351 Mon Sep 17 00:00:00 2001
From: "Woodhouse, David" <[email protected]>
Date: Wed, 19 Dec 2012 13:25:35 +0000
Subject: intel-iommu: Free old page tables before creating superpage

From: "Woodhouse, David" <[email protected]>

commit 6491d4d02893d9787ba67279595990217177b351 upstream.

The dma_pte_free_pagetable() function will only free a page table page
if it is asked to free the *entire* 2MiB range that it covers. So if a
page table page was used for one or more small mappings, it's likely to
end up still present in the page tables... but with no valid PTEs.

This was fine when we'd only be repopulating it with 4KiB PTEs anyway
but the same virtual address range can end up being reused for a
*large-page* mapping. And in that case were were trying to insert the
large page into the second-level page table, and getting a complaint
from the sanity check in __domain_mapping() because there was already a
corresponding entry. This was *relatively* harmless; it led to a memory
leak of the old page table page, but no other ill-effects.

Fix it by calling dma_pte_clear_range (hopefully redundant) and
dma_pte_free_pagetable() before setting up the new large page.

Signed-off-by: David Woodhouse <[email protected]>
Tested-by: Ravi Murty <[email protected]>
Tested-by: Sudeep Dutt <[email protected]>
Cc: [email protected] [3.0+]
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: CAI Qian <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 drivers/pci/intel-iommu.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -1793,10 +1793,17 @@ static int __domain_mapping(struct dmar_
                        if (!pte)
                                return -ENOMEM;
                        /* It is large page*/
-                       if (largepage_lvl > 1)
+                       if (largepage_lvl > 1) {
                                pteval |= DMA_PTE_LARGE_PAGE;
-                       else
+                               /* Ensure that old small page tables are 
removed to make room
+                                  for superpage, if they exist. */
+                               dma_pte_clear_range(domain, iov_pfn,
+                                                   iov_pfn + 
lvl_to_nr_pages(largepage_lvl) - 1);
+                               dma_pte_free_pagetable(domain, iov_pfn,
+                                                      iov_pfn + 
lvl_to_nr_pages(largepage_lvl) - 1);
+                       } else {
                                pteval &= ~(uint64_t)DMA_PTE_LARGE_PAGE;
+                       }
 
                }
                /* We don't need lock here, nobody else


Patches currently in stable-queue which might be from [email protected] 
are

queue-3.0/intel-iommu-free-old-page-tables-before-creating-superpage.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to