Skip to contentSkip to conversation

dmar: Fix domain id not update to newly create

PATCH New Youquan Song 1 participant 3 messages Dec 12, 2013 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dmar: Fix domain id not update to newly create

At domain_context_mapping_one(), if the domain is still not assign domain id, it will assign a new domain_id for it, but the newly creating domain id is not update to domain, so the domain will keep an unkown domain id.

It will cause the issues: like flush wrong domain in iommu->flush.flush_iotlb, and free/release wrong domain.

---
 drivers/iommu/intel-iommu.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/iommu/intel-iommu.c +1 -0
index 43b9bfe..9cd522f 100644
@@ -1625,6 +1625,7 @@ static int domain_context_mapping_one(struct dmar_domain *domain, int segment,
 		}
 	}
 
+	domain->id = id;
 	context_set_domain_id(context, id);
 
 	if (translation != CONTEXT_TT_PASS_THROUGH) {
Signature · 1 line
1.7.7.4
#1 lore raw

PATCH 2/3 dmar: Move the confuse comments to proper place

the "found=1" should be "there are other device owned by the domain", the comments is put at wrong place and make the code reviewing confuse, so move it to the correct place.

---
 drivers/iommu/intel-iommu.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/iommu/intel-iommu.c +4 -4
index 9cd522f..aa821fc 100644
@@ -3813,10 +3813,6 @@ static void domain_remove_one_dev_info(struct dmar_domain *domain,
 				continue;
 		}
 
-		/* if there is no other devices under the same iommu
-		 * owned by this domain, clear this iommu in iommu_bmp
-		 * update iommu count and coherency
-		 */
 		if (iommu == device_to_iommu(info->segment, info->bus,
 					    info->devfn))
 			found = 1;
@@ -3824,6 +3820,10 @@ static void domain_remove_one_dev_info(struct dmar_domain *domain,
 
 	spin_unlock_irqrestore(&device_domain_lock, flags);
 
+	/* if there is no other devices under the same iommu
+	 * owned by this domain, clear this iommu in iommu_bmp
+	 * update iommu count and coherency
+	 */
 	if (found == 0) {
 		unsigned long tmp_flags;
 		spin_lock_irqsave(&domain->iommu_lock, tmp_flags);
Signature · 1 line
1.7.7.4
#2 lore raw

PATCH 3/3 dmar: reduce loop to find multi-devices owned by IOMMU

When try to find if the iommu owns other devices in the domain except the device will be moved. It will loop all devices under the domain if the removed device is the first device in domain devices list.

This patch will improve it and it only loop before find the removed device and
one of other device, so save the loop time and make the code more clear.

---
 drivers/iommu/intel-iommu.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
drivers/iommu/intel-iommu.c +6 -9
index aa821fc..9f3bf3f 100644
@@ -3785,7 +3785,7 @@ static void domain_remove_one_dev_info(struct dmar_domain *domain,
 	struct device_domain_info *info, *tmp;
 	struct intel_iommu *iommu;
 	unsigned long flags;
-	int found = 0;
+	int found = 0, del = 0;
 
 	iommu = device_to_iommu(pci_domain_nr(pdev->bus), pdev->bus->number,
 				pdev->devfn);
@@ -3806,16 +3806,13 @@ static void domain_remove_one_dev_info(struct dmar_domain *domain,
 			free_devinfo_mem(info);
 
 			spin_lock_irqsave(&device_domain_lock, flags);
-
-			if (found)
-				break;
-			else
-				continue;
-		}
-
-		if (iommu == device_to_iommu(info->segment, info->bus,
+			del = 1;
+		} else if (iommu == device_to_iommu(info->segment, info->bus,
 					    info->devfn))
 			found = 1;
+
+		if (found & del)
+			break;
 	}
 
 	spin_unlock_irqrestore(&device_domain_lock, flags);
Signature · 1 line
1.7.7.4