mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] IOMMU Fixes
@ 2014-08-18 22:49 Joerg Roedel
  2014-08-18 22:49 ` [PATCH 1/3] iommu/vt-d: Defer domain removal if device is assigned to a driver Joerg Roedel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Joerg Roedel @ 2014-08-18 22:49 UTC (permalink / raw)
  To: iommu, linux-kernel; +Cc: joro

Hi,

here are a few fixes for the x86 iommu drivers and a small
one for the iommu core-code I plan to send for -rc2.


	Joerg

Joerg Roedel (3):
  iommu/vt-d: Defer domain removal if device is assigned to a driver
  iommu/amd: Fix cleanup_domain for mass device removal
  iommu/core: Check for the right function pointer in iommu_map()

 drivers/iommu/amd_iommu.c   | 10 ++++++----
 drivers/iommu/intel-iommu.c |  8 ++++++++
 drivers/iommu/iommu.c       |  2 +-
 3 files changed, 15 insertions(+), 5 deletions(-)

-- 
1.9.1


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

* [PATCH 1/3] iommu/vt-d: Defer domain removal if device is assigned to a driver
  2014-08-18 22:49 [PATCH 0/3] IOMMU Fixes Joerg Roedel
@ 2014-08-18 22:49 ` Joerg Roedel
  2014-08-18 22:49 ` [PATCH 2/3] iommu/amd: Fix cleanup_domain for mass device removal Joerg Roedel
  2014-08-18 22:49 ` [PATCH 3/3] iommu/core: Check for the right function pointer in iommu_map() Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2014-08-18 22:49 UTC (permalink / raw)
  To: iommu, linux-kernel
  Cc: joro, Joerg Roedel, Jiang Liu, David Woodhouse, stable

From: Joerg Roedel <jroedel@suse.de>

When the BUS_NOTIFY_DEL_DEVICE event is received the device
might still be attached to a driver. In this case the domain
can't be released as the mappings might still be in use.

Defer the domain removal in this case until we receivce the
BUS_NOTIFY_UNBOUND_DRIVER event.

Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: stable@vger.kernel.org   # v3.15, v3.16
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/intel-iommu.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index d1f5caa..5619f26 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -3869,6 +3869,14 @@ static int device_notifier(struct notifier_block *nb,
 	    action != BUS_NOTIFY_DEL_DEVICE)
 		return 0;
 
+	/*
+	 * If the device is still attached to a device driver we can't
+	 * tear down the domain yet as DMA mappings may still be in use.
+	 * Wait for the BUS_NOTIFY_UNBOUND_DRIVER event to do that.
+	 */
+	if (action == BUS_NOTIFY_DEL_DEVICE && dev->driver != NULL)
+		return 0;
+
 	domain = find_domain(dev);
 	if (!domain)
 		return 0;
-- 
1.9.1


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

* [PATCH 2/3] iommu/amd: Fix cleanup_domain for mass device removal
  2014-08-18 22:49 [PATCH 0/3] IOMMU Fixes Joerg Roedel
  2014-08-18 22:49 ` [PATCH 1/3] iommu/vt-d: Defer domain removal if device is assigned to a driver Joerg Roedel
@ 2014-08-18 22:49 ` Joerg Roedel
  2014-08-18 22:49 ` [PATCH 3/3] iommu/core: Check for the right function pointer in iommu_map() Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2014-08-18 22:49 UTC (permalink / raw)
  To: iommu, linux-kernel; +Cc: joro, Joerg Roedel, stable

From: Joerg Roedel <jroedel@suse.de>

When multiple devices are detached in __detach_device, they
are also removed from the domains dev_list. This makes it
unsafe to use list_for_each_entry_safe, as the next pointer
might also not be in the list anymore after __detach_device
returns. So just repeatedly remove the first element of the
list until it is empty.

Cc: stable@vger.kernel.org
Tested-by: Marti Raudsepp <marti@juffo.org>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/amd_iommu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 1840531..ecb0109 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3149,14 +3149,16 @@ free_domains:
 
 static void cleanup_domain(struct protection_domain *domain)
 {
-	struct iommu_dev_data *dev_data, *next;
+	struct iommu_dev_data *entry;
 	unsigned long flags;
 
 	write_lock_irqsave(&amd_iommu_devtable_lock, flags);
 
-	list_for_each_entry_safe(dev_data, next, &domain->dev_list, list) {
-		__detach_device(dev_data);
-		atomic_set(&dev_data->bind, 0);
+	while (!list_empty(&domain->dev_list)) {
+		entry = list_first_entry(&domain->dev_list,
+					 struct iommu_dev_data, list);
+		__detach_device(entry);
+		atomic_set(&entry->bind, 0);
 	}
 
 	write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
-- 
1.9.1


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

* [PATCH 3/3] iommu/core: Check for the right function pointer in iommu_map()
  2014-08-18 22:49 [PATCH 0/3] IOMMU Fixes Joerg Roedel
  2014-08-18 22:49 ` [PATCH 1/3] iommu/vt-d: Defer domain removal if device is assigned to a driver Joerg Roedel
  2014-08-18 22:49 ` [PATCH 2/3] iommu/amd: Fix cleanup_domain for mass device removal Joerg Roedel
@ 2014-08-18 22:49 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2014-08-18 22:49 UTC (permalink / raw)
  To: iommu, linux-kernel; +Cc: joro, Joerg Roedel

From: Joerg Roedel <jroedel@suse.de>

Check for the ->map and not the ->unmap pointer.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 1698360..ac4adb3 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -995,7 +995,7 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
 	size_t orig_size = size;
 	int ret = 0;
 
-	if (unlikely(domain->ops->unmap == NULL ||
+	if (unlikely(domain->ops->map == NULL ||
 		     domain->ops->pgsize_bitmap == 0UL))
 		return -ENODEV;
 
-- 
1.9.1


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

end of thread, other threads:[~2014-08-18 22:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-18 22:49 [PATCH 0/3] IOMMU Fixes Joerg Roedel
2014-08-18 22:49 ` [PATCH 1/3] iommu/vt-d: Defer domain removal if device is assigned to a driver Joerg Roedel
2014-08-18 22:49 ` [PATCH 2/3] iommu/amd: Fix cleanup_domain for mass device removal Joerg Roedel
2014-08-18 22:49 ` [PATCH 3/3] iommu/core: Check for the right function pointer in iommu_map() Joerg Roedel

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

Powered by JetHome