@@ -1606,7 +1606,7 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
1606
1606
int translation = CONTEXT_TT_MULTI_LEVEL ;
1607
1607
struct dma_pte * pgd = domain -> pgd ;
1608
1608
struct context_entry * context ;
1609
- int agaw , ret ;
1609
+ int ret ;
1610
1610
1611
1611
pr_debug ("Set context mapping for %02x:%02x.%d\n" ,
1612
1612
bus , PCI_SLOT (devfn ), PCI_FUNC (devfn ));
@@ -1623,27 +1623,15 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
1623
1623
1624
1624
copied_context_tear_down (iommu , context , bus , devfn );
1625
1625
context_clear_entry (context );
1626
-
1627
1626
context_set_domain_id (context , did );
1628
1627
1629
- /*
1630
- * Skip top levels of page tables for iommu which has
1631
- * less agaw than default. Unnecessary for PT mode.
1632
- */
1633
- for (agaw = domain -> agaw ; agaw > iommu -> agaw ; agaw -- ) {
1634
- ret = - ENOMEM ;
1635
- pgd = phys_to_virt (dma_pte_addr (pgd ));
1636
- if (!dma_pte_present (pgd ))
1637
- goto out_unlock ;
1638
- }
1639
-
1640
1628
if (info && info -> ats_supported )
1641
1629
translation = CONTEXT_TT_DEV_IOTLB ;
1642
1630
else
1643
1631
translation = CONTEXT_TT_MULTI_LEVEL ;
1644
1632
1645
1633
context_set_address_root (context , virt_to_phys (pgd ));
1646
- context_set_address_width (context , agaw );
1634
+ context_set_address_width (context , domain -> agaw );
1647
1635
context_set_translation_type (context , translation );
1648
1636
context_set_fault_enable (context );
1649
1637
context_set_present (context );
@@ -1876,20 +1864,9 @@ static int domain_setup_first_level(struct intel_iommu *iommu,
1876
1864
u32 pasid )
1877
1865
{
1878
1866
struct dma_pte * pgd = domain -> pgd ;
1879
- int agaw , level ;
1880
- int flags = 0 ;
1867
+ int level , flags = 0 ;
1881
1868
1882
- /*
1883
- * Skip top levels of page tables for iommu which has
1884
- * less agaw than default. Unnecessary for PT mode.
1885
- */
1886
- for (agaw = domain -> agaw ; agaw > iommu -> agaw ; agaw -- ) {
1887
- pgd = phys_to_virt (dma_pte_addr (pgd ));
1888
- if (!dma_pte_present (pgd ))
1889
- return - ENOMEM ;
1890
- }
1891
-
1892
- level = agaw_to_level (agaw );
1869
+ level = agaw_to_level (domain -> agaw );
1893
1870
if (level != 4 && level != 5 )
1894
1871
return - EINVAL ;
1895
1872
@@ -3492,42 +3469,41 @@ static void intel_iommu_domain_free(struct iommu_domain *domain)
3492
3469
domain_exit (dmar_domain );
3493
3470
}
3494
3471
3495
- int prepare_domain_attach_device (struct iommu_domain * domain ,
3496
- struct device * dev )
3472
+ int paging_domain_compatible (struct iommu_domain * domain , struct device * dev )
3497
3473
{
3498
3474
struct device_domain_info * info = dev_iommu_priv_get (dev );
3499
3475
struct dmar_domain * dmar_domain = to_dmar_domain (domain );
3500
3476
struct intel_iommu * iommu = info -> iommu ;
3501
3477
int addr_width ;
3502
3478
3479
+ if (WARN_ON_ONCE (!(domain -> type & __IOMMU_DOMAIN_PAGING )))
3480
+ return - EPERM ;
3481
+
3503
3482
if (dmar_domain -> force_snooping && !ecap_sc_support (iommu -> ecap ))
3504
3483
return - EINVAL ;
3505
3484
3506
3485
if (domain -> dirty_ops && !ssads_supported (iommu ))
3507
3486
return - EINVAL ;
3508
3487
3488
+ if (dmar_domain -> iommu_coherency !=
3489
+ iommu_paging_structure_coherency (iommu ))
3490
+ return - EINVAL ;
3491
+
3492
+ if (dmar_domain -> iommu_superpage !=
3493
+ iommu_superpage_capability (iommu , dmar_domain -> use_first_level ))
3494
+ return - EINVAL ;
3495
+
3496
+ if (dmar_domain -> use_first_level &&
3497
+ (!sm_supported (iommu ) || !ecap_flts (iommu -> ecap )))
3498
+ return - EINVAL ;
3499
+
3509
3500
/* check if this iommu agaw is sufficient for max mapped address */
3510
3501
addr_width = agaw_to_width (iommu -> agaw );
3511
3502
if (addr_width > cap_mgaw (iommu -> cap ))
3512
3503
addr_width = cap_mgaw (iommu -> cap );
3513
3504
3514
- if (dmar_domain -> max_addr > ( 1LL << addr_width ) )
3505
+ if (dmar_domain -> gaw > addr_width || dmar_domain -> agaw > iommu -> agaw )
3515
3506
return - EINVAL ;
3516
- dmar_domain -> gaw = addr_width ;
3517
-
3518
- /*
3519
- * Knock out extra levels of page tables if necessary
3520
- */
3521
- while (iommu -> agaw < dmar_domain -> agaw ) {
3522
- struct dma_pte * pte ;
3523
-
3524
- pte = dmar_domain -> pgd ;
3525
- if (dma_pte_present (pte )) {
3526
- dmar_domain -> pgd = phys_to_virt (dma_pte_addr (pte ));
3527
- iommu_free_page (pte );
3528
- }
3529
- dmar_domain -> agaw -- ;
3530
- }
3531
3507
3532
3508
if (sm_supported (iommu ) && !dev_is_real_dma_subdevice (dev ) &&
3533
3509
context_copied (iommu , info -> bus , info -> devfn ))
@@ -3543,7 +3519,7 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
3543
3519
3544
3520
device_block_translation (dev );
3545
3521
3546
- ret = prepare_domain_attach_device (domain , dev );
3522
+ ret = paging_domain_compatible (domain , dev );
3547
3523
if (ret )
3548
3524
return ret ;
3549
3525
@@ -4214,7 +4190,7 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
4214
4190
if (context_copied (iommu , info -> bus , info -> devfn ))
4215
4191
return - EBUSY ;
4216
4192
4217
- ret = prepare_domain_attach_device (domain , dev );
4193
+ ret = paging_domain_compatible (domain , dev );
4218
4194
if (ret )
4219
4195
return ret ;
4220
4196
0 commit comments