Skip to contentSkip to conversation

IOMMU Performance Optimization support

PATCH In review Mario Limonciello 8 participants 24 messages Sep 8 – Sep 29

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 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.

v2:
* Rebase on 7.3-rc2
* Adjust amdgpu parameter behavior

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 |  50 +++++
 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, 341 insertions(+)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 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.

---
v2:
* rebase on 7.3-rc2
* add tag

---
 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

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 1 line · Mario Limonciello

+EXPORT_SYMBOL_GPL(amd_iommu_enable_perfopt);

Last time we hardwired the GPU and IOMMU drivers together it was a huge mess to undo.

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

How does the GPU driver even know it is magic special?

drivers/iommu/amd/iommu.c static void detach_device(struct device *dev) · line 2672

Quoted 6 lines
drivers/iommu/amd/iommu.c +6 -0
+	/*
+	 * Restore ATS/PRI/PASID (and thus SVA) by re-homing the device onto its
+	 * identity domain with the flag cleared, so a later bind without PerfOpt
+	 * sees a normally-capable device. See the locking note in
+	 * amd_iommu_enable_perfopt().
+	 */

And this is sort of a wrong thing in the driver, it shouldn't have ATS turned on for identitiy mappings, and it certainly shouldn't have PRI turned on until a PRI capable domain is attached.

Jason

#3 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 9 lines · Jason Gunthorpe
Quoted 1 line · Mario Limonciello

+EXPORT_SYMBOL_GPL(amd_iommu_enable_perfopt);

Last time we hardwired the GPU and IOMMU drivers together it was a huge mess to undo.

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

The reason was to allow an "opt-out" path on the GPU driver.

Quoted 2 lines

How does the GPU driver even know it is magic special?

See patch 2/2. GPU driver looks if it's an APU and it's in identity mode. The special mode is only for the GPU in an APU. It shouldn't be applied to anything else.

Quoted 12 lines

drivers/iommu/amd/iommu.c static void detach_device(struct device *dev) · line 2672

Quoted 7 lines
drivers/iommu/amd/iommu.c +6 -0
+	/*
+	 * Restore ATS/PRI/PASID (and thus SVA) by re-homing the device onto its
+	 * identity domain with the flag cleared, so a later bind without PerfOpt
+	 * sees a normally-capable device. See the locking note in
+	 * amd_iommu_enable_perfopt().
+	 */

And this is sort of a wrong thing in the driver, it shouldn't have ATS turned on for identitiy mappings, and it certainly shouldn't have PRI turned on until a PRI capable domain is attached.

Quoted 2 lines

Jason

amd_iommu_disable_perfopt() only re-applies the policy that was previously set before PerfOpt.

If you would like I'll send a follow up patch to clarify this comment.

#4 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 6 lines · Mario Limonciello
Quoted 3 lines · Jason Gunthorpe
Quoted 1 line · Mario Limonciello

+EXPORT_SYMBOL_GPL(amd_iommu_enable_perfopt);

Quoted 8 lines
Quoted 6 lines

Last time we hardwired the GPU and IOMMU drivers together it was a huge mess to undo.

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

The reason was to allow an "opt-out" path on the GPU driver.

This seems like a very poor reason for doing this given the past negative experiances.

Jason

#5 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 14 lines · Jason Gunthorpe
Quoted 13 lines · Mario Limonciello
Quoted 9 lines · Jason Gunthorpe
Quoted 1 line · Mario Limonciello

+EXPORT_SYMBOL_GPL(amd_iommu_enable_perfopt);

Last time we hardwired the GPU and IOMMU drivers together it was a huge mess to undo.

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

Quoted 6 lines
Quoted 1 line

The reason was to allow an "opt-out" path on the GPU driver.

This seems like a very poor reason for doing this given the past negative experiances.

Jason

I guess I don't have the context of what happened in the past. Could you fill me in? I'm not against it being automatic when in identity mode. I'll just need to come up with a way to check it's the GPU inside of an APU not a dGPU connected to the APU.

maintainer
#6 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

In reply to Jason Gunthorpe
Quoted 3 lines · Jason Gunthorpe

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

This is a layering violation either way. Either the IOMMU driver needs to poke into device details and their relations or the device driver needs to poke into IOMMU details.

This is not perfect but to some degree unavoidable with these highly integrated SOCs.

-Joerg

#7 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 8 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

This is a layering violation either way. Either the IOMMU driver needs to poke into device details and their relations or the device driver needs to poke into IOMMU details.

There are no device details, this is just a module option in the gpu driver.

Quoted 2 lines

This is not perfect but to some degree unavoidable with these highly integrated SOCs.

This is exactly the sort of hacky thing ACPI should describe so the drivers can just turn things on automatically.

