Skip to content

Commit de24e55

Browse files
committed
iommu/vt-d: Simplify domain_context_mapping_one
Get rid of the special cases for VM domains vs. non-VM domains and simplify the code further to just handle the hardware passthrough vs. page-table case. Signed-off-by: Joerg Roedel <[email protected]>
1 parent 28ccce0 commit de24e55

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,52 +1942,44 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
19421942
return 0;
19431943
}
19441944

1945-
context_clear_entry(context);
1946-
1947-
id = domain->id;
19481945
pgd = domain->pgd;
19491946

1950-
if (domain_type_is_vm_or_si(domain)) {
1951-
if (domain_type_is_vm(domain)) {
1952-
id = __iommu_attach_domain(domain, iommu);
1953-
if (id < 0) {
1954-
spin_unlock_irqrestore(&iommu->lock, flags);
1955-
pr_err("%s: No free domain ids\n", iommu->name);
1956-
return -EFAULT;
1957-
}
1958-
}
1959-
1960-
/* Skip top levels of page tables for
1961-
* iommu which has less agaw than default.
1962-
* Unnecessary for PT mode.
1963-
*/
1964-
if (translation != CONTEXT_TT_PASS_THROUGH) {
1965-
for (agaw = domain->agaw; agaw != iommu->agaw; agaw--) {
1966-
pgd = phys_to_virt(dma_pte_addr(pgd));
1967-
if (!dma_pte_present(pgd)) {
1968-
spin_unlock_irqrestore(&iommu->lock, flags);
1969-
return -ENOMEM;
1970-
}
1971-
}
1972-
}
1947+
id = __iommu_attach_domain(domain, iommu);
1948+
if (id < 0) {
1949+
spin_unlock_irqrestore(&iommu->lock, flags);
1950+
pr_err("%s: No free domain ids\n", iommu->name);
1951+
return -EFAULT;
19731952
}
19741953

1954+
context_clear_entry(context);
19751955
context_set_domain_id(context, id);
19761956

1957+
/*
1958+
* Skip top levels of page tables for iommu which has less agaw
1959+
* than default. Unnecessary for PT mode.
1960+
*/
19771961
if (translation != CONTEXT_TT_PASS_THROUGH) {
1962+
for (agaw = domain->agaw; agaw != iommu->agaw; agaw--) {
1963+
pgd = phys_to_virt(dma_pte_addr(pgd));
1964+
if (!dma_pte_present(pgd)) {
1965+
spin_unlock_irqrestore(&iommu->lock, flags);
1966+
return -ENOMEM;
1967+
}
1968+
}
1969+
19781970
info = iommu_support_dev_iotlb(domain, iommu, bus, devfn);
19791971
translation = info ? CONTEXT_TT_DEV_IOTLB :
19801972
CONTEXT_TT_MULTI_LEVEL;
1981-
}
1982-
/*
1983-
* In pass through mode, AW must be programmed to indicate the largest
1984-
* AGAW value supported by hardware. And ASR is ignored by hardware.
1985-
*/
1986-
if (unlikely(translation == CONTEXT_TT_PASS_THROUGH))
1987-
context_set_address_width(context, iommu->msagaw);
1988-
else {
1973+
19891974
context_set_address_root(context, virt_to_phys(pgd));
19901975
context_set_address_width(context, iommu->agaw);
1976+
} else {
1977+
/*
1978+
* In pass through mode, AW must be programmed to
1979+
* indicate the largest AGAW value supported by
1980+
* hardware. And ASR is ignored by hardware.
1981+
*/
1982+
context_set_address_width(context, iommu->msagaw);
19911983
}
19921984

19931985
context_set_translation_type(context, translation);

0 commit comments

Comments
 (0)