mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] AMD IOMMU fixes for 2.6.34
@ 2010-03-01 13:24 Joerg Roedel
  2010-03-01 13:24 ` [PATCH 1/4] x86/amd-iommu: Remove double NULL check in check_device Joerg Roedel
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-03-01 13:24 UTC (permalink / raw)
  To: iommu; +Cc: linux-kernel

Hi,

here are some fixes I queued up for the amd iommu driver. I plan to send them
to Linus together with the other driver and iommu-api updates in my tree. If
there are any objections against the patches in this set please let me know.

Thanks,

	Joerg



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] x86/amd-iommu: Remove double NULL check in check_device
  2010-03-01 13:24 [PATCH 0/4] AMD IOMMU fixes for 2.6.34 Joerg Roedel
@ 2010-03-01 13:24 ` Joerg Roedel
  2010-03-01 13:24 ` [PATCH 2/4] x86/amd-iommu: Protect IOMMU-API map/unmap path Joerg Roedel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-03-01 13:24 UTC (permalink / raw)
  To: iommu; +Cc: linux-kernel, Julia Lawall, Joerg Roedel

From: Julia Lawall <julia@diku.dk>

dev was tested just above, so drop the second test.

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/kernel/amd_iommu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index adb0ba0..2c4a501 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -118,7 +118,7 @@ static bool check_device(struct device *dev)
 		return false;
 
 	/* No device or no PCI device */
-	if (!dev || dev->bus != &pci_bus_type)
+	if (dev->bus != &pci_bus_type)
 		return false;
 
 	devid = get_device_id(dev);
-- 
1.7.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] x86/amd-iommu: Protect IOMMU-API map/unmap path
  2010-03-01 13:24 [PATCH 0/4] AMD IOMMU fixes for 2.6.34 Joerg Roedel
  2010-03-01 13:24 ` [PATCH 1/4] x86/amd-iommu: Remove double NULL check in check_device Joerg Roedel
