Skip to content

Commit 28ccce0

Browse files
committed
iommu/vt-d: Calculate translation in domain_context_mapping_one
There is no reason to pass the translation type through multiple layers. It can also be determined in the domain_context_mapping_one function directly. Signed-off-by: Joerg Roedel <[email protected]>
1 parent e241142 commit 28ccce0

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ static inline int first_pte_in_page(struct dma_pte *pte)
364364
static struct dmar_domain *si_domain;
365365
static int hw_pass_through = 1;
366366

367-
/* domain represents a virtual machine, more than one devices
367+
/*
368+
* Domain represents a virtual machine, more than one devices
368369
* across iommus may be owned in one domain, e.g. kvm guest.
369370
*/
370371
#define DOMAIN_FLAG_VIRTUAL_MACHINE (1 << 0)
@@ -640,6 +641,11 @@ static inline int domain_type_is_vm(struct dmar_domain *domain)
640641
return domain->flags & DOMAIN_FLAG_VIRTUAL_MACHINE;
641642
}
642643

644+
static inline int domain_type_is_si(struct dmar_domain *domain)
645+
{
646+
return domain->flags & DOMAIN_FLAG_STATIC_IDENTITY;
647+
}
648+
643649
static inline int domain_type_is_vm_or_si(struct dmar_domain *domain)
644650
{
645651
return domain->flags & (DOMAIN_FLAG_VIRTUAL_MACHINE |
@@ -1907,21 +1913,23 @@ static void domain_exit(struct dmar_domain *domain)
19071913

19081914
static int domain_context_mapping_one(struct dmar_domain *domain,
19091915
struct intel_iommu *iommu,
1910-
u8 bus, u8 devfn, int translation)
1916+
u8 bus, u8 devfn)
19111917
{
1918+
int translation = CONTEXT_TT_MULTI_LEVEL;
1919+
struct device_domain_info *info = NULL;
19121920
struct context_entry *context;
19131921
unsigned long flags;
19141922
struct dma_pte *pgd;
19151923
int id;
19161924
int agaw;
1917-
struct device_domain_info *info = NULL;
1925+
1926+
if (hw_pass_through && domain_type_is_si(domain))
1927+
translation = CONTEXT_TT_PASS_THROUGH;
19181928

19191929
pr_debug("Set context mapping for %02x:%02x.%d\n",
19201930
bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
19211931

19221932
BUG_ON(!domain->pgd);
1923-
BUG_ON(translation != CONTEXT_TT_PASS_THROUGH &&
1924-
translation != CONTEXT_TT_MULTI_LEVEL);
19251933

19261934
spin_lock_irqsave(&iommu->lock, flags);
19271935
context = iommu_context_addr(iommu, bus, devfn, 1);
@@ -2013,7 +2021,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
20132021
struct domain_context_mapping_data {
20142022
struct dmar_domain *domain;
20152023
struct intel_iommu *iommu;
2016-
int translation;
20172024
};
20182025

20192026
static int domain_context_mapping_cb(struct pci_dev *pdev,
@@ -2022,13 +2029,11 @@ static int domain_context_mapping_cb(struct pci_dev *pdev,
20222029
struct domain_context_mapping_data *data = opaque;
20232030

20242031
return domain_context_mapping_one(data->domain, data->iommu,
2025-
PCI_BUS_NUM(alias), alias & 0xff,
2026-
data->translation);
2032+
PCI_BUS_NUM(alias), alias & 0xff);
20272033
}
20282034

20292035
static int
2030-
domain_context_mapping(struct dmar_domain *domain, struct device *dev,
2031-
int translation)
2036+
domain_context_mapping(struct dmar_domain *domain, struct device *dev)
20322037
{
20332038
struct intel_iommu *iommu;
20342039
u8 bus, devfn;
@@ -2039,12 +2044,10 @@ domain_context_mapping(struct dmar_domain *domain, struct device *dev,
20392044
return -ENODEV;
20402045

20412046
if (!dev_is_pci(dev))
2042-
return domain_context_mapping_one(domain, iommu, bus, devfn,
2043-
translation);
2047+
return domain_context_mapping_one(domain, iommu, bus, devfn);
20442048

20452049
data.domain = domain;
20462050
data.iommu = iommu;
2047-
data.translation = translation;
20482051

20492052
return pci_for_each_dma_alias(to_pci_dev(dev),
20502053
&domain_context_mapping_cb, &data);
@@ -2511,7 +2514,7 @@ static int iommu_prepare_identity_map(struct device *dev,
25112514
goto error;
25122515

25132516
/* context entry init */
2514-
ret = domain_context_mapping(domain, dev, CONTEXT_TT_MULTI_LEVEL);
2517+
ret = domain_context_mapping(domain, dev);
25152518
if (ret)
25162519
goto error;
25172520

@@ -2624,8 +2627,7 @@ static int identity_mapping(struct device *dev)
26242627
return 0;
26252628
}
26262629

2627-
static int domain_add_dev_info(struct dmar_domain *domain,
2628-
struct device *dev, int translation)
2630+
static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
26292631
{
26302632
struct dmar_domain *ndomain;
26312633
struct intel_iommu *iommu;
@@ -2640,7 +2642,7 @@ static int domain_add_dev_info(struct dmar_domain *domain,
26402642
if (ndomain != domain)
26412643
return -EBUSY;
26422644

2643-
ret = domain_context_mapping(domain, dev, translation);
2645+
ret = domain_context_mapping(domain, dev);
26442646
if (ret) {
26452647
domain_remove_one_dev_info(domain, dev);
26462648
return ret;
@@ -2785,9 +2787,7 @@ static int __init dev_prepare_static_identity_mapping(struct device *dev, int hw
27852787
if (!iommu_should_identity_map(dev, 1))
27862788
return 0;
27872789

2788-
ret = domain_add_dev_info(si_domain, dev,
2789-
hw ? CONTEXT_TT_PASS_THROUGH :
2790-
CONTEXT_TT_MULTI_LEVEL);
2790+
ret = domain_add_dev_info(si_domain, dev);
27912791
if (!ret)
27922792
pr_info("%s identity mapping for device %s\n",
27932793
hw ? "Hardware" : "Software", dev_name(dev));
@@ -3314,7 +3314,7 @@ static struct dmar_domain *__get_valid_domain_for_dev(struct device *dev)
33143314

33153315
/* make sure context mapping is ok */
33163316
if (unlikely(!domain_context_mapped(dev))) {
3317-
ret = domain_context_mapping(domain, dev, CONTEXT_TT_MULTI_LEVEL);
3317+
ret = domain_context_mapping(domain, dev);
33183318
if (ret) {
33193319
pr_err("Domain context map for %s failed\n",
33203320
dev_name(dev));
@@ -3369,10 +3369,7 @@ static int iommu_no_mapping(struct device *dev)
33693369
*/
33703370
if (iommu_should_identity_map(dev, 0)) {
33713371
int ret;
3372-
ret = domain_add_dev_info(si_domain, dev,
3373-
hw_pass_through ?
3374-
CONTEXT_TT_PASS_THROUGH :
3375-
CONTEXT_TT_MULTI_LEVEL);
3372+
ret = domain_add_dev_info(si_domain, dev);
33763373
if (!ret) {
33773374
pr_info("64bit %s uses identity mapping\n",
33783375
dev_name(dev));
@@ -4810,7 +4807,7 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
48104807
dmar_domain->agaw--;
48114808
}
48124809

4813-
return domain_add_dev_info(dmar_domain, dev, CONTEXT_TT_MULTI_LEVEL);
4810+
return domain_add_dev_info(dmar_domain, dev);
48144811
}
48154812

48164813
static void intel_iommu_detach_device(struct iommu_domain *domain,

0 commit comments

Comments
 (0)