Messages in this thread | | | From | "Tian, Kevin" <> | Subject | RE: [PATCH 02/12] iommu/vt-d: Remove for_each_device_domain() | Date | Wed, 1 Jun 2022 08:53:49 +0000 |
| |
> From: Lu Baolu <baolu.lu@linux.intel.com> > Sent: Friday, May 27, 2022 2:30 PM > > The per-device device_domain_info data could be retrieved from the > device itself. There's no need to search a global list. > > Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
> --- > drivers/iommu/intel/iommu.h | 2 -- > drivers/iommu/intel/iommu.c | 25 ------------------------- > drivers/iommu/intel/pasid.c | 37 +++++++++++-------------------------- > 3 files changed, 11 insertions(+), 53 deletions(-) > > diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h > index 8a6d64d726c0..2f4a5b9509c0 100644 > --- a/drivers/iommu/intel/iommu.h > +++ b/drivers/iommu/intel/iommu.h > @@ -727,8 +727,6 @@ extern int dmar_ir_support(void); > void *alloc_pgtable_page(int node); > void free_pgtable_page(void *vaddr); > struct intel_iommu *domain_get_iommu(struct dmar_domain *domain); > -int for_each_device_domain(int (*fn)(struct device_domain_info *info, > - void *data), void *data); > void iommu_flush_write_buffer(struct intel_iommu *iommu); > int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device > *dev); > struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 > *devfn); > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index cacae8bdaa65..6549b09d7f32 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -316,31 +316,6 @@ static int iommu_skip_te_disable; > > static DEFINE_SPINLOCK(device_domain_lock); > static LIST_HEAD(device_domain_list); > - > -/* > - * Iterate over elements in device_domain_list and call the specified > - * callback @fn against each element. > - */ > -int for_each_device_domain(int (*fn)(struct device_domain_info *info, > - void *data), void *data) > -{ > - int ret = 0; > - unsigned long flags; > - struct device_domain_info *info; > - > - spin_lock_irqsave(&device_domain_lock, flags); > - list_for_each_entry(info, &device_domain_list, global) { > - ret = fn(info, data); > - if (ret) { > - spin_unlock_irqrestore(&device_domain_lock, flags); > - return ret; > - } > - } > - spin_unlock_irqrestore(&device_domain_lock, flags); > - > - return 0; > -} > - > const struct iommu_ops intel_iommu_ops; > > static bool translation_pre_enabled(struct intel_iommu *iommu) > diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c > index b2ac5869286f..0627d6465f25 100644 > --- a/drivers/iommu/intel/pasid.c > +++ b/drivers/iommu/intel/pasid.c > @@ -103,36 +103,20 @@ device_detach_pasid_table(struct > device_domain_info *info, > } > > struct pasid_table_opaque { > - struct pasid_table **pasid_table; > - int segment; > - int bus; > - int devfn; > + struct pasid_table *pasid_table; > }; > > -static int search_pasid_table(struct device_domain_info *info, void *opaque) > -{ > - struct pasid_table_opaque *data = opaque; > - > - if (info->iommu->segment == data->segment && > - info->bus == data->bus && > - info->devfn == data->devfn && > - info->pasid_table) { > - *data->pasid_table = info->pasid_table; > - return 1; > - } > - > - return 0; > -} > - > static int get_alias_pasid_table(struct pci_dev *pdev, u16 alias, void > *opaque) > { > struct pasid_table_opaque *data = opaque; > + struct device_domain_info *info; > > - data->segment = pci_domain_nr(pdev->bus); > - data->bus = PCI_BUS_NUM(alias); > - data->devfn = alias & 0xff; > + info = dev_iommu_priv_get(&pdev->dev); > + if (!info || !info->pasid_table) > + return 0; > > - return for_each_device_domain(&search_pasid_table, data); > + data->pasid_table = info->pasid_table; > + return 1; > } > > /* > @@ -141,9 +125,9 @@ static int get_alias_pasid_table(struct pci_dev *pdev, > u16 alias, void *opaque) > */ > int intel_pasid_alloc_table(struct device *dev) > { > + struct pasid_table_opaque data = { NULL }; > struct device_domain_info *info; > struct pasid_table *pasid_table; > - struct pasid_table_opaque data; > struct page *pages; > u32 max_pasid = 0; > int ret, order; > @@ -155,11 +139,12 @@ int intel_pasid_alloc_table(struct device *dev) > return -EINVAL; > > /* DMA alias device already has a pasid table, use it: */ > - data.pasid_table = &pasid_table; > ret = pci_for_each_dma_alias(to_pci_dev(dev), > &get_alias_pasid_table, &data); > - if (ret) > + if (ret) { > + pasid_table = data.pasid_table; > goto attach_out; > + } > > pasid_table = kzalloc(sizeof(*pasid_table), GFP_KERNEL); > if (!pasid_table) > -- > 2.25.1
| |