@ 2010-03-01 13:24 ` Joerg Roedel
  2010-03-01 13:24 ` [PATCH 3/4] x86/amd-iommu: Pt mode fix for domain_destroy Joerg Roedel
  2010-03-01 13:24 ` [PATCH 4/4] x86/amd-iommu: Report errors in acpi parsing functions upstream Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-03-01 13:24 UTC (permalink / raw)
  To: iommu; +Cc: linux-kernel, Joerg Roedel

This patch introduces a mutex to lock page table updates in
the IOMMU-API path. We can't use the spin_lock here because
this patch might sleep.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/include/asm/amd_iommu_types.h |    2 ++
 arch/x86/kernel/amd_iommu.c            |    9 +++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/amd_iommu_types.h b/arch/x86/include/asm/amd_iommu_types.h
index ba19ad4..5e46e78 100644
--- a/arch/x86/include/asm/amd_iommu_types.h
+++ b/arch/x86/include/asm/amd_iommu_types.h
@@ -21,6 +21,7 @@
 #define _ASM_X86_AMD_IOMMU_TYPES_H
 
 #include <linux/types.h>
+#include <linux/mutex.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
 
@@ -237,6 +238,7 @@ struct protection_domain {
 	struct list_head list;  /* for list of all protection domains */
 	struct list_head dev_list; /* List of all devices in this domain */
 	spinlock_t lock;	/* mostly used to lock the page table*/
+	struct mutex api_lock;	/* protect page tables in the iommu-api path */
 	u16 id;			/* the domain id written to the device table */
 	int mode;		/* paging mode (0-6 levels) */
 	u64 *pt_root;		/* page table root pointer */
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 2c4a501..b97f2f1 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -2327,6 +2327,7 @@ static struct protection_domain *protection_domain_alloc(void)
 		return NULL;
 
 	spin_lock_init(&domain->lock);
+	mutex_init(&domain->api_lock);
 	domain->id = domain_id_alloc();
 	if (!domain->id)
 		goto out_err;
@@ -2456,6 +2457,8 @@ static int amd_iommu_map_range(struct iommu_domain *dom,
 	iova  &= PAGE_MASK;
 	paddr &= PAGE_MASK;
 
+	mutex_lock(&domain->api_lock);
+
 	for (i = 0; i < npages; ++i) {
 		ret = iommu_map_page(domain, iova, paddr, prot, PM_MAP_4k);
 		if (ret)
@@ -2465,6 +2468,8 @@ static int amd_iommu_map_range(struct iommu_domain *dom,
 		paddr += PAGE_SIZE;
 	}
 
+	mutex_unlock(&domain->api_lock);
+
 	return 0;
 }
 
@@ -2477,12 +2482,16 @@ static void amd_iommu_unmap_range(struct iommu_domain *dom,
 
 	iova  &= PAGE_MASK;
 
+	mutex_lock(&domain->api_lock);
+
 	for (i = 0; i < npages; ++i) {
 		iommu_unmap_page(domain, iova, PM_MAP_4k);
 		iova  += PAGE_SIZE;
 	}
 
 	iommu_flush_tlb_pde(domain);
+
+	mutex_unlock(&domain->api_lock);
 }
 
 static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
-- 
1.7.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] x86/amd-iommu: Pt mode fix for domain_destroy
  2010-03-01 13:24 [PATCH 0/4] AMD IOMMU fixes for 2.6.34 Joerg Roedel
  2010-03-01 13:24 ` [PATCH 1/4] x86/amd-iommu: Remove double NULL check in check_device Joerg Roedel
  2010-03-01 13:24 ` [PATCH 2/4] x86/amd-iommu: Protect IOMMU-API map/unmap path Joerg Roedel
@ 2010-03-01 13:24 ` Joerg Roedel
  2010-03-01 13:24 ` [PATCH 4/4] x86/amd-iommu: Report errors in acpi parsing functions upstream Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-03-01 13:24 UTC (permalink / raw)
  To: iommu; +Cc: linux-kernel, Chris Wright, stable, Joerg Roedel

From: Chris Wright <chrisw@sous-sol.org>

After a guest is shutdown, assigned devices are not properly
returned to the pt domain.  This can leave the device using
stale cached IOMMU data, and result in a non-functional
device after it's re-bound to the host driver.  For example,
I see this upon rebinding:

 AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a8000 flags=0x0050]
 AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a8040 flags=0x0050]
 AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a8080 flags=0x0050]
 AMD-Vi: Event logged [IO_PAGE_FAULT device=02:00.0 domain=0x0000 address=0x000000007e2a80c0 flags=0x0050]
 0000:02:00.0: eth2: Detected Hardware Unit Hang:
 ...

The amd_iommu_destroy_domain() function calls do_detach()
which doesn't reattach the pt domain to the device.
Use __detach_device() instead.

Cc: stable@kernel.org
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/kernel/amd_iommu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index b97f2f1..0c04254 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -2298,7 +2298,7 @@ static void cleanup_domain(struct protection_domain *domain)
 	list_for_each_entry_safe(dev_data, next, &domain->dev_list, list) {
 		struct device *dev = dev_data->dev;
 
-		do_detach(dev);
+		__detach_device(dev);
 		atomic_set(&dev_data->bind, 0);
 	}
 
-- 
1.7.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] x86/amd-iommu: Report errors in acpi parsing functions upstream
  2010-03-01 13:24 [PATCH 0/4] AMD IOMMU fixes for 2.6.34 Joerg Roedel
                   ` (2 preceding siblings ...)
  2010-03-01 13:24 ` [PATCH 3/4] x86/amd-iommu: Pt mode fix for domain_destroy Joerg Roedel
@ 2010-03-01 13:24 ` Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-03-01 13:24 UTC (permalink / raw)
  To: iommu; +Cc: linux-kernel, Joerg Roedel

