Skip to contentSkip to conversation

IOMMU Performance Optimization support

PATCH Superseded Mario Limonciello 3 participants 5 messages Aug 31

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover IOMMU Performance Optimization support

Add support for the AMD IOMMU Performance Optimization (PerfOpt) feature as defined in the AMD I/O Virtualization Technology (IOMMU) Specification, Section 3.4.9 (MMIO Offset 016Ch).

This feature allows privileged integrated I/O devices (GPUs) to bypass the IOMMU when directly accessing system memory. The IOMMU only enforces the IR/IW permission bits without GPA->SPA translations.

Drivers will opt into this behavior, and enable amdgpu to turn this feature on when an integrated GPU is already in identity mode. If a user prefers to keep it always off (even with identity mode) there is also a module parameter to force it off.

Mario Limonciello (2):
iommu/amd: Add PerfOpt IOMMU performance optimization support drm/amdgpu: Enable PerfOpt IOMMU perf optimization when GPU in
identity domain

 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  41 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  12 ++
 drivers/iommu/amd/amd_iommu.h              |   3 +
 drivers/iommu/amd/amd_iommu_types.h        |   7 +
 drivers/iommu/amd/init.c                   |  43 +++++
 drivers/iommu/amd/iommu.c                  | 214 +++++++++++++++++++++
 include/linux/amd-iommu.h                  |  11 ++
 8 files changed, 332 insertions(+)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 iommu/amd: Add PerfOpt IOMMU performance optimization support

Add support for the AMD IOMMU Performance Optimization (PerfOpt) feature as defined in the AMD I/O Virtualization Technology (IOMMU) Specification, Section 3.4.9 (MMIO Offset 016Ch).

This feature allows privileged integrated I/O devices (GPUs) to bypass the IOMMU when directly accessing system memory. The IOMMU only enforces the IR/IW permission bits without GPA->SPA translations.

amd_iommu_enable_perfopt() performs a detach/reattach cycle to rehome devices already on the identity domain with ATS/PRI/PASID/GCR3 disabled (skip_caps path). amd_iommu_disable_perfopt() restores those capabilities. The per-device dev_data->perfopt flag tracks state.

PERF_OPT_EN is a single control bit per IOMMU, shared by every device behind that IOMMU, while enablement is requested per device. It is therefore reference counted (amd_iommu->perfopt_refcount): armed on the first requesting device and cleared on the last, so one device's teardown never clears the bit while a peer behind the same IOMMU still needs it.

The per-device flag is cleared on every teardown path (blocked_domain_attach, release_device, and amd_iommu_disable_perfopt), dropping the reference with it, so a reused dev_data never carries stale PerfOpt state onto its next bind.

On suspend/resume the hardware is reprogrammed from scratch:
amd_iommu_perfopt_clear() forces the bit off without touching the reference count, and amd_iommu_perfopt_restore() re-asserts it from the count after early_enable_iommu(), so armed devices keep the optimization across resume without relying on each consumer driver to re-arm.

The exported amd_iommu_enable_perfopt()/amd_iommu_disable_perfopt() run only from a consumer driver's bind/unbind path. group->mutex is not exposed to drivers, but a device bound to its native driver cannot have its IOMMU domain changed concurrently by the core, which serializes the detach/attach pair against core-driven attach.

PerfOpt is opt-in -- only enabled when explicitly requested by a driver.

---
 drivers/iommu/amd/amd_iommu.h       |   3 +
 drivers/iommu/amd/amd_iommu_types.h |   7 +
 drivers/iommu/amd/init.c            |  43 ++++++
 drivers/iommu/amd/iommu.c           | 214 ++++++++++++++++++++++++++++
 include/linux/amd-iommu.h           |  11 ++
 5 files changed, 278 insertions(+)
drivers/iommu/amd/amd_iommu.h +3 -0
index a2fe804b038b6..1f8f9df8e6c24 100644
@@ -48,6 +48,9 @@ extern u8 amd_iommu_hpt_vasize;
 extern unsigned long amd_iommu_pgsize_bitmap;
 extern bool amd_iommu_hatdis;
 
