Re: [RFC 1/7] iommu/vt-d: Set the dma_ops per device so we can remove the iommu_no_mapping code

Lu Baolu
2019-05-06T01:42:15Z

Hi,

On 5/4/19 9:23 PM, Tom Murphy wrote:
> Set the dma_ops per device so we can remove the iommu_no_mapping code.
>
> Signed-off-by: Tom Murphy<tmurphy@arista.com>
> ---
> drivers/iommu/intel-iommu.c | 85 +++----------------------------------
> 1 file changed, 6 insertions(+), 79 deletions(-)
>
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index eace915602f0..2db1dc47e7e4 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -2622,17 +2622,6 @@ static int __init si_domain_init(int hw)
> return 0;
> }
>
> -static int identity_mapping(struct device *dev)
> -{
> - struct device_domain_info *info;
> -
> - info = dev->archdata.iommu;
> - if (info && info != DUMMY_DEVICE_DOMAIN_INFO)
> - return (info->domain == si_domain);
> -
> - return 0;
> -}
> -
> static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
> {
> struct dmar_domain *ndomain;
> @@ -3270,43 +3259,6 @@ static unsigned long intel_alloc_iova(struct device *dev,
> return iova_pfn;
> }
>
> -/* Check if the dev needs to go through non-identity map and unmap process.*/
> -static int iommu_no_mapping(struct device *dev)
> -{
> - int found;
> -
> - if (iommu_dummy(dev))
> - return 1;
> -
> - found = identity_mapping(dev);
> - if (found) {
> - /*
> - * If the device's dma_mask is less than the system's memory
> - * size then this is not a candidate for identity mapping.
> - */
> - u64 dma_mask = *dev->dma_mask;
> -
> - if (dev->coherent_dma_mask &&
> - dev->coherent_dma_mask < dma_mask)
> - dma_mask = dev->coherent_dma_mask;
> -
> - if (dma_mask < dma_get_required_mask(dev)) {
> - /*
> - * 32 bit DMA is removed from si_domain and fall back
> - * to non-identity mapping.
> - */
> - dmar_remove_one_dev_info(dev);
> - dev_warn(dev, "32bit DMA uses non-identity mapping\n");
> -
> - return 0;
> - }

The iommu_no_mapping() also checks whether any 32bit DMA device uses
identity mapping. The device might not work if the system memory space
is bigger than 4G.

Will you add this to other place, or it's unnecessary?

Best regards,
Lu Baolu