All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne
@ 2026-11-20 15:23 Vasant Hegde
  2026-11-20 15:53 ` Mario Limonciello
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Vasant Hegde @ 2026-11-20 15:23 UTC (permalink / raw)
  To: iommu, joro
  Cc: will, robin.murphy, suravee.suthikulpanit, Vasant Hegde,
	Mario Limonciello, Alex Deucher, Akshata V Unkal,
	Nathan Blomquist

DMA fails on Cezanne (family 19h, model 50h) when a device is placed in
an IOMMU v2 paging domain due to missing coherency setting in IOMMU HW.
The IOMMU walks v2 page tables without observing CPU writes still held
in the cache. v1 PTEs have a Force Coherent bit, which the driver sets
on every entry, but the v2 format has no equivalent bit, so v2 walks
are not kept coherent.

Set PT_FEAT_DMA_INCOHERENT for v2 domains on this CPU so the generic
page-table code clflushes table memory before the IOMMU reads it.

Link: https://lore.kernel.org/linux-iommu/CACOV87VBwH+R3eSBEOuz8hk7OaT63+A9m6ipPSW5wt1VhHMFPg@mail.gmail.com/
Cc: Mario Limonciello (AMD) <superm1@kernel.org>
Cc: Alex Deucher <alexander.deucher@amd.com>
Tested-by: Akshata V Unkal <Akshata.VUnkal@amd.com>
Co-developed-by: Nathan Blomquist <nblomquist@gmail.com>
Signed-off-by: Nathan Blomquist <nblomquist@gmail.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
 drivers/iommu/amd/iommu.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 41ee4ad1dcf8..0f04013f590d 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2792,6 +2792,15 @@ static const struct iommu_domain_ops amdv2_ops = {
 	.enforce_cache_coherency = amd_iommu_enforce_cache_coherency,
 };
 
+/*
+ * Force a clflush on Cezanne (family 19h, model 50h) when the v2
+ * page-table is enabled.
+ */
+static bool amd_iommu_force_incoherent(void)
+{
+	return boot_cpu_data.x86 == 0x19 && boot_cpu_data.x86_model == 0x50;
+}
+
 static struct iommu_domain *amd_iommu_domain_alloc_paging_v2(struct device *dev,
 							     u32 flags)
 {
@@ -2810,6 +2819,13 @@ static struct iommu_domain *amd_iommu_domain_alloc_paging_v2(struct device *dev,
 	domain->iommu.nid = dev_to_node(dev);
 
 	cfg.common.features = BIT(PT_FEAT_X86_64_AMD_ENCRYPT_TABLES);
+
+	if (amd_iommu_force_incoherent()) {
+		cfg.common.features |= BIT(PT_FEAT_DMA_INCOHERENT);
+		/* pt_iommu_init() rejects DMA_INCOHERENT without a device */
+		domain->iommu.iommu_device = dev;
+	}
+
 	if (amd_iommu_np_cache)
 		cfg.common.features |= BIT(PT_FEAT_FLUSH_RANGE_NO_GAPS);
 	else
-- 
2.31.1


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

* Re: [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne
  2026-11-20 15:23 [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne Vasant Hegde
@ 2026-11-20 15:53 ` Mario Limonciello
  2026-11-20 16:36 ` Nathan Blomquist
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Mario Limonciello @ 2026-11-20 15:53 UTC (permalink / raw)
  To: Vasant Hegde, iommu, joro
  Cc: will, robin.murphy, suravee.suthikulpanit, Alex Deucher,
	Akshata V Unkal, Nathan Blomquist

On 11/20/26 09:23, Vasant Hegde wrote:
> DMA fails on Cezanne (family 19h, model 50h) when a device is placed in
> an IOMMU v2 paging domain due to missing coherency setting in IOMMU HW.
> The IOMMU walks v2 page tables without observing CPU writes still held
> in the cache. v1 PTEs have a Force Coherent bit, which the driver sets
> on every entry, but the v2 format has no equivalent bit, so v2 walks
> are not kept coherent.
> 
> Set PT_FEAT_DMA_INCOHERENT for v2 domains on this CPU so the generic
> page-table code clflushes table memory before the IOMMU reads it.
> 

Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/6081
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>

> Link: https://lore.kernel.org/linux-iommu/CACOV87VBwH+R3eSBEOuz8hk7OaT63+A9m6ipPSW5wt1VhHMFPg@mail.gmail.com/
> Cc: Mario Limonciello (AMD) <superm1@kernel.org>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Tested-by: Akshata V Unkal <Akshata.VUnkal@amd.com>
> Co-developed-by: Nathan Blomquist <nblomquist@gmail.com>
> Signed-off-by: Nathan Blomquist <nblomquist@gmail.com>

Much appreciated for all your help here Nathan, you did a great job 
narrowing this down.

> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
> ---
>   drivers/iommu/amd/iommu.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 41ee4ad1dcf8..0f04013f590d 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2792,6 +2792,15 @@ static const struct iommu_domain_ops amdv2_ops = {
>   	.enforce_cache_coherency = amd_iommu_enforce_cache_coherency,
>   };
>   
> +/*
> + * Force a clflush on Cezanne (family 19h, model 50h) when the v2
> + * page-table is enabled.
> + */
> +static bool amd_iommu_force_incoherent(void)
> +{
> +	return boot_cpu_data.x86 == 0x19 && boot_cpu_data.x86_model == 0x50;
> +}
> +
>   static struct iommu_domain *amd_iommu_domain_alloc_paging_v2(struct device *dev,
>   							     u32 flags)
>   {
> @@ -2810,6 +2819,13 @@ static struct iommu_domain *amd_iommu_domain_alloc_paging_v2(struct device *dev,
>   	domain->iommu.nid = dev_to_node(dev);
>   
>   	cfg.common.features = BIT(PT_FEAT_X86_64_AMD_ENCRYPT_TABLES);
> +
> +	if (amd_iommu_force_incoherent()) {
> +		cfg.common.features |= BIT(PT_FEAT_DMA_INCOHERENT);
> +		/* pt_iommu_init() rejects DMA_INCOHERENT without a device */
> +		domain->iommu.iommu_device = dev;
> +	}
> +
>   	if (amd_iommu_np_cache)
>   		cfg.common.features |= BIT(PT_FEAT_FLUSH_RANGE_NO_GAPS);
>   	else


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

* Re: [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne
  2026-11-20 15:23 [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne Vasant Hegde
  2026-11-20 15:53 ` Mario Limonciello