+int amd_iommu_perfopt_clear(struct amd_iommu *iommu);
+int amd_iommu_perfopt_restore(struct amd_iommu *iommu);
+
 /* Protection domain ops */
 void amd_iommu_init_identity_domain(void);
 struct protection_domain *protection_domain_alloc(void);
drivers/iommu/amd/amd_iommu_types.h +7 -0
index 3dbe20023456b..755421e5cd757 100644
@@ -65,6 +65,7 @@
 #define MMIO_MSI_ADDR_LO_OFFSET	0x015C
 #define MMIO_MSI_ADDR_HI_OFFSET	0x0160
 #define MMIO_MSI_DATA_OFFSET	0x0164
+#define MMIO_PERF_OPT_OFFSET	0x016C
 #define MMIO_INTCAPXT_EVT_OFFSET	0x0170
 #define MMIO_INTCAPXT_PPR_OFFSET	0x0178
 #define MMIO_INTCAPXT_GALOG_OFFSET	0x0180
@@ -99,6 +100,8 @@
 #define FEATURE_GLX		GENMASK_ULL(15, 14)
 #define FEATURE_GAM_VAPIC	BIT_ULL(21)
 #define FEATURE_PASMAX		GENMASK_ULL(36, 32)
+#define FEATURE_PERF_OPT	BIT_ULL(45)
+#define PERF_OPT_EN		BIT(13)
 #define FEATURE_GIOSUP		BIT_ULL(48)
 #define FEATURE_HASUP		BIT_ULL(49)
 #define FEATURE_EPHSUP		BIT_ULL(50)
