Re: [PATCH v2 1/2] iova: Remove some magazine pointer NULL checks

John Garry
2022-09-07T10:11:00Z

On 07/09/2022 10:58, Ethan Zhao wrote:

Hi Ethan,

>> Or also add this:
>>
>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
>> index 0d6d8edf782d..e8f0b8f47f45 100644
>> --- a/drivers/iommu/dma-iommu.c
>> +++ b/drivers/iommu/dma-iommu.c
>> @@ -578,6 +578,12 @@ static int iommu_dma_init_domain(struct
>> iommu_domain *domain, dma_addr_t base,
>>              goto done_unlock;
>>          }
>>
>> +        if (!iovad->rcaches) {
>> +            pr_warn("IOVA domain rcache not properly initialised\n");
>> +            ret = -EFAULT;
>> +            goto done_unlock;
>> +        }
>> +
>>          ret = 0;
>>          goto done_unlock;
>>
> If the iovad->rcaches allocation failed, will skip iommu domain dma ops,
> so no need *any* iovad,->rcaches check, right ?
>
> and there is already warning about the fallback.

It's not as simple as that. We use the iovad->start_pfn member as a flag
for the IOVA domain being initialized. However that does not mean always
properly initialized. As above, the rcache init may fail, but in this
case we still set start_pfn.

This comes into play when we have multiple devices in the same IOMMU
group, for example, as I mentioned yesterday.

Thanks,
John