2009-06-09 13:58:26

by Joerg Roedel

[permalink] [raw]
Subject: [git pull][PATCH 0/4] amd-iommu fixes for tip/core/iommu

Hi Ingo,

The following changes since commit 62a6f465f6572e1f28765c583c12753bb3e23715:
Ingo Molnar (1):
Merge branch 'dma-debug/2.6.31' of git://git.kernel.org/.../joro/linux-2.6-iommu into core/iommu

are available in the git repository at:

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

Jiri Slaby (1):
amd_iommu: fix lock imbalance

Joerg Roedel (4):
Merge commit 'tip/core/iommu' into amd-iommu/fixes
amd-iommu: remove BUS_NOTIFY_BOUND_DRIVER handling
amd-iommu: detach device explicitly before attaching it to a new domain
amd-iommu: remove unnecessary "AMD IOMMU: " prefix

arch/x86/kernel/amd_iommu.c | 22 ++++++----------------
1 files changed, 6 insertions(+), 16 deletions(-)

These patches fix issues with device assignment to KVM, a possible
deadlock due to an unreleased lock and a minor printk style issue.
Please pull.

Thanks,

Joerg


2009-06-09 13:57:51

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 1/4] amd_iommu: fix lock imbalance

From: Jiri Slaby <[email protected]>

In alloc_coherent there is an omitted unlock on the path where mapping
fails. Add the unlock.

[ Impact: fix lock imbalance in alloc_coherent ]

Signed-off-by: Jiri Slaby <[email protected]>
Cc: Joerg Roedel <[email protected]>
Signed-off-by: Joerg Roedel <[email protected]>
---
arch/x86/kernel/amd_iommu.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index d689883..9f89bb6 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -1541,8 +1541,10 @@ static void *alloc_coherent(struct device *dev, size_t size,
*dma_addr = __map_single(dev, iommu, domain->priv, paddr,
size, DMA_BIDIRECTIONAL, true, dma_mask);

- if (*dma_addr == bad_dma_address)
+ if (*dma_addr == bad_dma_address) {
+ spin_unlock_irqrestore(&domain->lock, flags);
goto out_free;
+ }

iommu_completion_wait(iommu);

--
1.6.3.1

2009-06-09 13:58:06

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 3/4] amd-iommu: detach device explicitly before attaching it to a new domain

This fixes a bug with a device that could not be assigned to a KVM guest
because it is still assigned to a dma_ops protection domain.

[chrisw: simply remove WARN_ON(), will always fire since dev->driver
will be pci-sub]

Signed-off-by: Chris Wright <[email protected]>
Signed-off-by: Joerg Roedel <[email protected]>
---
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 8187260..772e910 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -2073,7 +2073,7 @@ static int amd_iommu_attach_device(struct iommu_domain *dom,

old_domain = domain_for_device(devid);
if (old_domain)
- return -EBUSY;
+ detach_device(old_domain, devid);

attach_device(iommu, domain, devid);

--
1.6.3.1

2009-06-09 13:58:38

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 2/4] amd-iommu: remove BUS_NOTIFY_BOUND_DRIVER handling

Handling this event causes device assignment in KVM to fail because the
device gets re-attached as soon as the pci-stub registers as the driver
for the device.

Signed-off-by: Joerg Roedel <[email protected]>
---
arch/x86/kernel/amd_iommu.c | 11 -----------
1 files changed, 0 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 8510e90..8187260 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -1145,17 +1145,6 @@ static int device_change_notifier(struct notifier_block *nb,
"to a non-dma-ops domain\n", dev_name(dev));

switch (action) {
- case BUS_NOTIFY_BOUND_DRIVER:
- if (domain)
- goto out;
- dma_domain = find_protection_domain(devid);
- if (!dma_domain)
- dma_domain = iommu->default_dom;
- attach_device(iommu, &dma_domain->domain, devid);
- DUMP_printk(KERN_INFO "AMD IOMMU: Using protection domain "
- "%d for device %s\n",
- dma_domain->domain.id, dev_name(dev));
- break;
case BUS_NOTIFY_UNBOUND_DRIVER:
if (!domain)
goto out;
--
1.6.3.1

2009-06-09 13:58:48

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 4/4] amd-iommu: remove unnecessary "AMD IOMMU: " prefix

That prefix is already included in the DUMP_printk macro. So there is no
need to repeat it in the format string.

Signed-off-by: Joerg Roedel <[email protected]>
---
arch/x86/kernel/amd_iommu.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 772e910..1c60554 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -1266,9 +1266,8 @@ static int get_device_resources(struct device *dev,
dma_dom = (*iommu)->default_dom;
*domain = &dma_dom->domain;
attach_device(*iommu, *domain, *bdf);
- DUMP_printk(KERN_INFO "AMD IOMMU: Using protection domain "
- "%d for device %s\n",
- (*domain)->id, dev_name(dev));
+ DUMP_printk("Using protection domain %d for device %s\n",
+ (*domain)->id, dev_name(dev));
}

if (domain_for_device(_bdf) == NULL)
--
1.6.3.1

2009-06-09 14:16:22

by Chris Wright

[permalink] [raw]
Subject: Re: [PATCH 2/4] amd-iommu: remove BUS_NOTIFY_BOUND_DRIVER handling

* Joerg Roedel ([email protected]) wrote:
> Handling this event causes device assignment in KVM to fail because the
> device gets re-attached as soon as the pci-stub registers as the driver
> for the device.
>
> Signed-off-by: Joerg Roedel <[email protected]>

Yep, makes good sense, will get picked up from get_device_resources.

Acked-by: Chris Wright <[email protected]>

thanks,
-chris

2009-06-09 14:21:27

by Ingo Molnar

[permalink] [raw]
Subject: Re: [git pull][PATCH 0/4] amd-iommu fixes for tip/core/iommu


* Joerg Roedel <[email protected]> wrote:

> Hi Ingo,
>
> The following changes since commit 62a6f465f6572e1f28765c583c12753bb3e23715:
> Ingo Molnar (1):
> Merge branch 'dma-debug/2.6.31' of git://git.kernel.org/.../joro/linux-2.6-iommu into core/iommu
>
> are available in the git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.git amd-iommu/fixes
>
> Jiri Slaby (1):
> amd_iommu: fix lock imbalance
>
> Joerg Roedel (4):
> Merge commit 'tip/core/iommu' into amd-iommu/fixes
> amd-iommu: remove BUS_NOTIFY_BOUND_DRIVER handling
> amd-iommu: detach device explicitly before attaching it to a new domain
> amd-iommu: remove unnecessary "AMD IOMMU: " prefix
>
> arch/x86/kernel/amd_iommu.c | 22 ++++++----------------
> 1 files changed, 6 insertions(+), 16 deletions(-)
>
> These patches fix issues with device assignment to KVM, a possible
> deadlock due to an unreleased lock and a minor printk style issue.
> Please pull.

Pulled into tip:core/iommu, thanks a lot Joerg!

Ingo