• Alexey Kardashevskiy's avatar
    KVM: PPC: Validate TCEs against preregistered memory page sizes · 42de7b9e
    Alexey Kardashevskiy authored
    The userspace can request an arbitrary supported page size for a DMA
    window and this works fine as long as the mapped memory is backed with
    the pages of the same or bigger size; if this is not the case,
    mm_iommu_ua_to_hpa{_rm}() fail and tables do not populated with
    dangerously incorrect TCEs.
    
    However since it is quite easy to misconfigure the KVM and we do not do
    reverts to all changes made to TCE tables if an error happens in a middle,
    we better do the acceptable page size validation before we even touch
    the tables.
    
    This enhances kvmppc_tce_validate() to check the hardware IOMMU page sizes
    against the preregistered memory page sizes.
    
    Since the new check uses real/virtual mode helpers, this renames
    kvmppc_tce_validate() to kvmppc_rm_tce_validate() to handle the real mode
    case and mirrors it for the virtual mode under the old name. The real
    mode handler is not used for the virtual mode as:
    1. it uses _lockless() list traversing primitives instead of RCU;
    2. realmode's mm_iommu_ua_to_hpa_rm() uses vmalloc_to_phys() which
    virtual mode does not have to use and since on POWER9+radix only virtual
    mode handlers actually work, we do not want to slow down that path even
    a bit.
    
    This removes EXPORT_SYMBOL_GPL(kvmppc_tce_validate) as the validators
    are static now.
    
    From now on the attempts on mapping IOMMU pages bigger than allowed
    will result in KVM exit.
    Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
    Reviewed-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
    [mpe: Fix KVM_HV=n build]
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    42de7b9e
book3s_64_vio_hv.c 16.8 KB