On Thu, Jan 23, 2025 at 04:48:29PM +0100, Christian König wrote: > No, no there are much more cases where drivers simply assume that they > are in the same iommu domain for different devices. This is an illegal assumption and invalid way to use the DMA API. Do not do that, do not architect things in DMABUF to permit that. The dma_addr_t out of the DMA API is only usable by the device passed in, period full stop. If you want to use it with two devices then call the DMA API twice. > E.g. that different > PCI endpoints can use the same dma_addr_t. > For example those classic sound devices for HDMI audio on graphics > cards work like this. > In other words if the device handled by the generic ALSA driver and the > GPU are not in the same iommu domain you run into trouble. Yes, I recall this weird AMD issue as well. IIRC the solution is not clean or "correct". :( I vaugely recall it was caused by a HW bug... > Well it might never been documented but I know of quite a bunch of > different cases that assume that a DMA addr will just ultimately work > for some other device/driver as well. Again, illegal assumption, breaks the abstraction. >> This is all DMA API internal details you shouldn't even be talking >> about at the DMA BUF level. It is all hidden and simply does not >> matter to DMA BUF at all. > > Well we somehow need to support the existing use cases with the new > API. Call the DMA API multiple times, once per device. That is the only correct way to handle this today. DMABUF is already architected like this, each and every attach should be dma mapping and generating a scatterlist for every unique importing device. Improving it to somehow avoid the redundant DMA API map would require new DMA API work. Do NOT randomly assume that devices share dma_addr_t, there is no architected way to ever discover this, it is a complete violation of all the API abstractions. >> If you want to pass an IOVA in one of these special driver-created >> domains then it would be some private address in DMABUF that only >> works on drivers that have understood they attached to these manually >> created domains. No DMA API involvement here. > > That won't fly like this. That would break at least the ALSA use case > and potentially quite a bunch of others. Your AMD ALSA weirdness is not using custom iommu_domains (nor should it), it is a different problem. > dma-iommu.c chooses an IOVA alignment based on its own reasoning that > is not always compatible with the HW. The HW can optimize if the IOVA > alignment meets certain restrictions. Much like page tables in a GPU. > > Yeah, but why can't we tell the DMA API those restrictions instead of > letting the driver manage the address space themselves? How do you propose to do this per-mapping operation without having the HW driver actually call the mapping operation? > > Same as the multipath, the ATS, and more. It is all per-mapping > > descisions of the executing HW, not global decisions or something > > like. > > So the DMA API has some structure or similar to describe the necessary > per-mapping properties? Not fully yet (though some multipath is supported), but I want to slowly move in this direction to solve all of these problems we have :( Jason