Skip to contentSkip to conversation

Fixes for AMD-Vi

PATCH New Joerg Roedel 1 participant 3 messages Sep 5, 2011 IOMMU

lore
Share & tools
lore
#0 lore raw

cover Fixes for AMD-Vi

Hi,

here are two small fixes for the AMD IOMMU driver. They fix a small performance problem because of too many unnecessary completion-wait commands and a dead-lock when a driver allocates more than 1GB of dma address space.

Regards,

Joerg

#1 lore raw

PATCH 1/2 iommu/amd: Make sure iommu->need_sync contains correct value

The value is only set to true but never set back to false, which causes to many completion-wait commands to be sent to hardware. Fix it with this patch.

---
 drivers/iommu/amd_iommu.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/iommu/amd_iommu.c +10 -3
index a14f8dc..4565223 100644
@@ -605,7 +605,9 @@ static void build_inv_all(struct iommu_cmd *cmd)
  * Writes the command to the IOMMUs command buffer and informs the
  * hardware about the new command.
  */
-static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd)
+static int iommu_queue_command_sync(struct amd_iommu *iommu,
+				    struct iommu_cmd *cmd,
+				    bool sync)
 {
 	u32 left, tail, head, next_tail;
 	unsigned long flags;
@@ -639,13 +641,18 @@ again:
 	copy_cmd_to_buffer(iommu, cmd, tail);
 
 	/* We need to sync now to make sure all commands are processed */
-	iommu->need_sync = true;
+	iommu->need_sync = sync;
 
 	spin_unlock_irqrestore(&iommu->lock, flags);
 
 	return 0;
 }
 
+static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd)
+{
+	return iommu_queue_command_sync(iommu, cmd, true);
+}
+
 /*
  * This function queues a completion wait command into the command
  * buffer of an IOMMU
@@ -661,7 +668,7 @@ static int iommu_completion_wait(struct amd_iommu *iommu)
 
 	build_completion_wait(&cmd, (u64)&sem);
 
-	ret = iommu_queue_command(iommu, &cmd);
+	ret = iommu_queue_command_sync(iommu, &cmd, false);
 	if (ret)
 		return ret;
 
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/2 iommu/amd: Don't take domain->lock recursivly

In reply to Joerg Roedel

The domain_flush_devices() function takes the domain->lock. But this function is only called from update_domain() which itself is already called unter the domain->lock. This causes a deadlock situation when the dma-address-space of a domain grows larger than 1GB.

---
 drivers/iommu/amd_iommu.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
drivers/iommu/amd_iommu.c +0 -5
index 4565223..0e4227f 100644
@@ -847,14 +847,9 @@ static void domain_flush_complete(struct protection_domain *domain)
 static void domain_flush_devices(struct protection_domain *domain)
 {
 	struct iommu_dev_data *dev_data;
-	unsigned long flags;
-
-	spin_lock_irqsave(&domain->lock, flags);
 
 	list_for_each_entry(dev_data, &domain->dev_list, list)
 		device_flush_dte(dev_data);
-
-	spin_unlock_irqrestore(&domain->lock, flags);
 }
 
 /****************************************************************************
Signature · 1 line
1.7.4.1