Who is ever going to track down and figure out it is OK to set these kinds of module options in the first place? There is general negative sentiment in the kernel to doing things like this with modue options.

How does Windows do it? There certainly isn't a "module option" there?

Jason

#8 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 6 lines · Jason Gunthorpe
Quoted 5 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

Quoted 6 lines
Quoted 3 lines

This is a layering violation either way. Either the IOMMU driver needs to poke into device details and their relations or the device driver needs to poke into IOMMU details.

There are no device details, this is just a module option in the gpu driver.

Well the GPU driver has knowledge whether it's a GPU inside of an APU to decide if it's valid. That information is part of the discovery table setup.

Quoted 7 lines
Quoted 3 lines

This is not perfect but to some degree unavoidable with these highly integrated SOCs.

This is exactly the sort of hacky thing ACPI should describe so the drivers can just turn things on automatically.

Quoted 7 lines

Who is ever going to track down and figure out it is OK to set these kinds of module options in the first place? There is general negative sentiment in the kernel to doing things like this with modue options.

How does Windows do it? There certainly isn't a "module option" there?

Jason

This specific one I don't know; but these kinds of things usually end up in knobs in a UI that plumb some IPC deep into the driver stack.

#9 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 13 lines · Mario Limonciello
Quoted 10 lines · Jason Gunthorpe
Quoted 8 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

This is a layering violation either way. Either the IOMMU driver needs to poke into device details and their relations or the device driver needs to poke into IOMMU details.

Quoted 6 lines
Quoted 2 lines

There are no device details, this is just a module option in the gpu driver.

Well the GPU driver has knowledge whether it's a GPU inside of an APU to decide if it's valid. That information is part of the discovery table setup.

Where was that in patch 2?

The right way for this to work is to quirk it through the iommu driver so it can choose the fast mode, and not involve the GPU driver at all. Like we've done for every other GPU weirdness. And AMD should be making this work better by providing ACPI support so the iommu driver can understand how it should work without inspecting PCI IDs.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

This is not perfect but to some degree unavoidable with these highly integrated SOCs.

This is exactly the sort of hacky thing ACPI should describe so the drivers can just turn things on automatically.

Quoted 8 lines
Quoted 5 lines

Who is ever going to track down and figure out it is OK to set these kinds of module options in the first place? There is general negative sentiment in the kernel to doing things like this with modue options.

How does Windows do it? There certainly isn't a "module option" there?

This specific one I don't know; but these kinds of things usually end up in knobs in a UI that plumb some IPC deep into the driver stack.

Given the huge delta I somehow doubt that AMD would ship a windows driver that defaults to "slow" ? Nor should linux...

Jason

#10 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 14 lines · Jason Gunthorpe
Quoted 13 lines · Mario Limonciello
Quoted 10 lines · Jason Gunthorpe
Quoted 8 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

This is a layering violation either way. Either the IOMMU driver needs to poke into device details and their relations or the device driver needs to poke into IOMMU details.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

There are no device details, this is just a module option in the gpu driver.

Well the GPU driver has knowledge whether it's a GPU inside of an APU to decide if it's valid. That information is part of the discovery table setup.

Where was that in patch 2?

amdgpu_device_use_perfopt()

Quoted 6 lines

The right way for this to work is to quirk it through the iommu driver so it can choose the fast mode, and not involve the GPU driver at all. Like we've done for every other GPU weirdness. And AMD should be making this work better by providing ACPI support so the iommu driver can understand how it should work without inspecting PCI IDs.

There is a heuristic that Vasant added recently that we detect APU from the IOMMU driver. We might be able to use that for now.

I'll take a look at what an incremental patch looks like on top of iommu/next that I think reworks all these paths the way you want. I should be able to post something next week.

#11 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 20 lines · Mario Limonciello
Quoted 17 lines · Jason Gunthorpe
Quoted 16 lines · Mario Limonciello
Quoted 12 lines · Jason Gunthorpe
Quoted 8 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

This is a layering violation either way. Either the IOMMU driver needs to poke into device details and their relations or the device driver needs to poke into IOMMU details.

There are no device details, this is just a module option in the gpu driver.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Well the GPU driver has knowledge whether it's a GPU inside of an APU to decide if it's valid. That information is part of the discovery table setup.

Where was that in patch 2?

amdgpu_device_use_perfopt()

Ah, sneaky, that looks like it just decodes from a a giant list of PCI IDs

Quoted 6 lines
Quoted 5 lines

The right way for this to work is to quirk it through the iommu driver so it can choose the fast mode, and not involve the GPU driver at all. Like we've done for every other GPU weirdness. And AMD should be making this work better by providing ACPI support so the iommu driver can understand how it should work without inspecting PCI IDs.