@@ -670,6 +673,9 @@ struct amd_iommu {
 	/* Extended features 2 */
 	u64 features2;
 
+	/* Devices requesting PerfOpt; the shared PERF_OPT_EN bit is on while >0. Protected by @lock. */
+	int perfopt_refcount;
+
 	/* PCI device id of the IOMMU device */
 	u16 devid;
 
@@ -831,6 +837,7 @@ struct iommu_dev_data {
 	u8 ppr          :1;		  /* Enable device PPR support */
 	bool use_vapic;			  /* Enable device to use vapic mode */
 	bool defer_attach;
+	bool perfopt;
 
 	struct ratelimit_state rs;        /* Ratelimit IOPF messages */
 };
drivers/iommu/amd/init.c +43 -0

65 lines not on this page · raw message

drivers/iommu/amd/iommu.c +214 -0

250 lines not on this page · raw message

include/linux/amd-iommu.h +11 -0
index edcee9f5335a6..e03575cbc08c6 100644
@@ -76,4 +76,15 @@ static inline int amd_iommu_snp_disable(void) { return 0; }
 static inline bool amd_iommu_sev_tio_supported(void) { return false; }
 #endif
 
+#ifdef CONFIG_AMD_IOMMU
+int amd_iommu_enable_perfopt(struct pci_dev *pdev);
+void amd_iommu_disable_perfopt(struct pci_dev *pdev);
+#else
+static inline int amd_iommu_enable_perfopt(struct pci_dev *pdev)
+{
+	return 0;
+}
+static inline void amd_iommu_disable_perfopt(struct pci_dev *pdev) { }
+#endif
+
 #endif /* _ASM_X86_AMD_IOMMU_H */
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 drm/amdgpu: Enable PerfOpt IOMMU perf optimization when GPU in identity domain

In reply to Mario Limonciello

Enable PerfOpt via amd_iommu_enable_perfopt() when the GPU's iommu_perfopt module parameter is enabled (default 1) and the GPU resides in the identity domain. The identity domain means the GPU is already performing direct DMA with the IOMMU only enforcing IR/IW permission bits -- no GPA->SPA translations.

amd_iommu_enable_perfopt() clears ATS, PRI, PASID and SVA for the device. This is safe in identity domain because DTE[I]=0 means the IOMMU already returns target abort for ATS requests from this peripheral and the GPU manages its own TLB.

PerfOpt is a soft, optional latency optimization: failing to arm it (for example on an IOMMU that does not implement the feature, which returns -ENODEV) must not be fatal, so probe and resume warn and continue rather than aborting.

PERF_OPT_EN is a per-IOMMU control shared by all devices behind that IOMMU; the IOMMU driver reference counts it so that on systems where multiple devices share one IOMMU, one GPU's teardown does not clear the bit while a peer still requires it.

Arming PerfOpt trades IOMMU DMA containment for lower DMA latency. This is enabled by default for GPUs in the identity domain as a deliberate, documented policy and can be disabled with iommu_perfopt=0.

The AMD IOMMU spec indicates this is only supported on integrated GPUs so check explicitly for AMD_IS_APU (which is set by amdgpu_device_ip_early_init()).

PerfOpt is disabled during GPU init teardown and restored on resume.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 41 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 12 +++++++
 3 files changed, 54 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 7974f9b7944f3..930a78db7132e 100644
@@ -156,6 +156,7 @@ struct amdgpu_watchdog_timer {
  * Modules parameters.
  */
 extern int amdgpu_modeset;
+extern int amdgpu_iommu_perfopt;
 extern unsigned int amdgpu_vram_limit;
 extern int amdgpu_vis_vram_limit;
 extern int amdgpu_gart_size;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +41 -0

71 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +12 -0
index 5b08afde37baf..26ba7852e1ceb 100644
@@ -185,6 +185,7 @@ char *amdgpu_disable_cu;
 char *amdgpu_virtual_display;
 int amdgpu_enforce_isolation = -1;
 int amdgpu_modeset = -1;
+int amdgpu_iommu_perfopt = 1;
 
 /* Specifies the default granularity for SVM, used in buffer
  * migration and restoration of backing memory when handling
@@ -392,6 +393,17 @@ module_param_named(fw_load_type, amdgpu_fw_load_type, int, 0444);
 MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)");
 module_param_named(aspm, amdgpu_aspm, int, 0444);
 
+/**
+ * DOC: iommu_perfopt (int)
+ * Control the AMD IOMMU PerfOpt DMA-latency optimization
+ * (0 = disable; 1 = enable on APU devices in identity domain).
+ * This arms the IOMMU PerfOpt control (IOMMU spec, MMIO Offset 016Ch, EFR PerfOptSup / PerfOptEn)
+ * Arming it disables ATS, PRI, PASID and SVA for the GPU and removes IOMMU DMA containment for it,
+ * trading isolation for lower DMA latency.
+ */
+MODULE_PARM_DESC(iommu_perfopt, "Control IOMMU PerfOpt DMA-latency optimization (1 = enable on APU devices in identity domain, 0 = disable)");
+module_param_named(iommu_perfopt, amdgpu_iommu_perfopt, int, 0444);
+
 /**
  * DOC: runpm (int)
  * Override for runtime power management control for dGPUs. The amdgpu driver can dynamically power down
Signature · 1 line
2.43.0
#3 lore raw

RE: [PATCH 2/2] drm/amdgpu: Enable PerfOpt IOMMU perf optimization when GPU in identity domain

Public

Quoted 186 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Monday, August 31, 2026 1:51 AM
To: Deucher, Alexander <[email protected]>; Joerg Roedel <[email protected]>
Cc: [email protected]; Suthikulpanit, Suravee <[email protected]>; Hegde, Vasant <[email protected]>; Will Deacon <[email protected]>; Robin Murphy <[email protected]>; open list:AMD IOMMU (AMD-VI) <[email protected]>; Jatin Kataria <[email protected]>; Boqun Feng <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: Enable PerfOpt IOMMU perf optimization when GPU in identity domain

Enable PerfOpt via amd_iommu_enable_perfopt() when the GPU's iommu_perfopt module parameter is enabled (default 1) and the GPU resides in the identity domain. The identity domain means the GPU is already performing direct DMA with the IOMMU only enforcing IR/IW permission bits -- no GPA->SPA translations.

amd_iommu_enable_perfopt() clears ATS, PRI, PASID and SVA for the device. This is safe in identity domain because DTE[I]=0 means the IOMMU already returns target abort for ATS requests from this peripheral and the GPU manages its own TLB.

PerfOpt is a soft, optional latency optimization: failing to arm it (for example on an IOMMU that does not implement the feature, which returns
-ENODEV) must not be fatal, so probe and resume warn and continue rather than aborting.

PERF_OPT_EN is a per-IOMMU control shared by all devices behind that IOMMU; the IOMMU driver reference counts it so that on systems where multiple devices share one IOMMU, one GPU's teardown does not clear the bit while a peer still requires it.

Arming PerfOpt trades IOMMU DMA containment for lower DMA latency. This is enabled by default for GPUs in the identity domain as a deliberate, documented policy and can be disabled with iommu_perfopt=0.

The AMD IOMMU spec indicates this is only supported on integrated GPUs so check explicitly for AMD_IS_APU (which is set by amdgpu_device_ip_early_init()).

PerfOpt is disabled during GPU init teardown and restored on resume.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 41
++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 12 +++++++
 3 files changed, 54 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 7974f9b7944f3..930a78db7132e 100644
@@ -156,6 +156,7 @@ struct amdgpu_watchdog_timer {
  * Modules parameters.
  */
 extern int amdgpu_modeset;
+extern int amdgpu_iommu_perfopt;
 extern unsigned int amdgpu_vram_limit;
 extern int amdgpu_vis_vram_limit;
 extern int amdgpu_gart_size;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +16 -0
index 44bed0ba64a37..75c74c72a52ea 100644
@@ -33,6 +33,7 @@
 #include <linux/console.h>
 #include <linux/slab.h>
 #include <linux/iommu.h>
+#include <linux/amd-iommu.h>
 #include <linux/pci.h>
 #include <linux/pci-p2pdma.h>
 #include <linux/apple-gmux.h>
@@ -3752,6 +3753,17 @@
 amdgpu_device_should_register_switcheroo(struct amdgpu_device *adev,
 bool px)
                     apple_gmux_detect(NULL, NULL)));  }
 
