From 76dcb280abd1f852fb54fcd302915645e09ff4e3 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Fri, 22 Sep 2023 22:21:54 +0900 Subject: [PATCH] iommu: Only allocate FQ domains for IOMMUs that support them Commit a4fdd9762272 ("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: a4fdd9762272 ("iommu: Use flush queue capability") Signed-off-by: Hector Martin (cherry picked from commit c819b078c2cbd21c1ee1f7d536c022f77b16ca66 https://github.com/AsahiLinux/linux) Signed-off-by: John Cabaj --- drivers/iommu/iommu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 615c374f044b1b..2eb4cda7311ea1 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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;