Skip to content

Commit ed56de8

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Refactor first_level_by_default()
The first stage page table is compatible across host and guest kernels. Therefore, this driver uses the first stage page table as the default for paging domains. The helper first_level_by_default() determines the feasibility of using the first stage page table based on a global policy. This policy requires consistency in scalable mode and first stage translation capability among all iommu units. However, this is unnecessary as domain allocation, attachment, and removal operations are performed on a per-device basis. The domain type (IOMMU_DOMAIN_DMA vs. IOMMU_DOMAIN_UNMANAGED) should not be a factor in determining the first stage page table usage. Both types are for paging domains, and there's no fundamental difference between them. The driver should not be aware of this distinction unless the core specifies allocation flags that require special handling. Convert first_level_by_default() from global to per-iommu and remove the 'type' input. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 5bdd86e commit ed56de8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,18 +1329,17 @@ static void free_dmar_iommu(struct intel_iommu *iommu)
13291329
* Check and return whether first level is used by default for
13301330
* DMA translation.
13311331
*/
1332-
static bool first_level_by_default(unsigned int type)
1332+
static bool first_level_by_default(struct intel_iommu *iommu)
13331333
{
13341334
/* Only SL is available in legacy mode */
1335-
if (!scalable_mode_support())
1335+
if (!sm_supported(iommu))
13361336
return false;
13371337

13381338
/* Only level (either FL or SL) is available, just use it */
1339-
if (intel_cap_flts_sanity() ^ intel_cap_slts_sanity())
1340-
return intel_cap_flts_sanity();
1339+
if (ecap_flts(iommu->ecap) ^ ecap_slts(iommu->ecap))
1340+
return ecap_flts(iommu->ecap);
13411341

1342-
/* Both levels are available, decide it based on domain type */
1343-
return type != IOMMU_DOMAIN_UNMANAGED;
1342+
return true;
13441343
}
13451344

13461345
int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu)
@@ -3110,7 +3109,7 @@ int __init intel_iommu_init(void)
31103109
* the virtual and physical IOMMU page-tables.
31113110
*/
31123111
if (cap_caching_mode(iommu->cap) &&
3113-
!first_level_by_default(IOMMU_DOMAIN_DMA)) {
3112+
!first_level_by_default(iommu)) {
31143113
pr_info_once("IOMMU batching disallowed due to virtualization\n");
31153114
iommu_set_dma_strict();
31163115
}
@@ -4359,10 +4358,12 @@ static struct iommu_domain identity_domain = {
43594358

43604359
static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device *dev)
43614360
{
4361+
struct device_domain_info *info = dev_iommu_priv_get(dev);
4362+
struct intel_iommu *iommu = info->iommu;
43624363
struct dmar_domain *dmar_domain;
43634364
bool first_stage;
43644365

4365-
first_stage = first_level_by_default(0);
4366+
first_stage = first_level_by_default(iommu);
43664367
dmar_domain = paging_domain_alloc(dev, first_stage);
43674368
if (IS_ERR(dmar_domain))
43684369
return ERR_CAST(dmar_domain);

0 commit comments

Comments
 (0)