All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] iommu: fix handling of attach/detach for default domains
@ 2016-02-16 14:40 Marek Szyprowski
       [not found] ` <1455633632-16873-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Szyprowski @ 2016-02-16 14:40 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw, Bartlomiej Zolnierkiewicz

Hello,

This patchset fixes attaching and detaching devices to a group, which
has default domain configured. With both patches applied all calls to
iommu's attach/detach functions will be balanced, whenever caller
attaches device to the default domain or the custom one.

Best regards
Marek Szyprowski
Samsung R&D Institute Poland


Patch summary:

Marek Szyprowski (2):
  iommu: call detach also for default_domain before attaching to new one
  iommu: fix default domain handling in __iommu_detach_group()

 drivers/iommu/iommu.c | 48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

-- 
1.9.2

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

* [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one
       [not found] ` <1455633632-16873-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
@ 2016-02-16 14:40   ` Marek Szyprowski
       [not found]     ` <1455633632-16873-2-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  2016-02-16 14:40   ` [PATCH 2/2] iommu: fix default domain handling in __iommu_detach_group() Marek Szyprowski
  1 sibling, 1 reply; 8+ messages in thread
From: Marek Szyprowski @ 2016-02-16 14:40 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw, Bartlomiej Zolnierkiewicz

This patch ensures that devices attached to the default_domain will be
first detached from it before attaching to new domain. To avoid forward
declaration, __iommu_attach_group() function has been moved to new place
in the source code.

Signed-off-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
---
 drivers/iommu/iommu.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 0e3b009..db231ad 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1198,22 +1198,6 @@ static int iommu_group_do_attach_device(struct device *dev, void *data)
 	return __iommu_attach_device(domain, dev);
 }
 
-static int __iommu_attach_group(struct iommu_domain *domain,
-				struct iommu_group *group)
-{
-	int ret;
-
-	if (group->default_domain && group->domain != group->default_domain)
-		return -EBUSY;
-
-	ret = __iommu_group_for_each_dev(group, domain,
-					 iommu_group_do_attach_device);
-	if (ret == 0)
-		group->domain = domain;
-
-	return ret;
-}
-
 int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group)
 {
 	int ret;
@@ -1235,6 +1219,28 @@ static int iommu_group_do_detach_device(struct device *dev, void *data)
 	return 0;
 }
 
+static int __iommu_attach_group(struct iommu_domain *domain,
+				struct iommu_group *group)
+{
+	int ret;
+
+	if (group->default_domain && group->domain != group->default_domain)
+		return -EBUSY;
+
+	if (group->default_domain && group->default_domain == group->domain) {
+		__iommu_group_for_each_dev(group, group->domain,
+					   iommu_group_do_detach_device);
+		group->domain = NULL;
+	}
+
+	ret = __iommu_group_for_each_dev(group, domain,
+					 iommu_group_do_attach_device);
+	if (ret == 0)
+		group->domain = domain;
+
+	return ret;
+}
+
 static void __iommu_detach_group(struct iommu_domain *domain,
 				 struct iommu_group *group)
 {
-- 
1.9.2

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

* [PATCH 2/2] iommu: fix default domain handling in __iommu_detach_group()
       [not found] ` <1455633632-16873-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  2016-02-16 14:40   ` [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one Marek Szyprowski
@ 2016-02-16 14:40   ` Marek Szyprowski
  1 sibling, 0 replies; 8+ messages in thread
From: Marek Szyprowski @ 2016-02-16 14:40 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw, Bartlomiej Zolnierkiewicz

This patch ensures that all devices will be first detached from the
provided domain and then attached to the default_domain if such has been
provided.

