Skip to content

Commit 1903ef8

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Refactor device_to_iommu() to retrieve iommu directly
The device_to_iommu() helper was originally designed to look up the DMAR ACPI table to retrieve the iommu device and the request ID for a given device. However, it was also being used in other places where there was no need to lookup the ACPI table at all. Retrieve the iommu device directly from the per-device iommu private data in functions called after device is probed. Rename the original device_to_iommu() function to a more meaningful name, device_lookup_iommu(), to avoid mis-using it. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Link: https://lore.kernel.org/r/20231116015048.29675-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 2cc14f5 commit 1903ef8

3 files changed

Lines changed: 13 additions & 38 deletions

File tree

drivers/iommu/intel/iommu.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static bool iommu_is_dummy(struct intel_iommu *iommu, struct device *dev)
703703
return false;
704704
}
705705

706-
struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn)
706+
static struct intel_iommu *device_lookup_iommu(struct device *dev, u8 *bus, u8 *devfn)
707707
{
708708
struct dmar_drhd_unit *drhd = NULL;
709709
struct pci_dev *pdev = NULL;
@@ -2081,14 +2081,11 @@ static int domain_context_mapping_cb(struct pci_dev *pdev,
20812081
static int
20822082
domain_context_mapping(struct dmar_domain *domain, struct device *dev)
20832083
{
2084+
struct device_domain_info *info = dev_iommu_priv_get(dev);
20842085
struct domain_context_mapping_data data;
2086+
struct intel_iommu *iommu = info->iommu;
2087+
u8 bus = info->bus, devfn = info->devfn;
20852088
struct pasid_table *table;
2086-
struct intel_iommu *iommu;
2087-
u8 bus, devfn;
2088-
2089-
iommu = device_to_iommu(dev, &bus, &devfn);
2090-
if (!iommu)
2091-
return -ENODEV;
20922089

20932090
table = intel_pasid_get_table(dev);
20942091

@@ -2447,15 +2444,10 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
24472444
struct device *dev)
24482445
{
24492446
struct device_domain_info *info = dev_iommu_priv_get(dev);
2450-
struct intel_iommu *iommu;
2447+
struct intel_iommu *iommu = info->iommu;
24512448
unsigned long flags;
2452-
u8 bus, devfn;
24532449
int ret;
24542450

2455-
iommu = device_to_iommu(dev, &bus, &devfn);
2456-
if (!iommu)
2457-
return -ENODEV;
2458-
24592451
ret = domain_attach_iommu(domain, iommu);
24602452
if (ret)
24612453
return ret;
@@ -4116,14 +4108,11 @@ static void intel_iommu_domain_free(struct iommu_domain *domain)
41164108
int prepare_domain_attach_device(struct iommu_domain *domain,
41174109
struct device *dev)
41184110
{
4111+
struct device_domain_info *info = dev_iommu_priv_get(dev);
41194112
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
4120-
struct intel_iommu *iommu;
4113+
struct intel_iommu *iommu = info->iommu;
41214114
int addr_width;
41224115

4123-
iommu = device_to_iommu(dev, NULL, NULL);
4124-
if (!iommu)
4125-
return -ENODEV;
4126-
41274116
if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap))
41284117
return -EINVAL;
41294118

@@ -4399,7 +4388,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
43994388
u8 bus, devfn;
44004389
int ret;
44014390

4402-
iommu = device_to_iommu(dev, &bus, &devfn);
4391+
iommu = device_lookup_iommu(dev, &bus, &devfn);
44034392
if (!iommu || !iommu->iommu.ops)
44044393
return ERR_PTR(-ENODEV);
44054394

@@ -4735,8 +4724,9 @@ static int intel_iommu_iotlb_sync_map(struct iommu_domain *domain,
47354724

47364725
static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
47374726
{
4738-
struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
4727+
struct device_domain_info *info = dev_iommu_priv_get(dev);
47394728
struct dev_pasid_info *curr, *dev_pasid = NULL;
4729+
struct intel_iommu *iommu = info->iommu;
47404730
struct dmar_domain *dmar_domain;
47414731
struct iommu_domain *domain;
47424732
unsigned long flags;

drivers/iommu/intel/iommu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,6 @@ int dmar_ir_support(void);
897897
void *alloc_pgtable_page(int node, gfp_t gfp);
898898
void free_pgtable_page(void *vaddr);
899899
void iommu_flush_write_buffer(struct intel_iommu *iommu);
900-
struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn);
901900
struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent,
902901
const struct iommu_user_data *user_data);
903902

drivers/iommu/intel/svm.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,9 @@ static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev,
366366
void intel_svm_remove_dev_pasid(struct device *dev, u32 pasid)
367367
{
368368
struct intel_svm_dev *sdev;
369-
struct intel_iommu *iommu;
370369
struct intel_svm *svm;
371370
struct mm_struct *mm;
372371

373-
iommu = device_to_iommu(dev, NULL, NULL);
374-
if (!iommu)
375-
return;
376-
377372
if (pasid_to_svm_sdev(dev, pasid, &svm, &sdev))
378373
return;
379374
mm = svm->mm;
@@ -724,25 +719,16 @@ int intel_svm_page_response(struct device *dev,
724719
struct iommu_fault_event *evt,
725720
struct iommu_page_response *msg)
726721
{
722+
struct device_domain_info *info = dev_iommu_priv_get(dev);
723+
struct intel_iommu *iommu = info->iommu;
724+
u8 bus = info->bus, devfn = info->devfn;
727725
struct iommu_fault_page_request *prm;
728-
struct intel_iommu *iommu;
729726
bool private_present;
730727
bool pasid_present;
731728
bool last_page;
732-
u8 bus, devfn;
733729
int ret = 0;
734730
u16 sid;
735731

736-
if (!dev || !dev_is_pci(dev))
737-
return -ENODEV;
738-
739-
iommu = device_to_iommu(dev, &bus, &devfn);
740-
if (!iommu)
741-
return -ENODEV;
742-
743-
if (!msg || !evt)
744-
return -EINVAL;
745-
746732
prm = &evt->fault.prm;
747733
sid = PCI_DEVID(bus, devfn);
748734
pasid_present = prm->flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID;

0 commit comments

Comments
 (0)