+static inline bool amdgpu_device_identity(struct amdgpu_device *adev) {
+     struct pci_dev *pdev = adev->pdev;
+     struct iommu_domain *domain =
 iommu_get_domain_for_dev(&pdev->dev);
+
+     if (!domain)
+             return false;
+
+     return domain->type == IOMMU_DOMAIN_IDENTITY; }
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -3958,6 +3970,18 @@ int amdgpu_device_init(struct amdgpu_device
 *adev,
      if (r)
              return r;
 
+     if (amdgpu_iommu_perfopt != 0 &&
+         amdgpu_device_identity(adev) &&
+         adev->flags & AMD_IS_APU) {
+             int perfopt_ret = amd_iommu_enable_perfopt(pdev);
+
+             /* Optional optimization; a failure to arm it must not abort

probe. */

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+             if (perfopt_ret)
+                     dev_warn(adev->dev,
+                              "Failed to enable IOMMU PerfOpt (%d);

continuing without it\n",

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +20 -0
+                              perfopt_ret);
+     }
+
      /*
       * No need to remove conflicting FBs for non-display class devices.
       * This prevents the sysfb from being freed accidently.
@@ -4327,6 +4351,9 @@ void amdgpu_device_fini_hw(struct
 amdgpu_device *adev)
 
      amdgpu_gart_dummy_page_fini(adev);
 
+     if (amdgpu_iommu_perfopt != 0)
+             amd_iommu_disable_perfopt(adev->pdev);
+
      if (pci_dev_is_disconnected(adev->pdev))
              amdgpu_device_unmap_mmio(adev);
@@ -4692,6 +4719,20 @@ int amdgpu_device_resume(struct drm_device
 *dev, bool notify_clients)
      if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
              return 0;
 
+     if (amdgpu_iommu_perfopt != 0 && amdgpu_device_identity(adev)) {
+             int perfopt_ret = amd_iommu_enable_perfopt(adev->pdev);
+
+             /*
+              * Must not return on failure: a bare return would leak the
+              * SR-IOV VF exclusive-mode acquisition taken above (released
+              * via the exit: path).
+              */
+             if (perfopt_ret)
+                     dev_warn(adev->dev,
+                              "Failed to enable IOMMU PerfOpt (%d);
 continuing without it\n",
+                              perfopt_ret);
+     }
+
      if (adev->in_s0ix)

