]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
iommu/vt-d: Clean up and fix page table clear/free behaviour
authorDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 5 Mar 2014 17:09:32 +0000 (17:09 +0000)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 19 Mar 2014 17:21:41 +0000 (17:21 +0000)
commitea8ea460c9ace60bbb5ac6e5521d637d5c15293d
tree219654a4515ee8e49597759b89ebcf1fb7aea26d
parent5cf0a76fa2179d246fc0375d733bdccffd59382b
iommu/vt-d: Clean up and fix page table clear/free behaviour

There is a race condition between the existing clear/free code and the
hardware. The IOMMU is actually permitted to cache the intermediate
levels of the page tables, and doesn't need to walk the table from the
very top of the PGD each time. So the existing back-to-back calls to
dma_pte_clear_range() and dma_pte_free_pagetable() can lead to a
use-after-free where the IOMMU reads from a freed page table.

When freeing page tables we actually need to do the IOTLB flush, with
the 'invalidation hint' bit clear to indicate that it's not just a
leaf-node flush, after unlinking each page table page from the next level
up but before actually freeing it.

So in the rewritten domain_unmap() we just return a list of pages (using
pg->freelist to make a list of them), and then the caller is expected to
do the appropriate IOTLB flush (or tear down the domain completely,
whatever), before finally calling dma_free_pagelist() to free the pages.

As an added bonus, we no longer need to flush the CPU's data cache for
pages which are about to be *removed* from the page table hierarchy anyway,
in the non-cache-coherent case. This drastically improves the performance
of large unmaps.

As a side-effect of all these changes, this also fixes the fact that
intel_iommu_unmap() was neglecting to free the page tables for the range
in question after clearing them.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/iommu/intel-iommu.c