Signed-off-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
---
 drivers/iommu/iommu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index db231ad..045efb0 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1246,14 +1246,14 @@ static void __iommu_detach_group(struct iommu_domain *domain,
 {
 	int ret;
 
-	if (!group->default_domain) {
-		__iommu_group_for_each_dev(group, domain,
-					   iommu_group_do_detach_device);
-		group->domain = NULL;
+	if (group->domain == group->default_domain)
 		return;
-	}
 
-	if (group->domain == group->default_domain)
+	__iommu_group_for_each_dev(group, domain,
+				   iommu_group_do_detach_device);
+	group->domain = NULL;
+
+	if (!group->default_domain)
 		return;
 
 	/* Detach by re-attaching to the default domain */
-- 
1.9.2

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

* Re: [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one
       [not found]     ` <1455633632-16873-2-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
@ 2016-02-16 15:59       ` Joerg Roedel
       [not found]         ` <20160216155922.GV18805-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Joerg Roedel @ 2016-02-16 15:59 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Bartlomiej Zolnierkiewicz

On Tue, Feb 16, 2016 at 03:40:31PM +0100, Marek Szyprowski wrote:
> This patch ensures that devices attached to the default_domain will be
> first detached from it before attaching to new domain. To avoid forward
> declaration, __iommu_attach_group() function has been moved to new place
> in the source code.

Actually it was intentional to not invoke the detach_device call-back in
the attach_device path.

The reason is that detaching first and than attaching again leaves the
device without a domain for a short period of time, until it is attached
to the new domain.

The attach_device call-back is supposed to handle this situation and
just silently overwrite any other domain->device binding it finds for
the device.

This allows to do re-attachment with less iommu flushes and to get rid
of the detach_device call-back at some point.



	Joerg

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

* Re: [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one
       [not found]         ` <20160216155922.GV18805-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
@ 2016-02-17  7:35           ` Marek Szyprowski
       [not found]             ` <56C422AE.9000108-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Szyprowski @ 2016-02-17  7:35 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Bartlomiej Zolnierkiewicz

Hello,

On 2016-02-16 16:59, Joerg Roedel wrote:
> On Tue, Feb 16, 2016 at 03:40:31PM +0100, Marek Szyprowski wrote:
>> This patch ensures that devices attached to the default_domain will be
>> first detached from it before attaching to new domain. To avoid forward
>> declaration, __iommu_attach_group() function has been moved to new place
>> in the source code.
> Actually it was intentional to not invoke the detach_device call-back in
> the attach_device path.
>
> The reason is that detaching first and than attaching again leaves the
> device without a domain for a short period of time, until it is attached
> to the new domain.
>
> The attach_device call-back is supposed to handle this situation and
> just silently overwrite any other domain->device binding it finds for
> the device.
>
> This allows to do re-attachment with less iommu flushes and to get rid
> of the detach_device call-back at some point.

Huh, I wasn't aware of this change in the iommu drivers api. For some
drivers attach/detach callbacks does something more than just programming
page table base register, like for example in case of exynos iommu it is
enabling runtime power management and clocks. The code is really much 
simpler
if those calls are balanced, but if the goal is to allow multiple 
unballanced
attach calls, I will try to fix this in our driver.

Maybe it should be documented somewhere, that attach calls can be 
unbalanced?

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

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

* Re: [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one
       [not found]             ` <56C422AE.9000108-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
@ 2016-02-17 11:14               ` Joerg Roedel
       [not found]                 ` <20160217111450.GA18805-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Joerg Roedel @ 2016-02-17 11:14 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Bartlomiej Zolnierkiewicz

On Wed, Feb 17, 2016 at 08:35:10AM +0100, Marek Szyprowski wrote:
> Huh, I wasn't aware of this change in the iommu drivers api. For some
> drivers attach/detach callbacks does something more than just programming
> page table base register, like for example in case of exynos iommu it is
> enabling runtime power management and clocks. The code is really
> much simpler
> if those calls are balanced, but if the goal is to allow multiple
> unballanced
> attach calls, I will try to fix this in our driver.
> 
> Maybe it should be documented somewhere, that attach calls can be
> unbalanced?

Well, when your driver uses default-domains, the detach_dev call-back is
not used anymore. The attach_dev call-back is supposed to just overwrite
any existing binding that may exist for the device. So the calls are not
unbalanced, the detach_dev calls just don't happen anymore.



	Joerg

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

* Re: [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one
       [not found]                 ` <20160217111450.GA18805-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
@ 2016-02-17 14:42                   ` Marek Szyprowski
       [not found]                     ` <56C486EE.5020504-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Szyprowski @ 2016-02-17 14:42 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Bartlomiej Zolnierkiewicz

Hello,

On 2016-02-17 12:14, Joerg Roedel wrote:
> On Wed, Feb 17, 2016 at 08:35:10AM +0100, Marek Szyprowski wrote:
>> Huh, I wasn't aware of this change in the iommu drivers api. For some
>> drivers attach/detach callbacks does something more than just programming
>> page table base register, like for example in case of exynos iommu it is
>> enabling runtime power management and clocks. The code is really
>> much simpler
>> if those calls are balanced, but if the goal is to allow multiple
>> unballanced
>> attach calls, I will try to fix this in our driver.
>>
>> Maybe it should be documented somewhere, that attach calls can be
>> unbalanced?
> Well, when your driver uses default-domains, the detach_dev call-back is
> not used anymore. The attach_dev call-back is supposed to just overwrite
> any existing binding that may exist for the device. So the calls are not
> unbalanced, the detach_dev calls just don't happen anymore.

 From driver perspective the default_domains don't really differ from the
'other' domains. They are just allocated from the IOMMU core and used by
the IOMMU/DMA-mapping glue code. That's what I got from reading the code.

There should be also a way to detach the driver even from the default domain
to implement the arch_tear_down_dma_ops function.

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

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

* Re: [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one
       [not found]                     ` <56C486EE.5020504-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
@ 2016-02-25 14:01                       ` Joerg Roedel
  0 siblings, 0 replies; 8+ messages in thread
From: Joerg Roedel @ 2016-02-25 14:01 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: linaro-mm-sig-cunTk1MwBs8s++Sfvej+rw,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Bartlomiej Zolnierkiewicz

Hi Marek,

On Wed, Feb 17, 2016 at 03:42:54PM +0100, Marek Szyprowski wrote:
> From driver perspective the default_domains don't really differ from the
> 'other' domains. They are just allocated from the IOMMU core and used by
> the IOMMU/DMA-mapping glue code. That's what I got from reading the code.
> 
> There should be also a way to detach the driver even from the default domain
> to implement the arch_tear_down_dma_ops function.

The attaching/detaching in the iommu-core only manages software state.
The iommu-driver can power-down the iommu device when the default-domain
is attached and it does not expect any map/unmap calls.

All it has to make sure is that it wakes up the iommu device again when
or before these calls are made again.


	Joerg

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

end of thread, other threads:[~2016-02-25 14:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-16 14:40 [PATCH 0/2] iommu: fix handling of attach/detach for default domains Marek Szyprowski
     [not found] ` <1455633632-16873-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2016-02-16 14:40   ` [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one Marek Szyprowski
     [not found]     ` <1455633632-16873-2-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2016-02-16 15:59       ` Joerg Roedel
     [not found]         ` <20160216155922.GV18805-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2016-02-17  7:35           ` Marek Szyprowski
     [not found]             ` <56C422AE.9000108-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2016-02-17 11:14               ` Joerg Roedel
     [not found]                 ` <20160217111450.GA18805-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2016-02-17 14:42                   ` Marek Szyprowski
     [not found]                     ` <56C486EE.5020504-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2016-02-25 14:01                       ` Joerg Roedel
2016-02-16 14:40   ` [PATCH 2/2] iommu: fix default domain handling in __iommu_detach_group() Marek Szyprowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.