On 03-06-2026 19:10, Christian König wrote:
> On 6/3/26 08:11, Ekansh Gupta wrote:
>> On 19-05-2026 12:25, Christian König wrote:
>>> On 5/19/26 08:16, Ekansh Gupta via B4 Relay wrote:
>>>> From: Ekansh Gupta <[email protected]>
> ...
>>>> +static int qda_memory_manager_map_imported(struct qda_memory_manager
>>>> *mem_mgr,
>>>> + struct qda_gem_obj *gem_obj,
>>>> + struct qda_iommu_device
>>>> *iommu_dev)
>>>> +{
>>>> + struct scatterlist *sg;
>>>> + dma_addr_t dma_addr;
>>>> +
>>>> + if (!gem_obj->is_imported || !gem_obj->sgt || !iommu_dev) {
>>>> + drm_err(gem_obj->base.dev, "Invalid parameters for
>>>> imported buffer mapping\n");
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + sg = gem_obj->sgt->sgl;
>>>> + if (!sg) {
>>>> + drm_err(gem_obj->base.dev, "Invalid scatter-gather list
>>>> for imported buffer\n");
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + gem_obj->iommu_dev = iommu_dev;
>>>> +
>>>> + /*
>>>> + * After dma_buf_map_attachment_unlocked(), sg_dma_address()
>>>> returns the
>>>> + * IOMMU virtual address, not the physical address. The IOMMU maps
>>>> the
>>>> + * entire buffer as a contiguous range in the IOMMU address space
>>>> even if
>>>> + * the underlying physical memory is non-contiguous. Therefore the
>>>> first
>>>> + * sg entry's DMA address is the start of the complete contiguous
>>>> + * IOMMU-mapped range and is sufficient to describe the buffer to
>>>> the DSP.
>>>> + */
>>>> + dma_addr = sg_dma_address(sg);
>>>> + dma_addr += ((u64)iommu_dev->sid << 32);
>>>> + gem_obj->dma_addr = dma_addr;
>>>
>>> That handling here is completely broken since it assumes that the exporter
>>> maps the buffer as contigious range.
>>>
>>> But that's in no way guaranteed.
>> I'll collect more details and will try to implement this in the right
>> way, maybe by iterating the full sg_table.>
>
> You could also document explicitly that you can only import contiguous
> buffers (e.g. DMA-buf heap CMA etc....) and then cleanly reject non
> contiguous buffers here.
>
> We have quite a number of drivers/HW with that limitation, so only accepting
> contiguous buffers is perfectly ok.
>
> You just can't silently assume that IOMMU would always map the entire buffer
> as one contiguous range, cause that is certainly not true.
I understand your point Christian, thanks for the suggestion!>
> Regards,
> Christian.
>
>
>>> Regards,
>>> Christian.