On Fri, Feb 21, 2025 at 03:23:22PM +0000, Robin Murphy wrote:
Eww... What's the issue with just checking the domain type in iommu_put_dma_cookie()? Is is that IOMMUFD and VFIO type 1 are both doing their own different thing with IOMMU_DOMAIN_UNMANAGED?
Yes
In general it seems like a bad smell to have a union in a structure with not enough information within that structire itself to know which union member is valid... :/
The concept is the opaque pointer belongs only to the caller that allocated and owns the domain. The core iommu code should never look at it or touch it.
The problem is with the mandatory call to dma-iommu in the free path - dma-iommu code should never be invoked outside of VFIO and the default domain cases.
So the little rework I sketched makes it into the caller knowing if dma-iommu is operating that domain and then only does it call the dma-iommu related functions, and the core code never touches the union content.
Jason