@@ -51,6 +51,8 @@ struct iommu_dma_cookie {
51
51
struct iommu_domain * fq_domain ;
52
52
};
53
53
54
+ static DEFINE_STATIC_KEY_FALSE (iommu_deferred_attach_enabled );
55
+
54
56
void iommu_dma_free_cpu_cached_iovas (unsigned int cpu ,
55
57
struct iommu_domain * domain )
56
58
{
@@ -383,9 +385,6 @@ static int iommu_dma_deferred_attach(struct device *dev,
383
385
{
384
386
const struct iommu_ops * ops = domain -> ops ;
385
387
386
- if (!is_kdump_kernel ())
387
- return 0 ;
388
-
389
388
if (unlikely (ops -> is_attach_deferred &&
390
389
ops -> is_attach_deferred (domain , dev )))
391
390
return iommu_attach_device (domain , dev );
@@ -535,7 +534,8 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
535
534
size_t iova_off = iova_offset (iovad , phys );
536
535
dma_addr_t iova ;
537
536
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 ))
539
539
return DMA_MAPPING_ERROR ;
540
540
541
541
size = iova_align (iovad , size + iova_off );
@@ -693,7 +693,8 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size,
693
693
694
694
* dma_handle = DMA_MAPPING_ERROR ;
695
695
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 ))
697
698
return NULL ;
698
699
699
700
min_size = alloc_sizes & - alloc_sizes ;
@@ -976,7 +977,8 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
976
977
unsigned long mask = dma_get_seg_boundary (dev );
977
978
int i ;
978
979
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 ))
980
982
return 0 ;
981
983
982
984
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC ))
@@ -1424,6 +1426,9 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc,
1424
1426
1425
1427
static int iommu_dma_init (void )
1426
1428
{
1429
+ if (is_kdump_kernel ())
1430
+ static_branch_enable (& iommu_deferred_attach_enabled );
1431
+
1427
1432
return iova_cache_get ();
1428
1433
}
1429
1434
arch_initcall (iommu_dma_init );
0 commit comments