@@ -535,15 +535,8 @@ static int domain_update_device_node(struct dmar_domain *domain)
535535 struct device_domain_info * info ;
536536 int nid = NUMA_NO_NODE ;
537537
538- assert_spin_locked (& device_domain_lock );
539-
540- if (list_empty (& domain -> devices ))
541- return NUMA_NO_NODE ;
542-
538+ spin_lock (& device_domain_lock );
543539 list_for_each_entry (info , & domain -> devices , link ) {
544- if (!info -> dev )
545- continue ;
546-
547540 /*
548541 * There could possibly be multiple device numa nodes as devices
549542 * within the same domain may sit behind different IOMMUs. There
@@ -554,6 +547,7 @@ static int domain_update_device_node(struct dmar_domain *domain)
554547 if (nid != NUMA_NO_NODE )
555548 break ;
556549 }
550+ spin_unlock (& device_domain_lock );
557551
558552 return nid ;
559553}
@@ -1376,23 +1370,23 @@ static void __iommu_flush_iotlb(struct intel_iommu *iommu, u16 did,
13761370}
13771371
13781372static struct device_domain_info *
1379- iommu_support_dev_iotlb (struct dmar_domain * domain , struct intel_iommu * iommu ,
1380- u8 bus , u8 devfn )
1373+ iommu_support_dev_iotlb (struct dmar_domain * domain , struct intel_iommu * iommu ,
1374+ u8 bus , u8 devfn )
13811375{
13821376 struct device_domain_info * info ;
13831377
1384- assert_spin_locked (& device_domain_lock );
1385-
13861378 if (!iommu -> qi )
13871379 return NULL ;
13881380
1389- list_for_each_entry (info , & domain -> devices , link )
1381+ spin_lock (& device_domain_lock );
1382+ list_for_each_entry (info , & domain -> devices , link ) {
13901383 if (info -> iommu == iommu && info -> bus == bus &&
13911384 info -> devfn == devfn ) {
1392- if (info -> ats_supported && info -> dev )
1393- return info ;
1394- break ;
1385+ spin_unlock (& device_domain_lock );
1386+ return info -> ats_supported ? info : NULL ;
13951387 }
1388+ }
1389+ spin_unlock (& device_domain_lock );
13961390
13971391 return NULL ;
13981392}
@@ -1402,23 +1396,21 @@ static void domain_update_iotlb(struct dmar_domain *domain)
14021396 struct device_domain_info * info ;
14031397 bool has_iotlb_device = false;
14041398
1405- assert_spin_locked (& device_domain_lock );
1406-
1407- list_for_each_entry (info , & domain -> devices , link )
1399+ spin_lock (& device_domain_lock );
1400+ list_for_each_entry (info , & domain -> devices , link ) {
14081401 if (info -> ats_enabled ) {
14091402 has_iotlb_device = true;
14101403 break ;
14111404 }
1412-
1405+ }
14131406 domain -> has_iotlb_device = has_iotlb_device ;
1407+ spin_unlock (& device_domain_lock );
14141408}
14151409
14161410static void iommu_enable_dev_iotlb (struct device_domain_info * info )
14171411{
14181412 struct pci_dev * pdev ;
14191413
1420- assert_spin_locked (& device_domain_lock );
1421-
14221414 if (!info || !dev_is_pci (info -> dev ))
14231415 return ;
14241416
@@ -1464,8 +1456,6 @@ static void iommu_disable_dev_iotlb(struct device_domain_info *info)
14641456{
14651457 struct pci_dev * pdev ;
14661458
1467- assert_spin_locked (& device_domain_lock );
1468-
14691459 if (!dev_is_pci (info -> dev ))
14701460 return ;
14711461
@@ -1906,9 +1896,10 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
19061896 struct pasid_table * table ,
19071897 u8 bus , u8 devfn )
19081898{
1899+ struct device_domain_info * info =
1900+ iommu_support_dev_iotlb (domain , iommu , bus , devfn );
19091901 u16 did = domain -> iommu_did [iommu -> seq_id ];
19101902 int translation = CONTEXT_TT_MULTI_LEVEL ;
1911- struct device_domain_info * info = NULL ;
19121903 struct context_entry * context ;
19131904 int ret ;
19141905
@@ -1922,9 +1913,7 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
19221913
19231914 BUG_ON (!domain -> pgd );
19241915
1925- spin_lock (& device_domain_lock );
19261916 spin_lock (& iommu -> lock );
1927-
19281917 ret = - ENOMEM ;
19291918 context = iommu_context_addr (iommu , bus , devfn , 1 );
19301919 if (!context )
@@ -1975,7 +1964,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
19751964 * Setup the Device-TLB enable bit and Page request
19761965 * Enable bit:
19771966 */
1978- info = iommu_support_dev_iotlb (domain , iommu , bus , devfn );
19791967 if (info && info -> ats_supported )
19801968 context_set_sm_dte (context );
19811969 if (info && info -> pri_supported )
@@ -1998,7 +1986,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
19981986 goto out_unlock ;
19991987 }
20001988
2001- info = iommu_support_dev_iotlb (domain , iommu , bus , devfn );
20021989 if (info && info -> ats_supported )
20031990 translation = CONTEXT_TT_DEV_IOTLB ;
20041991 else
@@ -2044,7 +2031,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
20442031
20452032out_unlock :
20462033 spin_unlock (& iommu -> lock );
2047- spin_unlock (& device_domain_lock );
20482034
20492035 return ret ;
20502036}
@@ -2456,13 +2442,11 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
24562442 if (!iommu )
24572443 return - ENODEV ;
24582444
2459- spin_lock (& device_domain_lock );
2460- info -> domain = domain ;
24612445 ret = domain_attach_iommu (domain , iommu );
2462- if (ret ) {
2463- spin_unlock (& device_domain_lock );
2446+ if (ret )
24642447 return ret ;
2465- }
2448+ info -> domain = domain ;
2449+ spin_lock (& device_domain_lock );
24662450 list_add (& info -> link , & domain -> devices );
24672451 spin_unlock (& device_domain_lock );
24682452
@@ -4638,9 +4622,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev)
46384622 if (!domain )
46394623 return - EINVAL ;
46404624
4641- spin_lock (& device_domain_lock );
46424625 spin_lock (& iommu -> lock );
4643-
46444626 ret = - EINVAL ;
46454627 if (!info -> pasid_supported )
46464628 goto out ;
@@ -4670,7 +4652,6 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev)
46704652
46714653 out :
46724654 spin_unlock (& iommu -> lock );
4673- spin_unlock (& device_domain_lock );
46744655
46754656 return ret ;
46764657}
0 commit comments