在 2021/6/17 19:34, Xiongfeng Wang 写道:

On 2021/6/4 17:36, LeoLiuoc wrote:
When using ACPI device to create identity mapping, if the physical node of
the ACPI device is a pci device, domain_1 will be created for these two
devices. But if the pci device and other pci devices belong to another
domain_2, this will happen conflict and destroy another domain. Such as
PCI devices under the PCIE-to-PCI bridge. Therefore, when the physical
node of the ACPI device is a PCI device, this patch uses the PCI device to
create the domain. In this way, there is only one domain.

Signed-off-by: LeoLiu-oc <LeoLiu-oc@zhaoxin.com>
---
 drivers/iommu/intel-iommu.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index e111e5d6d269..cf0dc4c80183 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2736,12 +2736,32 @@ static int domain_prepare_identity_map(struct device *dev,
     return iommu_domain_identity_map(domain, start, end);
 }

+static struct device *acpi_dev_find_pci_dev(struct device *dev)
+{
+    struct acpi_device_physical_node *pn;
+    struct acpi_device *adev;
+
+    if (dev->bus == &acpi_bus_type) {
+        adev = to_acpi_device(dev);
+        mutex_lock(&adev->physical_node_lock);
+        list_for_each_entry(pn, &adev->physical_node_list, node) {
+            if (dev_is_pci(pn->dev)) {
Needs 'mutex_unlock' here
Yes, you are right. We will submit a new version(v2) of this patch soon.
BRs
Leo

      
+                return pn->dev;
+            }
+        }
+        mutex_unlock(&adev->physical_node_lock);
+    }
+
+    return dev;
+}
+
 static int iommu_prepare_identity_map(struct device *dev,
                       unsigned long long start,
                       unsigned long long end)
 {
     struct dmar_domain *domain;
     int ret;
+    dev = acpi_dev_find_pci_dev(dev);

     domain = get_domain_for_dev(dev, DEFAULT_DOMAIN_ADDRESS_WIDTH);
     if (!domain)
.