Commit 55752949 authored by Lu Baolu's avatar Lu Baolu Committed by Joerg Roedel

iommu/vt-d: Avoid duplicated pci dma alias consideration

As we have abandoned the home-made lazy domain allocation
and delegated the DMA domain life cycle up to the default
domain mechanism defined in the generic iommu layer, we
needn't consider pci alias anymore when mapping/unmapping
the context entries. Without this fix, we see kernel NULL
pointer dereference during pci device hot-plug test.

Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: Kevin Tian <kevin.tian@intel.com>
Fixes: fa954e68 ("iommu/vt-d: Delegate the dma domain to upper layer")
Signed-off-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Reported-and-tested-by: default avatarXu Pengfei <pengfei.xu@intel.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 301e7ee1
...@@ -339,8 +339,6 @@ static void domain_exit(struct dmar_domain *domain); ...@@ -339,8 +339,6 @@ static void domain_exit(struct dmar_domain *domain);
static void domain_remove_dev_info(struct dmar_domain *domain); static void domain_remove_dev_info(struct dmar_domain *domain);
static void dmar_remove_one_dev_info(struct device *dev); static void dmar_remove_one_dev_info(struct device *dev);
static void __dmar_remove_one_dev_info(struct device_domain_info *info); static void __dmar_remove_one_dev_info(struct device_domain_info *info);
static void domain_context_clear(struct intel_iommu *iommu,
struct device *dev);
static int domain_detach_iommu(struct dmar_domain *domain, static int domain_detach_iommu(struct dmar_domain *domain,
struct intel_iommu *iommu); struct intel_iommu *iommu);
static bool device_is_rmrr_locked(struct device *dev); static bool device_is_rmrr_locked(struct device *dev);
...@@ -2105,26 +2103,9 @@ static int domain_context_mapping_one(struct dmar_domain *domain, ...@@ -2105,26 +2103,9 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
return ret; return ret;
} }
struct domain_context_mapping_data {
struct dmar_domain *domain;
struct intel_iommu *iommu;
struct pasid_table *table;
};
static int domain_context_mapping_cb(struct pci_dev *pdev,
u16 alias, void *opaque)
{
struct domain_context_mapping_data *data = opaque;
return domain_context_mapping_one(data->domain, data->iommu,
data->table, PCI_BUS_NUM(alias),
alias & 0xff);
}
static int static int
domain_context_mapping(struct dmar_domain *domain, struct device *dev) domain_context_mapping(struct dmar_domain *domain, struct device *dev)
{ {
struct domain_context_mapping_data data;
struct pasid_table *table; struct pasid_table *table;
struct intel_iommu *iommu; struct intel_iommu *iommu;
u8 bus, devfn; u8 bus, devfn;
...@@ -2134,17 +2115,7 @@ domain_context_mapping(struct dmar_domain *domain, struct device *dev) ...@@ -2134,17 +2115,7 @@ domain_context_mapping(struct dmar_domain *domain, struct device *dev)
return -ENODEV; return -ENODEV;
table = intel_pasid_get_table(dev); table = intel_pasid_get_table(dev);
return domain_context_mapping_one(domain, iommu, table, bus, devfn);
if (!dev_is_pci(dev))
return domain_context_mapping_one(domain, iommu, table,
bus, devfn);
data.domain = domain;
data.iommu = iommu;
data.table = table;
return pci_for_each_dma_alias(to_pci_dev(dev),
&domain_context_mapping_cb, &data);
} }
static int domain_context_mapped_cb(struct pci_dev *pdev, static int domain_context_mapped_cb(struct pci_dev *pdev,
...@@ -4784,28 +4755,6 @@ int __init intel_iommu_init(void) ...@@ -4784,28 +4755,6 @@ int __init intel_iommu_init(void)
return ret; return ret;
} }
static int domain_context_clear_one_cb(struct pci_dev *pdev, u16 alias, void *opaque)
{
struct intel_iommu *iommu = opaque;
domain_context_clear_one(iommu, PCI_BUS_NUM(alias), alias & 0xff);
return 0;
}
/*
* NB - intel-iommu lacks any sort of reference counting for the users of
* dependent devices. If multiple endpoints have intersecting dependent
* devices, unbinding the driver from any one of them will possibly leave
* the others unable to operate.
*/
static void domain_context_clear(struct intel_iommu *iommu, struct device *dev)
{
if (!iommu || !dev || !dev_is_pci(dev))
return;
pci_for_each_dma_alias(to_pci_dev(dev), &domain_context_clear_one_cb, iommu);
}
static void __dmar_remove_one_dev_info(struct device_domain_info *info) static void __dmar_remove_one_dev_info(struct device_domain_info *info)
{ {
struct dmar_domain *domain; struct dmar_domain *domain;
...@@ -4826,7 +4775,7 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info) ...@@ -4826,7 +4775,7 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info)
PASID_RID2PASID); PASID_RID2PASID);
iommu_disable_dev_iotlb(info); iommu_disable_dev_iotlb(info);
domain_context_clear(iommu, info->dev); domain_context_clear_one(iommu, info->bus, info->devfn);
intel_pasid_free_table(info->dev); intel_pasid_free_table(info->dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment