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: 795bbbb9b6f8 ("iommu/dma-iommu: Handle deferred devices") Reported-by: Jerry Snitselaar <jsnitsel@redhat.com> Suggested-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Joerg Roedel <jroedel@suse.de> Tested-by: Jerry Snitselaar <jsnitsel@redhat.com> Cc: Jerry Snitselaar <jsnitsel@redhat.com> Cc: Tom Murphy <murphyt7@tcd.ie> Cc: Robin Murphy <robin.murphy@arm.com> Link: https://lore.kernel.org/r/20200519130340.14564-1-joro@8bytes.org
This commit is contained in:
parent
ea90228c7b
commit
bd421264ed
@ -693,6 +693,15 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool iommu_is_attach_deferred(struct iommu_domain *domain,
|
||||||
|
struct device *dev)
|
||||||
|
{
|
||||||
|
if (domain->ops->is_attach_deferred)
|
||||||
|
return domain->ops->is_attach_deferred(domain, dev);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* iommu_group_add_device - add a device to an iommu group
|
* iommu_group_add_device - add a device to an iommu group
|
||||||
* @group: the group into which to add the device (reference should be held)
|
* @group: the group into which to add the device (reference should be held)
|
||||||
@ -747,7 +756,7 @@ rename:
|
|||||||
|
|
||||||
mutex_lock(&group->mutex);
|
mutex_lock(&group->mutex);
|
||||||
list_add_tail(&device->list, &group->devices);
|
list_add_tail(&device->list, &group->devices);
|
||||||
if (group->domain)
|
if (group->domain && !iommu_is_attach_deferred(group->domain, dev))
|
||||||
ret = __iommu_attach_device(group->domain, dev);
|
ret = __iommu_attach_device(group->domain, dev);
|
||||||
mutex_unlock(&group->mutex);
|
mutex_unlock(&group->mutex);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -1653,9 +1662,6 @@ static int __iommu_attach_device(struct iommu_domain *domain,
|
|||||||
struct device *dev)
|
struct device *dev)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
if ((domain->ops->is_attach_deferred != NULL) &&
|
|
||||||
domain->ops->is_attach_deferred(domain, dev))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (unlikely(domain->ops->attach_dev == NULL))
|
if (unlikely(domain->ops->attach_dev == NULL))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -1727,8 +1733,7 @@ EXPORT_SYMBOL_GPL(iommu_sva_unbind_gpasid);
|
|||||||
static void __iommu_detach_device(struct iommu_domain *domain,
|
static void __iommu_detach_device(struct iommu_domain *domain,
|
||||||
struct device *dev)
|
struct device *dev)
|
||||||
{
|
{
|
||||||
if ((domain->ops->is_attach_deferred != NULL) &&
|
if (iommu_is_attach_deferred(domain, dev))
|
||||||
domain->ops->is_attach_deferred(domain, dev))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (unlikely(domain->ops->detach_dev == NULL))
|
if (unlikely(domain->ops->detach_dev == NULL))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user