* [PATCH v2] iommu/amd: Force identity mode for selected GPUs only
@ 2026-08-24 8:58 Vasant Hegde
2026-08-24 9:09 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Vasant Hegde @ 2026-08-24 8:58 UTC (permalink / raw)
To: iommu, joro, linux-pci
Cc: will, robin.murphy, suravee.suthikulpanit, bhelgaas,
alexander.deucher, mario.limonciello, felix.kuehling, jgg,
Vasant Hegde
Certain AMD GPUs must always operate in IOMMU identity mode. This was
previously enforced using a PASID check, which happened to work because
these specific GPUs are PASID-capable. However, this approach incorrectly
applies identity mode enforcement to all PASID-capable devices, not just
the GPUs that require it.
This made sense in the past because the domain allocation API
(iommu_ops->domain_alloc()) only received the domain type, so the
driver had no way to inspect device capabilities and pick the most
suitable page table format (v1 or v2). With the recent driver
enhancement to use domain_alloc_paging_flags() for all paging
domain allocations, the driver can now inspect the device and flags
directly and choose the appropriate page table type per device.
Update amd_iommu_def_domain_type() to force identity mapping only for
the specific GPUs that require it, via a new quirks_force_identity_mapping().
With this change, a system booting in DMA translation mode will now
select:
* Guest (v2) page table for PASID-capable devices
* Host (v1) page table for non-PASID-capable devices
Also drop the amd_iommu_snp_en check, as SNP enforces paging domain,
which doesn't work with the identity requirement of these GPUs.
Link: https://lore.kernel.org/all/20200824105415.21000-1-joro@8bytes.org/
Link: https://lore.kernel.org/linux-iommu/20260723061548.10187-1-vasant.hegde@amd.com/
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
Changes in v2:
- Dropped disabling ATS for "Radeon Pro WX 4100"
- Addressed review comments
@Jason,
Once this patch settles, I will send separate patch to drop
'untrusted' check inside amd_iommu_def_domain_type().
Regarding SME check, I have retained SME chek inside
quirks_force_identity_mapping(). If everyone is fine to drop then I
will do follow up patch later.
-Vasant
drivers/iommu/amd/iommu.c | 45 +++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 11 deletions(-)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 29dc18d3d22e..fc7819f57521 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3122,6 +3122,26 @@ static bool amd_iommu_is_attach_deferred(struct device *dev)
return dev_data->defer_attach;
}
+static bool quirks_force_identity_mapping(struct pci_dev *pdev)
+{
+ int class = pdev->class >> 8;
+
+ /* AMD GPU vendor ID */
+ if (pdev->vendor != PCI_VENDOR_ID_ATI)
+ return false;
+
+ /* GPU class */
+ if (class != PCI_CLASS_DISPLAY_VGA &&
+ class != PCI_CLASS_DISPLAY_OTHER)
+ return false;
+
+ if (pci_upstream_bridge(pdev)->vendor == PCI_VENDOR_ID_ATI)
+ return false;
+
+ /* It is the GPU in an APU, force identity domain */
+ return true;
+}
+
static int amd_iommu_def_domain_type(struct device *dev)
{
struct iommu_dev_data *dev_data;
@@ -3130,20 +3150,23 @@ static int amd_iommu_def_domain_type(struct device *dev)
if (!dev_data)
return 0;
+ if (!dev_is_pci(dev))
+ return 0;
+
/* Always use DMA domain for untrusted device */
- if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted)
+ if (to_pci_dev(dev)->untrusted)
return IOMMU_DOMAIN_DMA;
- /*
- * Do not identity map IOMMUv2 capable devices when:
- * - memory encryption is active, because some of those devices
- * (AMD GPUs) don't have the encryption bit in their DMA-mask
- * and require remapping.
- * - SNP is enabled, because it prohibits DTE[Mode]=0.
- */
- if (pdev_pasid_supported(dev_data) &&
- !cc_platform_has(CC_ATTR_MEM_ENCRYPT) &&
- !amd_iommu_snp_en) {
+ /* Apply device specific quirks */
+ if (quirks_force_identity_mapping(to_pci_dev(dev))) {
+ /*
+ * When memory encryption is active, some of these devices
+ * don't have the encryption bit in their DMA-mask and
+ * require remapping.
+ */
+ if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
+ return 0;
+
return IOMMU_DOMAIN_IDENTITY;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] iommu/amd: Force identity mode for selected GPUs only
2026-08-24 8:58 [PATCH v2] iommu/amd: Force identity mode for selected GPUs only Vasant Hegde
@ 2026-08-24 9:09 ` sashiko-bot
2026-08-24 13:18 ` Mario Limonciello
2026-08-24 13:24 ` Jason Gunthorpe
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-08-24 9:09 UTC (permalink / raw)
To: Vasant Hegde; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Missing NULL pointer check for `pci_upstream_bridge()` causes a kernel panic during boot on systems where the GPU is on the root bus.
- [High] The heuristic used to distinguish discrete GPUs (dGPUs) from APU GPUs is flawed and will incorrectly force identity mapping on many dGPUs.
- [High] Discrete GPUs break on SNP-enabled systems due to the removal of the SNP check combined with flawed GPU identification.
--
--- Patch [1]: [PATCH v2] iommu/amd: Force identity mode for selected GPUs only ---
commit 8994b69ea108b9e83363d3bf65d86e8798e45ba5
Author: Vasant Hegde <vasant.hegde@amd.com>
iommu/amd: Force identity mode for selected GPUs only
This commit updates AMD IOMMU domain allocation to force identity mapping
only for specific APU GPUs, rather than all PASID-capable devices. It
introduces quirks_force_identity_mapping() to apply this targeted enforcement
and drops the previous SNP check.
Link: https://lore.kernel.org/all/20200824105415.21000-1-joro@8bytes.org/
Link: https://lore.kernel.org/linux-iommu/20260723061548.10187-1-vasant.hegde@amd.com/
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 4dc306a4b5c62..eef585918e607 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -3165,6 +3165,26 @@ static bool amd_iommu_is_attach_deferred(struct device *dev)
> return dev_data->defer_attach;
> }
>
> +static bool quirks_force_identity_mapping(struct pci_dev *pdev)
> +{
> + int class = pdev->class >> 8;
> +
> + /* AMD GPU vendor ID */
> + if (pdev->vendor != PCI_VENDOR_ID_ATI)
> + return false;
> +
> + /* GPU class */
> + if (class != PCI_CLASS_DISPLAY_VGA &&
> + class != PCI_CLASS_DISPLAY_OTHER)
> + return false;
> +
> + if (pci_upstream_bridge(pdev)->vendor == PCI_VENDOR_ID_ATI)
[Severity: Critical]
Is it possible for pci_upstream_bridge() to return NULL here?
If the GPU is located on the PCIe root bus (such as in an integrated SoC
design, or when passed through to a VM via VFIO), pci_upstream_bridge(pdev)
would return NULL. This would lead to a kernel panic when dereferencing
->vendor during boot.
> + return false;
> +
> + /* It is the GPU in an APU, force identity domain */
> + return true;
> +}
[Severity: High]
Does this heuristic accurately distinguish APUs from standard discrete GPUs?
Standard discrete GPUs are typically plugged directly into motherboard PCIe
slots, which means their upstream bridge is the motherboard's root port
(e.g., an Intel or AMD root port, not an ATI switch). Since the root port
vendor is not ATI, this check would fall through and erroneously return true,
forcing standard discrete GPUs into the identity domain.
[ ... ]
> - /*
> - * Do not identity map IOMMUv2 capable devices when:
> - * - memory encryption is active, because some of those devices
> - * (AMD GPUs) don't have the encryption bit in their DMA-mask
> - * and require remapping.
> - * - SNP is enabled, because it prohibits DTE[Mode]=0.
> - */
> - if (pdev_pasid_supported(dev_data) &&
> - !cc_platform_has(CC_ATTR_MEM_ENCRYPT) &&
> - !amd_iommu_snp_en) {
> + /* Apply device specific quirks */
> + if (quirks_force_identity_mapping(to_pci_dev(dev))) {
> + /*
> + * When memory encryption is active, some of these devices
> + * don't have the encryption bit in their DMA-mask and
> + * require remapping.
> + */
> + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
> + return 0;
> +
> + return IOMMU_DOMAIN_IDENTITY;
> }
[Severity: High]
Since the amd_iommu_snp_en check was dropped, how does this affect discrete
GPUs on SNP-enabled systems?
If standard discrete GPUs are incorrectly identified as APUs by
quirks_force_identity_mapping(), they will be unconditionally forced into
IOMMU_DOMAIN_IDENTITY here when SME is disabled.
On systems with SNP enabled, amd_iommu_identity_attach() will reject the
identity domain if Mode0 isn't supported, returning -EINVAL. Could this leave
the discrete GPU without a valid domain and break DMA entirely?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260824085821.5422-1-vasant.hegde@amd.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] iommu/amd: Force identity mode for selected GPUs only
2026-08-24 8:58 [PATCH v2] iommu/amd: Force identity mode for selected GPUs only Vasant Hegde
2026-08-24 9:09 ` sashiko-bot
@ 2026-08-24 13:18 ` Mario Limonciello
2026-08-24 13:24 ` Jason Gunthorpe
2 siblings, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2026-08-24 13:18 UTC (permalink / raw)
To: Vasant Hegde, iommu, joro, linux-pci
Cc: will, robin.murphy, suravee.suthikulpanit, bhelgaas,
alexander.deucher, felix.kuehling, jgg
On 8/24/26 03:58, Vasant Hegde wrote:
> Certain AMD GPUs must always operate in IOMMU identity mode. This was
> previously enforced using a PASID check, which happened to work because
> these specific GPUs are PASID-capable. However, this approach incorrectly
> applies identity mode enforcement to all PASID-capable devices, not just
> the GPUs that require it.
>
> This made sense in the past because the domain allocation API
> (iommu_ops->domain_alloc()) only received the domain type, so the
> driver had no way to inspect device capabilities and pick the most
> suitable page table format (v1 or v2). With the recent driver
> enhancement to use domain_alloc_paging_flags() for all paging
> domain allocations, the driver can now inspect the device and flags
> directly and choose the appropriate page table type per device.
>
> Update amd_iommu_def_domain_type() to force identity mapping only for
> the specific GPUs that require it, via a new quirks_force_identity_mapping().
>
> With this change, a system booting in DMA translation mode will now
> select:
> * Guest (v2) page table for PASID-capable devices
> * Host (v1) page table for non-PASID-capable devices
>
> Also drop the amd_iommu_snp_en check, as SNP enforces paging domain,
> which doesn't work with the identity requirement of these GPUs.
>
> Link: https://lore.kernel.org/all/20200824105415.21000-1-joro@8bytes.org/
> Link: https://lore.kernel.org/linux-iommu/20260723061548.10187-1-vasant.hegde@amd.com/
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Mario Limonciello <mario.limonciello@amd.com>
> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>> ---
> Changes in v2:
> - Dropped disabling ATS for "Radeon Pro WX 4100"
> - Addressed review comments
>
> @Jason,
> Once this patch settles, I will send separate patch to drop
> 'untrusted' check inside amd_iommu_def_domain_type().
>
> Regarding SME check, I have retained SME chek inside
> quirks_force_identity_mapping(). If everyone is fine to drop then I
> will do follow up patch later.
>
> -Vasant
>
> drivers/iommu/amd/iommu.c | 45 +++++++++++++++++++++++++++++----------
> 1 file changed, 34 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 29dc18d3d22e..fc7819f57521 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -3122,6 +3122,26 @@ static bool amd_iommu_is_attach_deferred(struct device *dev)
> return dev_data->defer_attach;
> }
>
> +static bool quirks_force_identity_mapping(struct pci_dev *pdev)
> +{
> + int class = pdev->class >> 8;
> +
> + /* AMD GPU vendor ID */
> + if (pdev->vendor != PCI_VENDOR_ID_ATI)
> + return false;
> +
> + /* GPU class */
> + if (class != PCI_CLASS_DISPLAY_VGA &&
> + class != PCI_CLASS_DISPLAY_OTHER)
> + return false;
> +
> + if (pci_upstream_bridge(pdev)->vendor == PCI_VENDOR_ID_ATI)
> + return false;
> +
> + /* It is the GPU in an APU, force identity domain */
> + return true;
> +}
> +
> static int amd_iommu_def_domain_type(struct device *dev)
> {
> struct iommu_dev_data *dev_data;
> @@ -3130,20 +3150,23 @@ static int amd_iommu_def_domain_type(struct device *dev)
> if (!dev_data)
> return 0;
>
> + if (!dev_is_pci(dev))
> + return 0;
> +
> /* Always use DMA domain for untrusted device */
> - if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted)
> + if (to_pci_dev(dev)->untrusted)
> return IOMMU_DOMAIN_DMA;
>
> - /*
> - * Do not identity map IOMMUv2 capable devices when:
> - * - memory encryption is active, because some of those devices
> - * (AMD GPUs) don't have the encryption bit in their DMA-mask
> - * and require remapping.
> - * - SNP is enabled, because it prohibits DTE[Mode]=0.
> - */
> - if (pdev_pasid_supported(dev_data) &&
> - !cc_platform_has(CC_ATTR_MEM_ENCRYPT) &&
> - !amd_iommu_snp_en) {
> + /* Apply device specific quirks */
> + if (quirks_force_identity_mapping(to_pci_dev(dev))) {
> + /*
> + * When memory encryption is active, some of these devices
> + * don't have the encryption bit in their DMA-mask and
> + * require remapping.
> + */
> + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
> + return 0;
> +
> return IOMMU_DOMAIN_IDENTITY;
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] iommu/amd: Force identity mode for selected GPUs only
2026-08-24 8:58 [PATCH v2] iommu/amd: Force identity mode for selected GPUs only Vasant Hegde
2026-08-24 9:09 ` sashiko-bot
2026-08-24 13:18 ` Mario Limonciello
@ 2026-08-24 13:24 ` Jason Gunthorpe
2 siblings, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2026-08-24 13:24 UTC (permalink / raw)
To: Vasant Hegde
Cc: iommu, joro, linux-pci, will, robin.murphy, suravee.suthikulpanit,
bhelgaas, alexander.deucher, mario.limonciello, felix.kuehling
On Mon, Aug 24, 2026 at 08:58:21AM +0000, Vasant Hegde wrote:
> Certain AMD GPUs must always operate in IOMMU identity mode. This was
> previously enforced using a PASID check, which happened to work because
> these specific GPUs are PASID-capable. However, this approach incorrectly
> applies identity mode enforcement to all PASID-capable devices, not just
> the GPUs that require it.
>
> This made sense in the past because the domain allocation API
> (iommu_ops->domain_alloc()) only received the domain type, so the
> driver had no way to inspect device capabilities and pick the most
> suitable page table format (v1 or v2). With the recent driver
> enhancement to use domain_alloc_paging_flags() for all paging
> domain allocations, the driver can now inspect the device and flags
> directly and choose the appropriate page table type per device.
>
> Update amd_iommu_def_domain_type() to force identity mapping only for
> the specific GPUs that require it, via a new quirks_force_identity_mapping().
>
> With this change, a system booting in DMA translation mode will now
> select:
> * Guest (v2) page table for PASID-capable devices
> * Host (v1) page table for non-PASID-capable devices
>
> Also drop the amd_iommu_snp_en check, as SNP enforces paging domain,
> which doesn't work with the identity requirement of these GPUs.
>
> Link: https://lore.kernel.org/all/20200824105415.21000-1-joro@8bytes.org/
> Link: https://lore.kernel.org/linux-iommu/20260723061548.10187-1-vasant.hegde@amd.com/
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Mario Limonciello <mario.limonciello@amd.com>
> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
> ---
> Changes in v2:
> - Dropped disabling ATS for "Radeon Pro WX 4100"
> - Addressed review comments
>
> @Jason,
> Once this patch settles, I will send separate patch to drop
> 'untrusted' check inside amd_iommu_def_domain_type().
>
> Regarding SME check, I have retained SME chek inside
> quirks_force_identity_mapping(). If everyone is fine to drop then I
> will do follow up patch later.
Sure
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> + /* Apply device specific quirks */
> + if (quirks_force_identity_mapping(to_pci_dev(dev))) {
> + /*
> + * When memory encryption is active, some of these devices
> + * don't have the encryption bit in their DMA-mask and
> + * require remapping.
> + */
> + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
> + return 0;
I still haven't seen an explanation why this make sense. This
patch says two conflicting things:
1) We need identity for the APU cases because they can't handle
translation
2) We can't have identity for the SME case because it can't handle the
high address bit, so use paging.
Surely #2 is also a per-GPU version thing and this address width issue
was fixed in newer chips?
But even so, if paging doesn't work why is it OK to use it for SME? If
paging does work then why do we quirk it away?
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-24 13:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-24 8:58 [PATCH v2] iommu/amd: Force identity mode for selected GPUs only Vasant Hegde
2026-08-24 9:09 ` sashiko-bot
2026-08-24 13:18 ` Mario Limonciello
2026-08-24 13:24 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox