From d55e700ba1472d6b6a62ae307cdec9b8bf92cbd1 Mon Sep 17 00:00:00 2001
From: Ben Hutchings <ben@decadent.org.uk>
Date: Tue, 13 Jan 2026 11:52:16 +0800
Subject: [PATCH 2/2] UBUNTU: SAUCE: intel-iommu: Add option to exclude
 integrated GPU only

BugLink: https://bugs.launchpad.net/bugs/2136958

There is still laptop firmware that touches the integrated GPU behind
the operating system's back, and doesn't say so in the RMRR table.
Enabling the IOMMU for all devices causes breakage, but turning it off
for all graphics devices seems like a major weakness.

Add an option, intel_iommu=intgpu_off, to exclude only integrated GPUs
from remapping.  This is a narrower exclusion than igfx_off: it only
affects Intel devices on the root bus.  Devices attached through an
external port (Thunderbolt or ExpressCard) won't be on the root bus.

Bug-Debian: https://bugs.debian.org/935270
Bug-Kali: https://bugs.kali.org/view.php?id=5644
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
(backported from commit https://salsa.debian.org/kernel-team/linux/-/blob/debian/latest/debian/patches/features/x86/intel-iommu-add-option-to-exclude-integrated-gpu-only.patch)
[acelan: Resolved conflicts due to missing commits and code structure differences:
 - Added IS_INTGPU_DEVICE macro after existing IS_GFX_DEVICE definition (line 37)
 - Added dmar_map_intgpu variable after existing dmar_map_ipu variable (line 222)
 - Defined IDENTMAP_INTGPU as 16 (after IDENTMAP_IPU = 8) instead of 8 as in
   original patch, since IDENTMAP_IPU already occupies that value in current kernel]
Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  2 ++
 drivers/iommu/intel/iommu.c                     | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a56a38190d9c5..a1981d8c2dc71 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2372,6 +2372,8 @@
 			bypassed by not enabling DMAR with this option. In
 			this case, gfx device will use physical address for
 			DMA.
+		intgpu_off [Default Off]
+			Bypass the DMAR unit for an integrated GPU only.
 		strict [Default Off]
 			Deprecated, equivalent to iommu.strict=1.
 		sp_off [Default Off]
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 2fd45028ca148..6388608c97d35 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -35,6 +35,9 @@
 #define CONTEXT_SIZE		VTD_PAGE_SIZE
 
 #define IS_GFX_DEVICE(pdev) pci_is_display(pdev)
+#define IS_INTGPU_DEVICE(pdev) (IS_GFX_DEVICE(pdev) &&		\
+				(pdev)->vendor == 0x8086 &&	\
+				pci_is_root_bus((pdev)->bus))
 #define IS_USB_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_SERIAL_USB)
 #define IS_ISA_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA)
 #define IS_INTEL_IPU(pdev) ((pdev)->vendor == PCI_VENDOR_ID_INTEL &&	\
@@ -218,6 +221,7 @@ int intel_iommu_enabled = 0;
 EXPORT_SYMBOL_GPL(intel_iommu_enabled);
 
 static int dmar_map_ipu = 1;
+static int dmar_map_intgpu = 1;
 static int intel_iommu_superpage = 1;
 static int iommu_identity_mapping;
 static int iommu_skip_te_disable;
@@ -225,6 +229,7 @@ static int disable_igfx_iommu;
 
 #define IDENTMAP_AZALIA		4
 #define IDENTMAP_IPU		8
+#define IDENTMAP_INTGPU		16
 
 const struct iommu_ops intel_iommu_ops;
 static const struct iommu_dirty_ops intel_dirty_ops;
@@ -264,6 +269,9 @@ static int __init intel_iommu_setup(char *str)
 		} else if (!strncmp(str, "igfx_off", 8)) {
 			disable_igfx_iommu = 1;
 			pr_info("Disable GFX device mapping\n");
+		} else if (!strncmp(str, "intgpu_off", 10)) {
+			dmar_map_intgpu = 0;
+			pr_info("Disable integrated GPU device mapping\n");
 		} else if (!strncmp(str, "forcedac", 8)) {
 			pr_warn("intel_iommu=forcedac deprecated; use iommu.forcedac instead\n");
 			iommu_dma_forcedac = true;
@@ -1892,6 +1900,9 @@ static int device_def_domain_type(struct device *dev)
 
 		if ((iommu_identity_mapping & IDENTMAP_IPU) && IS_INTEL_IPU(pdev))
 			return IOMMU_DOMAIN_IDENTITY;
+
+		if ((iommu_identity_mapping & IDENTMAP_INTGPU) && IS_INTGPU_DEVICE(pdev))
+			return IOMMU_DOMAIN_IDENTITY;
 	}
 
 	return 0;
@@ -2185,6 +2196,9 @@ static int __init init_dmars(void)
 	if (!dmar_map_ipu)
 		iommu_identity_mapping |= IDENTMAP_IPU;
 
+	if (!dmar_map_intgpu)
+		iommu_identity_mapping |= IDENTMAP_INTGPU;
+
 	check_tylersburg_isoch();
 
 	/*
-- 
2.51.0

