Skip to content

Commit

Permalink
iommu: Only allocate FQ domains for IOMMUs that support them
Browse files Browse the repository at this point in the history
Commit a4fdd97 ("iommu: Use flush queue capability") hid the
IOMMU_DOMAIN_DMA_FQ domain type from domain allocation. A check was
introduced in iommu_dma_init_domain() to fall back if not supported, but
this check runs too late: by that point, devices have been attached to
the IOMMU, and the IOMMU driver might not expect FQ domains at
ops->attach_dev() time.

Ensure that we immediately clamp FQ domains to plain DMA if not
supported by the driver at device attach time, not later.

This regressed apple-dart in v6.5.

Cc: regressions@lists.linux.dev
Cc: stable@vger.kernel.org
Fixes: a4fdd97 ("iommu: Use flush queue capability")
Signed-off-by: Hector Martin <marcan@marcan.st>
(cherry picked from commit c819b07 https://github.com/AsahiLinux/linux)
Signed-off-by: John Cabaj <john.cabaj@canonical.com>
  • Loading branch information
marcan authored and john-cabaj committed Jan 20, 2025
1 parent 1b9330d commit 76dcb28
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/iommu/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,15 @@ static int __iommu_attach_device(struct iommu_domain *domain,
if (unlikely(domain->ops->attach_dev == NULL))
return -ENODEV;

/*
* Ensure we do not try to attach devices to FQ domains if the
* IOMMU does not support them. We can safely fall back to
* non-FQ.
*/
if (domain->type == IOMMU_DOMAIN_DMA_FQ &&
!device_iommu_capable(dev, IOMMU_CAP_DEFERRED_FLUSH))
domain->type = IOMMU_DOMAIN_DMA;

ret = domain->ops->attach_dev(domain, dev);
if (ret)
return ret;
Expand Down

0 comments on commit 76dcb28

Please sign in to comment.