Re: [PATCH v2] iommu/amd: Make PerfOpt compulsory

From: Mario Limonciello

Date: Wed Sep 30 2026 - 10:20:47 EST


On 9/30/26 04:38, Vasant Hegde wrote:
Mario,

On 9/29/2026 7:04 AM, Mario Limonciello (AMD) wrote:
PerfOpt is only a feature usable by integrated GPUs and only in identity
mode. Instead of leaving a policy knob in amdgpu, just turn it on when
an integrated GPU is in identity.

This drops quite a bit of compatibility glue. There was a refcounting
system, exported symbols, and device attach/detach logic. By just setting
it immediately it's a lot more straightforward.

Suggested-by: Jason Gunthorpe <jgg@xxxxxxxx>
Signed-off-by: Mario Limonciello (AMD) <superm1@xxxxxxxxxx>
---
v2:
* Move WARN_ON to amd_iommu_perfopt_clear()
* Make amd_iommu_perfopt_clear() void
* Drop unnecessary cleanup/create paths that unset feature
* Enable the feature in IOMMU if supported (per guidance in IVRS spec)
* Use existing check_feature() helper instead
---


.../...

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index c9b28e5e582ea..a1adb40d5b79d 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2345,6 +2345,35 @@ static void pdom_detach_iommu(struct amd_iommu *iommu,
spin_unlock_irqrestore(&pdom->lock, flags);
}
+/*
+ * Program or clear the per-IOMMU PerfOpt enable bit
+ * This allows a privileged internal GPU to be able to bypass IOMMU when
+ * in identity mode.
+ */
+int amd_iommu_perfopt_set(struct amd_iommu *iommu, bool enable)

Please move this to init.c file

Thanks, good suggestion.


+{
+ u32 old, val, readback;
+
+ if (!check_feature(FEATURE_PERF_OPT))
+ return enable ? -ENODEV : 0;
+
+ old = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET);
+ if (old == U32_MAX)
+ return -EIO;
+
+ val = enable ? old | PERF_OPT_EN : old & ~PERF_OPT_EN;
+ if (val != old)
+ writel(val, iommu->mmio_base + MMIO_PERF_OPT_OFFSET);
+ readback = readl(iommu->mmio_base + MMIO_PERF_OPT_OFFSET);
+ if (readback == U32_MAX ||
+ (readback & PERF_OPT_EN) != (val & PERF_OPT_EN)) {
+ dev_err(iommu->iommu.dev, "Failed to set PerfOpt to %d\n", enable);
+ return -EIO;
+ }
+

May be check return value before enabling dev_data->perfopt?

I thought about this.

Let me know what you think of the approach of clearing the bit in amd_iommu_efr on failures within amd_iommu_perfopt_set().

That would mean that dev_data->perfopt doesn't get enabled later.