aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorWoodhouse, David <david.woodhouse@intel.com>2012-12-19 08:25:35 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-20 13:06:04 -0500
commit6491d4d02893d9787ba67279595990217177b351 (patch)
tree744820c7f1acc07c3f9daf4bafa5514a1fed04aa /drivers/iommu
parent1800098549fc310cffffefdcb3722adaad0edda8 (diff)
intel-iommu: Free old page tables before creating superpage
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 <David.Woodhouse@intel.com> Tested-by: Ravi Murty <Ravi.Murty@intel.com> Tested-by: Sudeep Dutt <sudeep.dutt@intel.com> Cc: stable@kernel.org [3.0+] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/intel-iommu.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 0badfa48b32..9476c1b9609 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -1827,10 +1827,17 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
1827 if (!pte) 1827 if (!pte)
1828 return -ENOMEM; 1828 return -ENOMEM;
1829 /* It is large page*/ 1829 /* It is large page*/
1830 if (largepage_lvl > 1) 1830 if (largepage_lvl > 1) {
1831 pteval |= DMA_PTE_LARGE_PAGE; 1831 pteval |= DMA_PTE_LARGE_PAGE;
1832 else 1832 /* Ensure that old small page tables are removed to make room
1833 for superpage, if they exist. */
1834 dma_pte_clear_range(domain, iov_pfn,
1835 iov_pfn + lvl_to_nr_pages(largepage_lvl) - 1);
1836 dma_pte_free_pagetable(domain, iov_pfn,
1837 iov_pfn + lvl_to_nr_pages(largepage_lvl) - 1);
1838 } else {
1833 pteval &= ~(uint64_t)DMA_PTE_LARGE_PAGE; 1839 pteval &= ~(uint64_t)DMA_PTE_LARGE_PAGE;
1840 }
1834 1841
1835 } 1842 }
1836 /* We don't need lock here, nobody else 1843 /* We don't need lock here, nobody else