@ 2026-11-20 16:36 ` Nathan Blomquist
  2026-11-20 19:26 ` Jason Gunthorpe
  2026-11-23 10:35 ` Jörg Rödel
  3 siblings, 0 replies; 7+ messages in thread
From: Nathan Blomquist @ 2026-11-20 16:36 UTC (permalink / raw)
  To: Vasant Hegde
  Cc: iommu, joro, will, robin.murphy, suravee.suthikulpanit,
	Mario Limonciello, Alex Deucher, Akshata V Unkal

Hi Vasant,

I tested the posted patch on pristine v7.4-rc3 with a Ryzen 5 5600G
(Cezanne) and Radeon RX 5500 XT. On the same setup, unpatched rc3 hit
an IOMMU page fault and failed PSP initialization. With the patch, the
GPU initialized successfully. The IOMMU device table confirmed
translated v2 DMA-FQ without an amd_iommu= override.

As a simple test, I also used the RX 5500 XT to hardware-decode and
transcode the full 1080p60 Big Buck Bunny movie from H.264 to HEVC,
then hardware-decoded all frames of the output. No IOMMU faults, GPU
resets, or DMA-API errors were observed.

Tested-by: Nathan Blomquist <nblomquist@gmail.com>

Thanks,
Nathan


On Fri, 20 Nov 2026 15:23:08 +0000, Vasant Hegde <vasant.hegde@amd.com> wrote:
> DMA fails on Cezanne (family 19h, model 50h) when a device is placed in
> an IOMMU v2 paging domain due to missing coherency setting in IOMMU HW.
> The IOMMU walks v2 page tables without observing CPU writes still held
> in the cache. v1 PTEs have a Force Coherent bit, which the driver sets
> on every entry, but the v2 format has no equivalent bit, so v2 walks
> are not kept coherent.
>
> Set PT_FEAT_DMA_INCOHERENT for v2 domains on this CPU so the generic
> page-table code clflushes table memory before the IOMMU reads it.
>
> Link: https://lore.kernel.org/linux-iommu/CACOV87VBwH+R3eSBEOuz8hk7OaT63+A9m6ipPSW5wt1VhHMFPg@mail.gmail.com/
> Cc: Mario Limonciello (AMD) <superm1@kernel.org>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Tested-by: Akshata V Unkal <Akshata.VUnkal@amd.com>
> Co-developed-by: Nathan Blomquist <nblomquist@gmail.com>
> Signed-off-by: Nathan Blomquist <nblomquist@gmail.com>
> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
> ---
>  drivers/iommu/amd/iommu.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 41ee4ad1dcf8..0f04013f590d 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2792,6 +2792,15 @@ static const struct iommu_domain_ops amdv2_ops = {
>       .enforce_cache_coherency = amd_iommu_enforce_cache_coherency,
>  };
>
> +/*
> + * Force a clflush on Cezanne (family 19h, model 50h) when the v2
> + * page-table is enabled.
> + */
> +static bool amd_iommu_force_incoherent(void)
> +{
> +     return boot_cpu_data.x86 == 0x19 && boot_cpu_data.x86_model == 0x50;
> +}
> +
>  static struct iommu_domain *amd_iommu_domain_alloc_paging_v2(struct device *dev,
>                                                            u32 flags)
>  {
> @@ -2810,6 +2819,13 @@ static struct iommu_domain *amd_iommu_domain_alloc_paging_v2(struct device *dev,
>       domain->iommu.nid = dev_to_node(dev);
>
>       cfg.common.features = BIT(PT_FEAT_X86_64_AMD_ENCRYPT_TABLES);
> +
> +     if (amd_iommu_force_incoherent()) {
> +             cfg.common.features |= BIT(PT_FEAT_DMA_INCOHERENT);
> +             /* pt_iommu_init() rejects DMA_INCOHERENT without a device */
> +             domain->iommu.iommu_device = dev;
> +     }
> +
>       if (amd_iommu_np_cache)
>               cfg.common.features |= BIT(PT_FEAT_FLUSH_RANGE_NO_GAPS);
>       else
> --
> 2.31.1

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

* Re: [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne
  2026-11-20 15:23 [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne Vasant Hegde
  2026-11-20 15:53 ` Mario Limonciello
  2026-11-20 16:36 ` Nathan Blomquist
@ 2026-11-20 19:26 ` Jason Gunthorpe
  2026-11-23 11:24   ` Vasant Hegde
  2026-11-23 10:35 ` Jörg Rödel
  3 siblings, 1 reply; 7+ messages in thread
