All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Apply workaround for ATS write permission check
@ 2016-02-10 21:48 ` Jay Cornwall
  0 siblings, 0 replies; 4+ messages in thread
From: Jay Cornwall @ 2016-02-10 21:48 UTC (permalink / raw)
  To: iommu; +Cc: Joerg Roedel, Jay Cornwall, stable

The AMD Family 15h Models 30h-3Fh (Kaveri) BIOS and Kernel Developer's
Guide omitted part of the BIOS IOMMU L2 register setup specification.
Without this setup the IOMMU L2 does not fully respect write permissions
when handling an ATS translation request.

The IOMMU L2 will set PTE dirty bit when handling an ATS translation with
write permission request, even when PTE RW bit is clear. This may occur by
direct translation (which would cause a PPR) or by prefetch request from
the ATC.

This is observed in practice when the IOMMU L2 modifies a PTE which maps a
pagecache page. The ext4 filesystem driver BUGs when asked to writeback
these (non-modified) pages.

Enable ATS write permission check in the Kaveri IOMMU L2 if BIOS has not.

Signed-off-by: Jay Cornwall <jay@jcornwall.me>
Cc: <stable@vger.kernel.org> # v3.19+
---
 drivers/iommu/amd_iommu_init.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 013bdff..0c4257e 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1016,6 +1016,34 @@ static void amd_iommu_erratum_746_workaround(struct amd_iommu *iommu)
 }
 
 /*
+ * Family15h Model 30h-3fh (IOMMU Mishandles ATS Write Permission)
+ * Workaround:
+ *     BIOS should enable ATS write permission check by setting
+ *     L2_DEBUG_3[AtsIgnoreIWDis](D0F2xF4_x47[0]) = 1b
+ */
+static void amd_iommu_ats_write_check_workaround(struct amd_iommu *iommu)
+{
+	u32 value;
+
+	if ((boot_cpu_data.x86 != 0x15) ||
+	    (boot_cpu_data.x86_model < 0x30) ||
+	    (boot_cpu_data.x86_model > 0x3f))
+		return;
+
+	/* Test L2_DEBUG_3[AtsIgnoreIWDis] == 1 */
+	value = iommu_read_l2(iommu, 0x47);
+
+	if (value & BIT(0))
+		return;
+
+	/* Set L2_DEBUG_3[AtsIgnoreIWDis] = 1 */
+	iommu_write_l2(iommu, 0x47, value | BIT(0));
+
+	pr_info("AMD-Vi: Applying ATS write check workaround for IOMMU at %s\n",
+		dev_name(&iommu->dev->dev));
+}
+
+/*
  * This function clues the initialization function for one IOMMU
  * together and also allocates the command buffer and programs the
  * hardware. It does NOT enable the IOMMU. This is done afterwards.
@@ -1284,6 +1312,7 @@ static int iommu_init_pci(struct amd_iommu *iommu)
 	}
 
 	amd_iommu_erratum_746_workaround(iommu);
+	amd_iommu_ats_write_check_workaround(iommu);
 
 	iommu->iommu_dev = iommu_device_create(&iommu->dev->dev, iommu,
 					       amd_iommu_groups, "ivhd%d",
-- 
1.9.1


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

* [PATCH] iommu/amd: Apply workaround for ATS write permission check
@ 2016-02-10 21:48 ` Jay Cornwall
  0 siblings, 0 replies; 4+ messages in thread
From: Jay Cornwall @ 2016-02-10 21:48 UTC (permalink / raw)
  To: iommu; +Cc: Joerg Roedel, Jay Cornwall, stable

The AMD Family 15h Models 30h-3Fh (Kaveri) BIOS and Kernel Developer's
Guide omitted part of the BIOS IOMMU L2 register setup specification.
Without this setup the IOMMU L2 does not fully respect write permissions
when handling an ATS translation request.

The IOMMU L2 will set PTE dirty bit when handling an ATS translation with
write permission request, even when PTE RW bit is clear. This may occur by
direct translation (which would cause a PPR) or by prefetch request from
the ATC.

This is observed in practice when the IOMMU L2 modifies a PTE which maps a
pagecache page. The ext4 filesystem driver BUGs when asked to writeback
these (non-modified) pages.

Enable ATS write permission check in the Kaveri IOMMU L2 if BIOS has not.