Quoted 6 lines

There is a heuristic that Vasant added recently that we detect APU from the IOMMU driver. We might be able to use that for now.

I'll take a look at what an incremental patch looks like on top of iommu/next that I think reworks all these paths the way you want. I should be able to post something next week.

ACPI is the right answer to these kinds of problems.

Jason

#12 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 25 lines · Jason Gunthorpe
Quoted 24 lines · Mario Limonciello
Quoted 21 lines · Jason Gunthorpe
Quoted 19 lines · Mario Limonciello
Quoted 6 lines · Jason Gunthorpe
Quoted 5 lines · Joerg Roedel
Quoted 3 lines · Jason Gunthorpe

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

Quoted 6 lines
Quoted 3 lines

This is a layering violation either way. Either the IOMMU driver needs to poke into device details and their relations or the device driver needs to poke into IOMMU details.

There are no device details, this is just a module option in the gpu driver.

Well the GPU driver has knowledge whether it's a GPU inside of an APU to decide if it's valid. That information is part of the discovery table setup.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Where was that in patch 2?

amdgpu_device_use_perfopt()

Ah, sneaky, that looks like it just decodes from a a giant list of PCI IDs

Actually; no. amdgpu has migrated away from PCI IDs and probes based on the "ATI vendor" + "display class" instead. As part of the probe sequence there is something called an IP discovery table pull from the platform that identifies all IP blocks in the hardware.

This IP discovery table will indicate graphics IP and that is mapped to relevant driver code. So for example GC 11.5.1 is what you find in a Strix Halo APU. If a future APU had exactly the same graphics IP but a different display IP it would still be GC 11.5.1.

This design was implemented about 4 years ago, and all SoCs (APU, dGPU and accelerator) since then use it.

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

The right way for this to work is to quirk it through the iommu driver so it can choose the fast mode, and not involve the GPU driver at all. Like we've done for every other GPU weirdness. And AMD should be making this work better by providing ACPI support so the iommu driver can understand how it should work without inspecting PCI IDs.

There is a heuristic that Vasant added recently that we detect APU from the IOMMU driver. We might be able to use that for now.

Quoted 7 lines
Quoted 3 lines

I'll take a look at what an incremental patch looks like on top of iommu/next that I think reworks all these paths the way you want. I should be able to post something next week.

ACPI is the right answer to these kinds of problems.

Jason

I'll discuss this with architects for the future programs.

For now as promissed I've worked out a patch [1] that keeps it all in iommu/amd per your suggestions. It is using the existing APU heuristic.

https://lore.kernel.org/linux-iommu/[email protected]/ [1]

#13 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 4 lines · Mario Limonciello

Actually; no. amdgpu has migrated away from PCI IDs and probes based on the "ATI vendor" + "display class" instead. As part of the probe sequence there is something called an IP discovery table pull from the platform that identifies all IP blocks in the hardware.

Oh, so that big table is not processing pci ids.. OK

Quoted 4 lines

This IP discovery table will indicate graphics IP and that is mapped to relevant driver code. So for example GC 11.5.1 is what you find in a Strix Halo APU. If a future APU had exactly the same graphics IP but a different display IP it would still be GC 11.5.1.

Move this stuff to drivers/firmware and iommu and GPU can access it together?

"IP discovery table" sure sounds like a platform firmware datablob to me at least?

Jason

#14 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 14 lines · Jason Gunthorpe
Quoted 4 lines · Mario Limonciello

Actually; no. amdgpu has migrated away from PCI IDs and probes based on the "ATI vendor" + "display class" instead. As part of the probe sequence there is something called an IP discovery table pull from the platform that identifies all IP blocks in the hardware.

Oh, so that big table is not processing pci ids.. OK

Quoted 4 lines

This IP discovery table will indicate graphics IP and that is mapped to relevant driver code. So for example GC 11.5.1 is what you find in a Strix Halo APU. If a future APU had exactly the same graphics IP but a different display IP it would still be GC 11.5.1.

Quoted 7 lines

Move this stuff to drivers/firmware and iommu and GPU can access it together?

"IP discovery table" sure sounds like a platform firmware datablob to me at least?

Jason

Yes; it comes from platform firmware.

Alex, what do you think of doing this?

#15 lore raw

RE: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Public

Quoted 35 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Monday, September 28, 2026 1:15 PM
To: Jason Gunthorpe <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Mario Limonciello <[email protected]>; Joerg Roedel <[email protected]>; [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]>; Derek J . Clark <[email protected]>
Subject: Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

Quoted 17 lines · Jason Gunthorpe
Quoted 4 lines · Mario Limonciello

Actually; no. amdgpu has migrated away from PCI IDs and probes based on the "ATI vendor" + "display class" instead. As part of the probe sequence there is something called an IP discovery table pull from the platform that identifies all IP blocks in the hardware.

