iommu/amd: Update set_dte_entry and clear_dte_entry
authorSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Wed, 6 Jul 2022 11:38:11 +0000 (17:08 +0530)
committerJoerg Roedel <jroedel@suse.de>
Thu, 7 Jul 2022 07:37:46 +0000 (09:37 +0200)
Start using per PCI segment data structures instead of global data
structures.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Link: https://lore.kernel.org/r/20220706113825.25582-22-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/iommu.c

index 6e0cd9c..493cda5 100644 (file)
@@ -1537,6 +1537,7 @@ static void set_dte_entry(struct amd_iommu *iommu, u16 devid,
        u64 pte_root = 0;
        u64 flags = 0;
        u32 old_domid;
+       struct dev_table_entry *dev_table = get_dev_table(iommu);
 
        if (domain->iop.mode != PAGE_MODE_NONE)
                pte_root = iommu_virt_to_phys(domain->iop.root);
@@ -1545,7 +1546,7 @@ static void set_dte_entry(struct amd_iommu *iommu, u16 devid,
                    << DEV_ENTRY_MODE_SHIFT;
        pte_root |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V | DTE_FLAG_TV;
 
-       flags = amd_iommu_dev_table[devid].data[1];
+       flags = dev_table[devid].data[1];
 
        if (ats)
                flags |= DTE_FLAG_IOTLB;
@@ -1584,9 +1585,9 @@ static void set_dte_entry(struct amd_iommu *iommu, u16 devid,
        flags &= ~DEV_DOMID_MASK;
        flags |= domain->id;
 
-       old_domid = amd_iommu_dev_table[devid].data[1] & DEV_DOMID_MASK;
-       amd_iommu_dev_table[devid].data[1]  = flags;
-       amd_iommu_dev_table[devid].data[0]  = pte_root;
+       old_domid = dev_table[devid].data[1] & DEV_DOMID_MASK;
+       dev_table[devid].data[1]  = flags;
+       dev_table[devid].data[0]  = pte_root;
 
        /*
         * A kdump kernel might be replacing a domain ID that was copied from
@@ -1598,11 +1599,13 @@ static void set_dte_entry(struct amd_iommu *iommu, u16 devid,
        }
 }
 
-static void clear_dte_entry(u16 devid)
+static void clear_dte_entry(struct amd_iommu *iommu, u16 devid)
 {
+       struct dev_table_entry *dev_table = get_dev_table(iommu);
+
        /* remove entry from the device table seen by the hardware */
-       amd_iommu_dev_table[devid].data[0]  = DTE_FLAG_V | DTE_FLAG_TV;
-       amd_iommu_dev_table[devid].data[1] &= DTE_FLAG_MASK;
+       dev_table[devid].data[0]  = DTE_FLAG_V | DTE_FLAG_TV;
+       dev_table[devid].data[1] &= DTE_FLAG_MASK;
 
        amd_iommu_apply_erratum_63(devid);
 }
@@ -1646,7 +1649,7 @@ static void do_detach(struct iommu_dev_data *dev_data)
        /* Update data structures */
        dev_data->domain = NULL;
        list_del(&dev_data->list);
-       clear_dte_entry(dev_data->devid);
+       clear_dte_entry(iommu, dev_data->devid);
        clone_aliases(iommu, dev_data->dev);
 
        /* Flush the DTE entry */