8da7a17 intel-iommu: rework the page walk logic

3 files Authored by Peter Xu 5 years ago, Committed by Michael Roth 5 years ago,
    intel-iommu: rework the page walk logic
    
    This patch fixes a potential small window that the DMA page table might
    be incomplete or invalid when the guest sends domain/context
    invalidations to a device.  This can cause random DMA errors for
    assigned devices.
    
    This is a major change to the VT-d shadow page walking logic. It
    includes but is not limited to:
    
    - For each VTDAddressSpace, now we maintain what IOVA ranges we have
      mapped and what we have not.  With that information, now we only send
      MAP or UNMAP when necessary.  Say, we don't send MAP notifies if we
      know we have already mapped the range, meanwhile we don't send UNMAP
      notifies if we know we never mapped the range at all.
    
    - Introduce vtd_sync_shadow_page_table[_range] APIs so that we can call
      in any places to resync the shadow page table for a device.
    
    - When we receive domain/context invalidation, we should not really run
      the replay logic, instead we use the new sync shadow page table API to
      resync the whole shadow page table without unmapping the whole
      region.  After this change, we'll only do the page walk once for each
      domain invalidations (before this, it can be multiple, depending on
      number of notifiers per address space).
    
    While at it, the page walking logic is also refactored to be simpler.
    
    CC: QEMU Stable <qemu-stable@nongnu.org>
    Reported-by: Jintack Lim <jintack@cs.columbia.edu>
    Tested-by: Jintack Lim <jintack@cs.columbia.edu>
    Signed-off-by: Peter Xu <peterx@redhat.com>
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
    (cherry picked from commit 63b88968f139b6a77f2f81e6f1eedf70c0170a85)
    Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
    
        
file modified
+155 -58
file modified
+2 -1