From: Jason Gunthorpe @ 2026-11-20 19:26 UTC (permalink / raw)
  To: Vasant Hegde
  Cc: iommu, joro, will, robin.murphy, suravee.suthikulpanit,
	Mario Limonciello, Alex Deucher, Akshata V Unkal,
	Nathan Blomquist

On Fri, Nov 20, 2026 at 03:23:08PM +0000, Vasant Hegde wrote:
> DMA fails on Cezanne (family 19h, model 50h) when a device is placed in
> an IOMMU v2 paging domain due to missing coherency setting in IOMMU HW.
> The IOMMU walks v2 page tables without observing CPU writes still held
> in the cache. v1 PTEs have a Force Coherent bit, which the driver sets
> on every entry, but the v2 format has no equivalent bit, so v2 walks
> are not kept coherent.

That seems like an enormous obvious hardware bug? I'm shocked it was
released like that..

Is anything else non-coherent by accident?

> +/*
> + * Force a clflush on Cezanne (family 19h, model 50h) when the v2
> + * page-table is enabled.
> + */

No errata #?

It seems OK to me otherwise

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason

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

* Re: [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne
  2026-11-20 15:23 [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne Vasant Hegde
                   ` (2 preceding siblings ...)
  2026-11-20 19:26 ` Jason Gunthorpe
@ 2026-11-23 10:35 ` Jörg Rödel
  3 siblings, 0 replies; 7+ messages in thread
From: Jörg Rödel @ 2026-11-23 10:35 UTC (permalink / raw)
  To: Vasant Hegde
  Cc: iommu, will, robin.murphy, suravee.suthikulpanit,
	Mario Limonciello, Alex Deucher, Akshata V Unkal,
	Nathan Blomquist

On Fri, Nov 20, 2026 at 03:23:08PM +0000, Vasant Hegde wrote:
>  drivers/iommu/amd/iommu.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

Applied, thanks.

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

* Re: [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne
  2026-11-20 19:26 ` Jason Gunthorpe
@ 2026-11-23 11:24   ` Vasant Hegde
  2026-11-23 15:02     ` Jason Gunthorpe
  0 siblings, 1 reply; 7+ messages in thread
From: Vasant Hegde @ 2026-11-23 11:24 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: iommu, joro, will, robin.murphy, suravee.suthikulpanit,
	Mario Limonciello, Alex Deucher, Akshata V Unkal,
	Nathan Blomquist



On 11/21/2026 12:56 AM, Jason Gunthorpe wrote:
> On Fri, Nov 20, 2026 at 03:23:08PM +0000, Vasant Hegde wrote:
>> DMA fails on Cezanne (family 19h, model 50h) when a device is placed in
>> an IOMMU v2 paging domain due to missing coherency setting in IOMMU HW.
>> The IOMMU walks v2 page tables without observing CPU writes still held
>> in the cache. v1 PTEs have a Force Coherent bit, which the driver sets
>> on every entry, but the v2 format has no equivalent bit, so v2 walks
>> are not kept coherent.
> 
> That seems like an enormous obvious hardware bug? I'm shocked it was
> released like that..

I believe this is missing BIOS programming.

> 
> Is anything else non-coherent by accident?

We ran tests on as many variants we could get it. As we know this is the only
platform hit this bug.

-Vasant


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

* Re: [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne
  2026-11-23 11:24   ` Vasant Hegde
@ 2026-11-23 15:02     ` Jason Gunthorpe
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Gunthorpe @ 2026-11-23 15:02 UTC (permalink / raw)
  To: Vasant Hegde
  Cc: iommu, joro, will, robin.murphy, suravee.suthikulpanit,
	Mario Limonciello, Alex Deucher, Akshata V Unkal,
	Nathan Blomquist

On Mon, Nov 23, 2026 at 04:54:39PM +0530, Vasant Hegde wrote:
> 
> 
> On 11/21/2026 12:56 AM, Jason Gunthorpe wrote:
> > On Fri, Nov 20, 2026 at 03:23:08PM +0000, Vasant Hegde wrote:
> >> DMA fails on Cezanne (family 19h, model 50h) when a device is placed in
> >> an IOMMU v2 paging domain due to missing coherency setting in IOMMU HW.
> >> The IOMMU walks v2 page tables without observing CPU writes still held
> >> in the cache. v1 PTEs have a Force Coherent bit, which the driver sets
> >> on every entry, but the v2 format has no equivalent bit, so v2 walks
> >> are not kept coherent.
> > 
> > That seems like an enormous obvious hardware bug? I'm shocked it was
> > released like that..
> 
> I believe this is missing BIOS programming.

So a BIOS upgrade fixes it? Seems rough to patch the kernel based on
sillicon ID then.

Because you also have to block viommu if the S2 is non-coherent, this
patch should be updated.

And that's a big impact for a BIOS bug that will be fixed for some
people...

Jason

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

end of thread, other threads:[~2026-11-23 15:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 15:23 [PATCH] iommu/amd: Mark v2 page tables incoherent on Cezanne Vasant Hegde
2026-11-20 15:53 ` Mario Limonciello
2026-11-20 16:36 ` Nathan Blomquist
2026-11-20 19:26 ` Jason Gunthorpe
2026-11-23 11:24   ` Vasant Hegde
2026-11-23 15:02     ` Jason Gunthorpe
2026-11-23 10:35 ` Jörg Rödel

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.