amdgpu_dpm_gfx_state_change(adev,
sGpuChangeState_D0Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
index 5b08afde37baf..26ba7852e1ceb 100644
@@ -185,6 +185,7 @@ char *amdgpu_disable_cu;  char
 *amdgpu_virtual_display;  int amdgpu_enforce_isolation = -1;  int
 amdgpu_modeset = -1;
+int amdgpu_iommu_perfopt = 1;
 
 /* Specifies the default granularity for SVM, used in buffer
  * migration and restoration of backing memory when handling @@ -392,6
+393,17 @@ module_param_named(fw_load_type, amdgpu_fw_load_type,

int, 0444); MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)"); module_param_named(aspm, amdgpu_aspm, int, 0444);

+/**
+ * DOC: iommu_perfopt (int)
+ * Control the AMD IOMMU PerfOpt DMA-latency optimization
+ * (0 = disable; 1 = enable on APU devices in identity domain).
+ * This arms the IOMMU PerfOpt control (IOMMU spec, MMIO Offset 016Ch,

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +6 -0
+EFR PerfOptSup / PerfOptEn)
+ * Arming it disables ATS, PRI, PASID and SVA for the GPU and removes
+IOMMU DMA containment for it,
+ * trading isolation for lower DMA latency.
+ */
+MODULE_PARM_DESC(iommu_perfopt, "Control IOMMU PerfOpt DMA-

latency

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
+optimization (1 = enable on APU devices in identity domain, 0 =
+disable)"); module_param_named(iommu_perfopt,
Quoted 2 lines

amdgpu_iommu_perfopt,
+int, 0444);

For consistency with the other driver parameters, I would make the default -1 (auto) and have auto enable for APU devices. That way we can add 1 as an option later if we want to add a way to force it on in certain scenarios.

Akex

Quoted 7 lines

+
/**
* DOC: runpm (int)
* Override for runtime power management control for dGPUs. The amdgpu
driver can dynamically power down
--
2.43.0

Tested-by on the v1 series
#4 lore raw
In reply to Mario Limonciello
Quoted 18 lines · Mario Limonciello

Add support for the AMD IOMMU Performance Optimization (PerfOpt) feature as defined in the AMD I/O Virtualization Technology (IOMMU) Specification, Section 3.4.9 (MMIO Offset 016Ch).

This feature allows privileged integrated I/O devices (GPUs) to bypass the IOMMU when directly accessing system memory. The IOMMU only enforces the IR/IW permission bits without GPA->SPA translations.

Drivers will opt into this behavior, and enable amdgpu to turn this feature on when an integrated GPU is already in identity mode. If a user prefers to keep it always off (even with identity mode) there is also a module parameter to force it off.

Mario Limonciello (2):
iommu/amd: Add PerfOpt IOMMU performance optimization support drm/amdgpu: Enable PerfOpt IOMMU perf optimization when GPU in
identity domain

Quoted 9 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  41 ++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  12 ++
  drivers/iommu/amd/amd_iommu.h              |   3 +
  drivers/iommu/amd/amd_iommu_types.h        |   7 +
  drivers/iommu/amd/init.c                   |  43 +++++
  drivers/iommu/amd/iommu.c                  | 214 +++++++++++++++++++++
  include/linux/amd-iommu.h                  |  11 ++
  8 files changed, 332 insertions(+)

Hi Mario,

The Legion Go 2 has a significant performance degradation when IOMMU is ON and VRAM is set to auto in the BIOS. I applied these to linux-next and compared to 7.2 neptune on the Legion Go 2 and got the following results:
Game: Avowed
With patches:

Go 2| Vram: 2GB, IOMMU: Off, FPS: 35-40, Frame Time: consistent
Go 2| Vram: 2GB, IOMMU: On, FPS: 35-40, Frame Time: consistent
Go 2| Vram: Auto, IOMMU: Off, FPS: 35-40, Frame Time: consistent
Go 2| Vram: Auto, IOMMU: On, FPS: 35-40, Frame Time: consistent

Without Patches:

Go 2| Vram: 2GB, IOMMU: Off, FPS: 35-40, Frame Time: consistent
Go 2| Vram: 2GB, IOMMU: On, FPS: 35-40, Frame Time: consistent
Go 2| Vram: Auto, IOMMU: Off, FPS: 35-40, Frame Time: consistent
Go 2| Vram: Auto, IOMMU: On, FPS: 20, Frame Time: inconsistent

Overall, this seems to fix the performance issue with IOMMU when BIOS is in the factory default setting.