• Alexey Kardashevskiy's avatar
    powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown · 4b6fad70
    Alexey Kardashevskiy authored
    At the moment the userspace tool is expected to request pinning of
    the entire guest RAM when VFIO IOMMU SPAPR v2 driver is present.
    When the userspace process finishes, all the pinned pages need to
    be put; this is done as a part of the userspace memory context (MM)
    destruction which happens on the very last mmdrop().
    
    This approach has a problem that a MM of the userspace process
    may live longer than the userspace process itself as kernel threads
    use userspace process MMs which was runnning on a CPU where
    the kernel thread was scheduled to. If this happened, the MM remains
    referenced until this exact kernel thread wakes up again
    and releases the very last reference to the MM, on an idle system this
    can take even hours.
    
    This moves preregistered regions tracking from MM to VFIO; insteads of
    using mm_iommu_table_group_mem_t::used, tce_container::prereg_list is
    added so each container releases regions which it has pre-registered.
    
    This changes the userspace interface to return EBUSY if a memory
    region is already registered in a container. However it should not
    have any practical effect as the only userspace tool available now
    does register memory region once per container anyway.
    
    As tce_iommu_register_pages/tce_iommu_unregister_pages are called
    under container->lock, this does not need additional locking.
    Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
    Reviewed-by: default avatarNicholas Piggin <npiggin@gmail.com>
    Acked-by: default avatarAlex Williamson <alex.williamson@redhat.com>
    Reviewed-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    4b6fad70
mmu_context_iommu.c 8.09 KB