Oh, so that big table is not processing pci ids.. OK

Quoted 4 lines

This IP discovery table will indicate graphics IP and that is mapped to relevant driver code. So for example GC 11.5.1 is what you find in a Strix Halo APU. If a future APU had exactly the same graphics IP but a different display IP it would still be GC 11.5.1.

Move this stuff to drivers/firmware and iommu and GPU can access it together?

Quoted 8 lines
Quoted 4 lines

"IP discovery table" sure sounds like a platform firmware datablob to me at least?

Jason

Yes; it comes from platform firmware.

Alex, what do you think of doing this?

It's not platform specific, it's AMD GPU specific. It also exists on dGPUs which will work in any platform. I guess we could put some sort of data table in there for this sort of thing but as it stands today, I don't really see it as being much different from PCI IDs with respect to the IOMMU. I think IVRS tables would be a better fit for this since they are supposed to describe the behavior of the IOMMU with respect to the devices present on the system.

Alex

#16 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

In reply to Jason Gunthorpe
Quoted 5 lines · Jason Gunthorpe
Quoted 1 line · Mario Limonciello

+EXPORT_SYMBOL_GPL(amd_iommu_enable_perfopt);

Last time we hardwired the GPU and IOMMU drivers together it was a huge mess to undo.

Every time a driver depends on an exact iommu driver is a major design problem.

Quoted 5 lines

Why does the GPU driver have to request this? Why can't the iommu driver know that this is a special device that can use this magic fast path and then auto set it when identity is asked for?

How does the GPU driver even know it is magic special?

Yes. And WTF is "perfopt" supposed to mean. Everything is a performance optimization.

maintainer
#17 lore raw

Re: [PATCH v2 1/2] iommu/amd: Add PerfOpt IOMMU performance optimization support

In reply to Mario Limonciello

include/linux/amd-iommu.h static inline int amd_iommu_snp_disable(void) { return 0; } · line 88

Quoted 10 lines · Mario Limonciello
include/linux/amd-iommu.h +10 -0
+#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

This commit broke build on i386, I fixed it up but please compile test on 32-bit next time.

-Joerg

#18 lore raw

PATCH v2 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.

---
v2:
* Add tag (Derek)
* Use -1 for default module option (Alex)
* Add a function to check whether to use perf opt Allows one place to control all the places for policy.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 50 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 12 ++++++
 3 files changed, 63 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 +50 -0

80 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +12 -0
index 5b08afde37baf..7b54ca8beeb4c 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 supported devices).
+ * 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 supported devices, 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
#19 lore raw
In reply to Mario Limonciello
Quoted 22 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.

v2:
* Rebase on 7.3-rc2
* Adjust amdgpu parameter behavior

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

Quoted 10 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  50 +++++
  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, 341 insertions(+)

Alex, Vasant, Joerg,

Gentle ping on this series.

Thanks,

Tested-by on the v2 series
#20 lore raw
In reply to Mario Limonciello
Quoted 4 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).

Quoted 9 lines

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.

Our GPU memory accessing benchmark confirms the improvement: without the patchset, GTT is 2x - 3x slower than VRAM, after this, the latency gap is almost gone (within 10%). Nice work!

Regards,
Boqun

Quoted 22 lines

v2:
* Rebase on 7.3-rc2
* Adjust amdgpu parameter behavior

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 |  50 +++++
 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, 341 insertions(+)
Signature · 1 line
2.43.0
maintainer
#21 lore raw
In reply to Mario Limonciello

Hi Alex,

Quoted 5 lines · Mario Limonciello

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 |  50 +++++
 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, 341 insertions(+)

What is your preference on what tree this should go through? The IOMMU changes are bigger, so my preference is the iommu tree, but for that I need your Ack on the GPU part. Or let me know whether you prefer this to go through your tree.

-Joerg

maintainer Acked-by
#22 lore raw

Public

Quoted 31 lines

-----Original Message-----
From: Joerg Roedel <[email protected]>
Sent: Thursday, September 24, 2026 7:43 AM
To: Deucher, Alexander <[email protected]>
Cc: Limonciello, Mario <[email protected]>; amd- [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]>
Subject: Re: [PATCH v2 0/2] IOMMU Performance Optimization support

Hi Alex,

Quoted 5 lines · Mario Limonciello

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 |  50 +++++
 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, 341 insertions(+)
Quoted 4 lines

What is your preference on what tree this should go through? The IOMMU changes are bigger, so my preference is the iommu tree, but for that I need your Ack on the GPU part. Or let me know whether you prefer this to go through your tree.

IOMMU tree is fine with me:

For the series.

Alex