@@ -51,6 +51,8 @@ struct iommu_dma_cookie {
5151 struct iommu_domain * fq_domain ;
5252};
5353
54+ static DEFINE_STATIC_KEY_FALSE (iommu_deferred_attach_enabled );
55+
5456void iommu_dma_free_cpu_cached_iovas (unsigned int cpu ,
5557 struct iommu_domain * domain )
5658{
@@ -383,9 +385,6 @@ static int iommu_dma_deferred_attach(struct device *dev,
383385{
384386 const struct iommu_ops * ops = domain -> ops ;
385387
386- if (!is_kdump_kernel ())
387- return 0 ;
388-
389388 if (unlikely (ops -> is_attach_deferred &&
390389 ops -> is_attach_deferred (domain , dev )))
391390 return iommu_attach_device (domain , dev );
@@ -535,7 +534,8 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
535534 size_t iova_off = iova_offset (iovad , phys );
536535 dma_addr_t iova ;
537536
538- if (unlikely (iommu_dma_deferred_attach (dev , domain )))
537+ if (static_branch_unlikely (& iommu_deferred_attach_enabled ) &&
538+ iommu_dma_deferred_attach (dev , domain ))
539539 return DMA_MAPPING_ERROR ;
540540
541541 size = iova_align (iovad , size + iova_off );
@@ -693,7 +693,8 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size,
693693
694694 * dma_handle = DMA_MAPPING_ERROR ;
695695
696- if (unlikely (iommu_dma_deferred_attach (dev , domain )))
696+ if (static_branch_unlikely (& iommu_deferred_attach_enabled ) &&
697+ iommu_dma_deferred_attach (dev , domain ))
697698 return NULL ;
698699
699700 min_size = alloc_sizes & - alloc_sizes ;
@@ -976,7 +977,8 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
976977 unsigned long mask = dma_get_seg_boundary (dev );
977978 int i ;
978979
979- if (unlikely (iommu_dma_deferred_attach (dev , domain )))
980+ if (static_branch_unlikely (& iommu_deferred_attach_enabled ) &&
981+ iommu_dma_deferred_attach (dev , domain ))
980982 return 0 ;
981983
982984 if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC ))
@@ -1424,6 +1426,9 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc,
14241426
14251427static int iommu_dma_init (void )
14261428{
1429+ if (is_kdump_kernel ())
1430+ static_branch_enable (& iommu_deferred_attach_enabled );
1431+
14271432 return iova_cache_get ();
14281433}
14291434arch_initcall (iommu_dma_init );
0 commit comments