Skip to contentSkip to conversation

IOMMU fixes for 2.6.33-rc5

GIT PULL New Joerg Roedel 2 participants 7 messages Jan 22, 2010 – Jan 27, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Ingo,

The following changes since commit 92dcffb916d309aa01778bf8963a6932e4014d07:
Linus Torvalds (1):

        Linux 2.6.33-rc5

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.git iommu/fixes

Joerg Roedel (5):
x86/amd-iommu: Fix possible integer overflow
x86/amd-iommu: Fix NULL pointer dereference in __detach_device() x86/amd-iommu: Fix IOMMU-API initialization for iommu=pt x86/amd-iommu: Fix deassignment of a device from the pt_domain Merge branches 'amd-iommu/fixes' and 'dma-debug/fixes' into iommu/fixes

Thiago Farina (1):
lib/dma-debug.c: mark file-local struct symbol static.

 arch/x86/include/asm/amd_iommu_proto.h |    1 +
 arch/x86/kernel/amd_iommu.c            |   23 ++++++++++++++++-------
 arch/x86/kernel/amd_iommu_init.c       |    3 +++
 lib/dma-debug.c                        |    2 +-
 4 files changed, 21 insertions(+), 8 deletions(-)

The patches fix several issues with device kvm device assignement when the amd iommu driver is configured to run in passthrough mode. One patch fixes a possible integer overflow in the driver as well. The last patch in the series fixes a build warning in the dma-api debug code. Please pull.

Thanks,

Joerg

#1 lore raw

PATCH 1/5 x86/amd-iommu: Fix possible integer overflow

The variable i in this function could be increased to over 2**32 which would result in an integer overflow when using int. Fix it by changing i to unsigned long.

---
 arch/x86/kernel/amd_iommu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/amd_iommu.c +1 -1