Signed-off-by: Jay Cornwall <jay@jcornwall.me>
Cc: <stable@vger.kernel.org> # v3.19+
---
 drivers/iommu/amd_iommu_init.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 013bdff..0c4257e 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1016,6 +1016,34 @@ static void amd_iommu_erratum_746_workaround(struct amd_iommu *iommu)
 }
 
 /*
+ * Family15h Model 30h-3fh (IOMMU Mishandles ATS Write Permission)
+ * Workaround:
+ *     BIOS should enable ATS write permission check by setting
+ *     L2_DEBUG_3[AtsIgnoreIWDis](D0F2xF4_x47[0]) = 1b
+ */
+static void amd_iommu_ats_write_check_workaround(struct amd_iommu *iommu)
+{
+	u32 value;
+
+	if ((boot_cpu_data.x86 != 0x15) ||
+	    (boot_cpu_data.x86_model < 0x30) ||
+	    (boot_cpu_data.x86_model > 0x3f))
+		return;
+
+	/* Test L2_DEBUG_3[AtsIgnoreIWDis] == 1 */
+	value = iommu_read_l2(iommu, 0x47);
+
+	if (value & BIT(0))
+		return;
+
+	/* Set L2_DEBUG_3[AtsIgnoreIWDis] = 1 */
+	iommu_write_l2(iommu, 0x47, value | BIT(0));
+
+	pr_info("AMD-Vi: Applying ATS write check workaround for IOMMU at %s\n",
+		dev_name(&iommu->dev->dev));
+}
+
+/*
  * This function clues the initialization function for one IOMMU
  * together and also allocates the command buffer and programs the
  * hardware. It does NOT enable the IOMMU. This is done afterwards.
@@ -1284,6 +1312,7 @@ static int iommu_init_pci(struct amd_iommu *iommu)
 	}
 
 	amd_iommu_erratum_746_workaround(iommu);
+	amd_iommu_ats_write_check_workaround(iommu);
 
 	iommu->iommu_dev = iommu_device_create(&iommu->dev->dev, iommu,
 					       amd_iommu_groups, "ivhd%d",
-- 
1.9.1

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

* Re: [PATCH] iommu/amd: Apply workaround for ATS write permission check
@ 2016-02-25 15:07   ` Joerg Roedel
  0 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2016-02-25 15:07 UTC (permalink / raw)
  To: Jay Cornwall; +Cc: iommu, stable

On Wed, Feb 10, 2016 at 03:48:01PM -0600, Jay Cornwall wrote:
> The AMD Family 15h Models 30h-3Fh (Kaveri) BIOS and Kernel Developer's
> Guide omitted part of the BIOS IOMMU L2 register setup specification.
> Without this setup the IOMMU L2 does not fully respect write permissions
> when handling an ATS translation request.
> 
> The IOMMU L2 will set PTE dirty bit when handling an ATS translation with
> write permission request, even when PTE RW bit is clear. This may occur by
> direct translation (which would cause a PPR) or by prefetch request from
> the ATC.
> 
> This is observed in practice when the IOMMU L2 modifies a PTE which maps a
> pagecache page. The ext4 filesystem driver BUGs when asked to writeback
> these (non-modified) pages.
> 
> Enable ATS write permission check in the Kaveri IOMMU L2 if BIOS has not.
> 
> Signed-off-by: Jay Cornwall <jay@jcornwall.me>
> Cc: <stable@vger.kernel.org> # v3.19+
> ---
>  drivers/iommu/amd_iommu_init.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)

Applied, thanks.


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

* Re: [PATCH] iommu/amd: Apply workaround for ATS write permission check
@ 2016-02-25 15:07   ` Joerg Roedel
  0 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2016-02-25 15:07 UTC (permalink / raw)
  To: Jay Cornwall
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	stable-u79uwXL29TY76Z2rM5mHXA

On Wed, Feb 10, 2016 at 03:48:01PM -0600, Jay Cornwall wrote:
> The AMD Family 15h Models 30h-3Fh (Kaveri) BIOS and Kernel Developer's
> Guide omitted part of the BIOS IOMMU L2 register setup specification.
> Without this setup the IOMMU L2 does not fully respect write permissions
> when handling an ATS translation request.
> 
> The IOMMU L2 will set PTE dirty bit when handling an ATS translation with
> write permission request, even when PTE RW bit is clear. This may occur by
> direct translation (which would cause a PPR) or by prefetch request from
> the ATC.
> 
> This is observed in practice when the IOMMU L2 modifies a PTE which maps a
> pagecache page. The ext4 filesystem driver BUGs when asked to writeback
> these (non-modified) pages.
> 
> Enable ATS write permission check in the Kaveri IOMMU L2 if BIOS has not.
> 
> Signed-off-by: Jay Cornwall <jay-gJmSnxjMpeIFV7jr3Ov9Ew@public.gmane.org>
> Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> # v3.19+
> ---
>  drivers/iommu/amd_iommu_init.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)

Applied, thanks.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-10 21:48 [PATCH] iommu/amd: Apply workaround for ATS write permission check Jay Cornwall
2016-02-10 21:48 ` Jay Cornwall
2016-02-25 15:07 ` Joerg Roedel
2016-02-25 15:07   ` Joerg Roedel

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.