linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3.2] iommu/amd: Initialize device table after dma_ops
@ 2013-02-28 21:39 Shuah Khan
  2013-03-02 23:00 ` Ben Hutchings
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2013-02-28 21:39 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, LKML, stable, Greg KH, ben, shuahkhan

When dma_ops are initialized the unity mappings are created. The
init_device_table_dma() function makes sure DMA from all devices is
blocked by default. This opens a short window in time where DMA to
unity mapped regions is blocked by the IOMMU. Make sure this does not
happen by initializing the device table after dma_ops.

Back-port upstream commit: f528d980c17b8714aedc918ba86e058af914d66b
Tested on 3.2.38

Signed-off-by: Joerg Roedel <joro@8bytes.org>
Signed-off-by: Shuah Khan <shuah.khan@hp.com>
CC: stable@vger.kernel.org 3.2
---
 drivers/iommu/amd_iommu_init.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 62a4d5c..b7d1cdd 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1396,6 +1396,7 @@ static struct syscore_ops amd_iommu_syscore_ops = {
  */
 static int __init amd_iommu_init(void)
 {
+	struct amd_iommu *iommu;
 	int i, ret = 0;
 
 	/*
@@ -1444,9 +1445,6 @@ static int __init amd_iommu_init(void)
 	if (amd_iommu_pd_alloc_bitmap == NULL)
 		goto free;
 
-	/* init the device table */
-	init_device_table();
-
 	/*
 	 * let all alias entries point to itself
 	 */
@@ -1496,6 +1494,12 @@ static int __init amd_iommu_init(void)
 	if (ret)
 		goto free_disable;
 
+	/* init the device table */
+	init_device_table();
+
+	for_each_iommu(iommu)
+		iommu_flush_all_caches(iommu);
+
 	amd_iommu_init_api();
 
 	amd_iommu_init_notifier();
-- 
1.7.10.4




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

* Re: [PATCH 3.2] iommu/amd: Initialize device table after dma_ops
  2013-02-28 21:39 [PATCH 3.2] iommu/amd: Initialize device table after dma_ops Shuah Khan
@ 2013-03-02 23:00 ` Ben Hutchings
  2013-03-03 22:58   ` Joerg Roedel
  0 siblings, 1 reply; 4+ messages in thread
From: Ben Hutchings @ 2013-03-02 23:00 UTC (permalink / raw)
  To: shuah.khan; +Cc: Joerg Roedel, iommu, LKML, stable, Greg KH, shuahkhan

[-- Attachment #1: Type: text/plain, Size: 2032 bytes --]

On Thu, 2013-02-28 at 14:39 -0700, Shuah Khan wrote:
> When dma_ops are initialized the unity mappings are created. The
> init_device_table_dma() function makes sure DMA from all devices is
> blocked by default. This opens a short window in time where DMA to
> unity mapped regions is blocked by the IOMMU. Make sure this does not
> happen by initializing the device table after dma_ops.
> 
> Back-port upstream commit: f528d980c17b8714aedc918ba86e058af914d66b
> Tested on 3.2.38
> 
> Signed-off-by: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Shuah Khan <shuah.khan@hp.com>
> CC: stable@vger.kernel.org 3.2

I'm not convinced about this backport, because the order of
initialisation already changed a lot after 3.2 and before the upstream
commit.  So I'm going to wait for Joerg to confirm that this makes sense
before adding it to the patch queue.

Ben.

> ---
>  drivers/iommu/amd_iommu_init.c |   10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
> index 62a4d5c..b7d1cdd 100644
> --- a/drivers/iommu/amd_iommu_init.c
> +++ b/drivers/iommu/amd_iommu_init.c
> @@ -1396,6 +1396,7 @@ static struct syscore_ops amd_iommu_syscore_ops = {
>   */
>  static int __init amd_iommu_init(void)
>  {
> +	struct amd_iommu *iommu;
>  	int i, ret = 0;
>  
>  	/*
> @@ -1444,9 +1445,6 @@ static int __init amd_iommu_init(void)
>  	if (amd_iommu_pd_alloc_bitmap == NULL)
>  		goto free;
>  
> -	/* init the device table */
> -	init_device_table();
> -
>  	/*
>  	 * let all alias entries point to itself
>  	 */
> @@ -1496,6 +1494,12 @@ static int __init amd_iommu_init(void)
>  	if (ret)
>  		goto free_disable;
>  
> +	/* init the device table */
> +	init_device_table();
> +
> +	for_each_iommu(iommu)
> +		iommu_flush_all_caches(iommu);
> +
>  	amd_iommu_init_api();
>  
>  	amd_iommu_init_notifier();

-- 
Ben Hutchings
Computers are not intelligent.	They only think they are.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

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

* Re: [PATCH 3.2] iommu/amd: Initialize device table after dma_ops
  2013-03-02 23:00 ` Ben Hutchings
@ 2013-03-03 22:58   ` Joerg Roedel
  2013-03-17  3:42     ` Ben Hutchings
  0 siblings, 1 reply; 4+ messages in thread
From: Joerg Roedel @ 2013-03-03 22:58 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: shuah.khan, iommu, LKML, stable, Greg KH, shuahkhan

Hi Ben,

On Sat, Mar 02, 2013 at 11:00:35PM +0000, Ben Hutchings wrote:
> I'm not convinced about this backport, because the order of
> initialisation already changed a lot after 3.2 and before the upstream
> commit.  So I'm going to wait for Joerg to confirm that this makes sense
> before adding it to the patch queue.

The patch looks good, it fixes a race condition during amd_iommu
initialization. I'll also gave the backport a test to be sure it
doesn't break anything.

Thanks,

	Joerg



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

* Re: [PATCH 3.2] iommu/amd: Initialize device table after dma_ops
  2013-03-03 22:58   ` Joerg Roedel
@ 2013-03-17  3:42     ` Ben Hutchings
  0 siblings, 0 replies; 4+ messages in thread
From: Ben Hutchings @ 2013-03-17  3:42 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: shuah.khan, iommu, LKML, stable, Greg KH, shuahkhan

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

On Sun, 2013-03-03 at 23:58 +0100, Joerg Roedel wrote:
> Hi Ben,
> 
> On Sat, Mar 02, 2013 at 11:00:35PM +0000, Ben Hutchings wrote:
> > I'm not convinced about this backport, because the order of
> > initialisation already changed a lot after 3.2 and before the upstream
> > commit.  So I'm going to wait for Joerg to confirm that this makes sense
> > before adding it to the patch queue.
> 
> The patch looks good, it fixes a race condition during amd_iommu
> initialization. I'll also gave the backport a test to be sure it
> doesn't break anything.

Applied, thanks all.

Ben.

-- 
Ben Hutchings
Usenet is essentially a HUGE group of people passing notes in class.
                      - Rachel Kadel, `A Quick Guide to Newsgroup Etiquette'

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

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

end of thread, other threads:[~2013-03-17  3:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-28 21:39 [PATCH 3.2] iommu/amd: Initialize device table after dma_ops Shuah Khan
2013-03-02 23:00 ` Ben Hutchings
2013-03-03 22:58   ` Joerg Roedel
2013-03-17  3:42     ` Ben Hutchings

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).