Skip to content

Commit bd42126

Browse files
committed
iommu: Fix deferred domain attachment
The IOMMU core code has support for deferring the attachment of a domain to a device. This is needed in kdump kernels where the new domain must not be attached to a device before the device driver takes it over. When the AMD IOMMU driver got converted to use the dma-iommu implementation, the deferred attaching got lost. The code in dma-iommu.c has support for deferred attaching, but it calls into iommu_attach_device() to actually do it. But iommu_attach_device() will check if the device should be deferred in it code-path and do nothing, breaking deferred attachment. Move the is_deferred_attach() check out of the attach_device path and into iommu_group_add_device() to make deferred attaching work from the dma-iommu code. Fixes: 795bbbb ("iommu/dma-iommu: Handle deferred devices") Reported-by: Jerry Snitselaar <[email protected]> Suggested-by: Robin Murphy <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Tested-by: Jerry Snitselaar <[email protected]> Cc: Jerry Snitselaar <[email protected]> Cc: Tom Murphy <[email protected]> Cc: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ea90228 commit bd42126

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/iommu/iommu.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,15 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group,
693693
return ret;
694694
}
695695

696+
static bool iommu_is_attach_deferred(struct iommu_domain *domain,
697+
struct device *dev)
698+
{
699+
if (domain->ops->is_attach_deferred)
700+
return domain->ops->is_attach_deferred(domain, dev);
701+
702+
return false;
703+
}
704+
696705
/**
697706
* iommu_group_add_device - add a device to an iommu group
698707
* @group: the group into which to add the device (reference should be held)
@@ -747,7 +756,7 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev)
747756

748757
mutex_lock(&group->mutex);
749758
list_add_tail(&device->list, &group->devices);
750-
if (group->domain)
759+
if (group->domain && !iommu_is_attach_deferred(group->domain, dev))
751760
ret = __iommu_attach_device(group->domain, dev);
752761
mutex_unlock(&group->mutex);
753762
if (ret)
@@ -1653,9 +1662,6 @@ static int __iommu_attach_device(struct iommu_domain *domain,
16531662
struct device *dev)
16541663
{
16551664
int ret;
1656-
if ((domain->ops->is_attach_deferred != NULL) &&
1657-
domain->ops->is_attach_deferred(domain, dev))
1658-
return 0;
16591665

16601666
if (unlikely(domain->ops->attach_dev == NULL))
16611667
return -ENODEV;
@@ -1727,8 +1733,7 @@ EXPORT_SYMBOL_GPL(iommu_sva_unbind_gpasid);
17271733
static void __iommu_detach_device(struct iommu_domain *domain,
17281734
struct device *dev)
17291735
{
1730-
if ((domain->ops->is_attach_deferred != NULL) &&
1731-
domain->ops->is_attach_deferred(domain, dev))
1736+
if (iommu_is_attach_deferred(domain, dev))
17321737
return;
17331738

17341739
if (unlikely(domain->ops->detach_dev == NULL))

0 commit comments

Comments
 (0)