Since acpi_table_parse ignores the return values of the
parsing function this patch introduces a workaround and
reports these errors upstream via a global variable.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/kernel/amd_iommu_init.c |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c
index 9dc91b4..feaf471 100644
--- a/arch/x86/kernel/amd_iommu_init.c
+++ b/arch/x86/kernel/amd_iommu_init.c
@@ -138,9 +138,9 @@ int amd_iommus_present;
 bool amd_iommu_np_cache __read_mostly;
 
 /*
- * Set to true if ACPI table parsing and hardware intialization went properly
+ * The ACPI table parsing functions set this variable on an error
  */
-static bool amd_iommu_initialized;
+static int __initdata amd_iommu_init_err;
 
 /*
  * List of protection domains - used during resume
@@ -391,9 +391,11 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table)
 	 */
 	for (i = 0; i < table->length; ++i)
 		checksum += p[i];
-	if (checksum != 0)
+	if (checksum != 0) {
 		/* ACPI table corrupt */
-		return -ENODEV;
+		amd_iommu_init_err = -ENODEV;
+		return 0;
+	}
 
 	p += IVRS_HEADER_LENGTH;
 
@@ -920,11 +922,16 @@ static int __init init_iommu_all(struct acpi_table_header *table)
 				    h->mmio_phys);
 
 			iommu = kzalloc(sizeof(struct amd_iommu), GFP_KERNEL);
-			if (iommu == NULL)
-				return -ENOMEM;
+			if (iommu == NULL) {
+				amd_iommu_init_err = -ENOMEM;
+				return 0;
+			}
+
 			ret = init_iommu_one(iommu, h);
-			if (ret)
-				return ret;
+			if (ret) {
+				amd_iommu_init_err = ret;
+				return 0;
+			}
 			break;
 		default:
 			break;
@@ -934,8 +941,6 @@ static int __init init_iommu_all(struct acpi_table_header *table)
 	}
 	WARN_ON(p != end);
 
-	amd_iommu_initialized = true;
-
 	return 0;
 }
 
@@ -1211,6 +1216,10 @@ static int __init amd_iommu_init(void)
 	if (acpi_table_parse("IVRS", find_last_devid_acpi) != 0)
 		return -ENODEV;
 
+	ret = amd_iommu_init_err;
+	if (ret)
+		goto out;
+
 	dev_table_size     = tbl_size(DEV_TABLE_ENTRY_SIZE);
 	alias_table_size   = tbl_size(ALIAS_TABLE_ENTRY_SIZE);
 	rlookup_table_size = tbl_size(RLOOKUP_TABLE_ENTRY_SIZE);
@@ -1270,12 +1279,19 @@ static int __init amd_iommu_init(void)
 	if (acpi_table_parse("IVRS", init_iommu_all) != 0)
 		goto free;
 
-	if (!amd_iommu_initialized)
+	if (amd_iommu_init_err) {
+		ret = amd_iommu_init_err;
 		goto free;
+	}
 
 	if (acpi_table_parse("IVRS", init_memory_definitions) != 0)
 		goto free;
 
+	if (amd_iommu_init_err) {
+		ret = amd_iommu_init_err;
+		goto free;
+	}
+
 	ret = sysdev_class_register(&amd_iommu_sysdev_class);
 	if (ret)
 		goto free;
-- 
1.7.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-01 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-01 13:24 [PATCH 0/4] AMD IOMMU fixes for 2.6.34 Joerg Roedel
2010-03-01 13:24 ` [PATCH 1/4] x86/amd-iommu: Remove double NULL check in check_device Joerg Roedel
2010-03-01 13:24 ` [PATCH 2/4] x86/amd-iommu: Protect IOMMU-API map/unmap path Joerg Roedel
2010-03-01 13:24 ` [PATCH 3/4] x86/amd-iommu: Pt mode fix for domain_destroy Joerg Roedel
2010-03-01 13:24 ` [PATCH 4/4] x86/amd-iommu: Report errors in acpi parsing functions upstream Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®