index 23824fe..c2ccbd7 100644
@@ -980,7 +980,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
 {
 	int index = dma_dom->aperture_size >> APERTURE_RANGE_SHIFT;
 	struct amd_iommu *iommu;
-	int i;
+	unsigned long i;
 
 #ifdef CONFIG_IOMMU_STRESS
 	populate = false;
Signature · 1 line
1.6.6
#2 lore raw

PATCH 2/5 x86/amd-iommu: Fix NULL pointer dereference in __detach_device()

In reply to Joerg Roedel

In the __detach_device function the reference count for a device-domain binding may become zero. This results in the device being removed from the domain and dev_data->domain will be NULL. This is bad because this pointer is dereferenced when trying to unlock the domain->lock. This patch fixes the issue by keeping the domain in a seperate variable.

---
 arch/x86/kernel/amd_iommu.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/amd_iommu.c +5 -2
index c2ccbd7..4478a48 100644
@@ -1489,11 +1489,14 @@ static void __detach_device(struct device *dev)
 {
 	struct iommu_dev_data *dev_data = get_dev_data(dev);
 	struct iommu_dev_data *alias_data;
+	struct protection_domain *domain;
 	unsigned long flags;
 
 	BUG_ON(!dev_data->domain);
 
-	spin_lock_irqsave(&dev_data->domain->lock, flags);
+	domain = dev_data->domain;
+
+	spin_lock_irqsave(&domain->lock, flags);
 
 	if (dev_data->alias != dev) {
 		alias_data = get_dev_data(dev_data->alias);
@@ -1504,7 +1507,7 @@ static void __detach_device(struct device *dev)
 	if (atomic_dec_and_test(&dev_data->bind))
 		do_detach(dev);
 
-	spin_unlock_irqrestore(&dev_data->domain->lock, flags);
+	spin_unlock_irqrestore(&domain->lock, flags);
 
 	/*
 	 * If we run in passthrough mode the device must be assigned to the
Signature · 1 line
1.6.6
#3 lore raw

PATCH 3/5 x86/amd-iommu: Fix IOMMU-API initialization for iommu=pt

In reply to Joerg Roedel

This patch moves the initialization of the iommu-api out of the dma-ops initialization code. This ensures that the iommu-api is initialized even with iommu=pt.

---
 arch/x86/include/asm/amd_iommu_proto.h |    1 +
 arch/x86/kernel/amd_iommu.c            |    8 ++++++--
 arch/x86/kernel/amd_iommu_init.c       |    3 +++
 3 files changed, 10 insertions(+), 2 deletions(-)
arch/x86/include/asm/amd_iommu_proto.h +1 -0
index 4d817f9..d2544f1 100644
@@ -31,6 +31,7 @@ extern void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu);
 extern int amd_iommu_init_devices(void);
 extern void amd_iommu_uninit_devices(void);
 extern void amd_iommu_init_notifier(void);
+extern void amd_iommu_init_api(void);
 #ifndef CONFIG_AMD_IOMMU_STATS
 
 static inline void amd_iommu_stats_init(void) { }
arch/x86/kernel/amd_iommu.c +6 -2
index 4478a48..751ce73 100644
@@ -2221,6 +2221,12 @@ static struct dma_map_ops amd_iommu_dma_ops = {
 /*
  * The function which clues the AMD IOMMU driver into dma_ops.
  */
+
+void __init amd_iommu_init_api(void)
+{
+	register_iommu(&amd_iommu_ops);
+}
+
 int __init amd_iommu_init_dma_ops(void)
 {
 	struct amd_iommu *iommu;
@@ -2256,8 +2262,6 @@ int __init amd_iommu_init_dma_ops(void)
 	/* Make the driver finally visible to the drivers */
 	dma_ops = &amd_iommu_dma_ops;
 
-	register_iommu(&amd_iommu_ops);
-
 	amd_iommu_stats_init();
 
 	return 0;
arch/x86/kernel/amd_iommu_init.c +3 -0
index fb490ce..9dc91b4 100644
@@ -1292,9 +1292,12 @@ static int __init amd_iommu_init(void)
 		ret = amd_iommu_init_passthrough();
 	else
 		ret = amd_iommu_init_dma_ops();
+
 	if (ret)
 		goto free;
 
+	amd_iommu_init_api();
+
 	amd_iommu_init_notifier();
 
 	enable_iommus();
Signature · 1 line
1.6.6
#4 lore raw

PATCH 4/5 x86/amd-iommu: Fix deassignment of a device from the pt_domain

In reply to Joerg Roedel

Deassigning a device from the passthrough domain does not work and breaks device assignment to kvm guests. This patch fixes the issue.

---
 arch/x86/kernel/amd_iommu.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/amd_iommu.c +4 -2
index 751ce73..adb0ba0 100644
@@ -1511,9 +1511,11 @@ static void __detach_device(struct device *dev)
 
 	/*
 	 * If we run in passthrough mode the device must be assigned to the
-	 * passthrough domain if it is detached from any other domain
+	 * passthrough domain if it is detached from any other domain.
+	 * Make sure we can deassign from the pt_domain itself.
 	 */
-	if (iommu_pass_through && dev_data->domain == NULL)
+	if (iommu_pass_through &&
+	    (dev_data->domain == NULL && domain != pt_domain))
 		__attach_device(dev, pt_domain);
 }
 
Signature · 1 line
1.6.6
#5 lore raw

PATCH 5/5 lib/dma-debug.c: mark file-local struct symbol static.

In reply to Joerg Roedel

From: Thiago Farina <[email protected]>

warning: symbol 'filter_fops' was not declared. Should it be static?

---
 lib/dma-debug.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/dma-debug.c +1 -1
index 7399744..e039958 100644
@@ -587,7 +587,7 @@ out_unlock:
 	return count;
 }
 
-const struct file_operations filter_fops = {
+static const struct file_operations filter_fops = {
 	.read  = filter_read,
 	.write = filter_write,
 };
Signature · 1 line
1.6.6
#6 lore raw
In reply to Joerg Roedel
Quoted 26 lines · Joerg Roedel

Hi Ingo,

The following changes since commit 92dcffb916d309aa01778bf8963a6932e4014d07:
Linus Torvalds (1):

        Linux 2.6.33-rc5

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.git iommu/fixes

Joerg Roedel (5):
x86/amd-iommu: Fix possible integer overflow
x86/amd-iommu: Fix NULL pointer dereference in __detach_device() x86/amd-iommu: Fix IOMMU-API initialization for iommu=pt x86/amd-iommu: Fix deassignment of a device from the pt_domain Merge branches 'amd-iommu/fixes' and 'dma-debug/fixes' into iommu/fixes

Thiago Farina (1):
lib/dma-debug.c: mark file-local struct symbol static.

 arch/x86/include/asm/amd_iommu_proto.h |    1 +
 arch/x86/kernel/amd_iommu.c            |   23 ++++++++++++++++-------
 arch/x86/kernel/amd_iommu_init.c       |    3 +++
 lib/dma-debug.c                        |    2 +-
 4 files changed, 21 insertions(+), 8 deletions(-)
Quoted 4 lines

The patches fix several issues with device kvm device assignement when the amd iommu driver is configured to run in passthrough mode. One patch fixes a possible integer overflow in the driver as well. The last patch in the series fixes a build warning in the dma-api debug code. Please pull.

Pulled, thanks a lot Joerg!

Ingo