Re: [PATCH v2] iommu/amd: Make PerfOpt compulsory
From: Vasant Hegde
Date: Wed Sep 30 2026 - 11:26:19 EST
On 9/30/2026 7:09 PM, Mario Limonciello wrote:
> On 9/30/26 04:38, Vasant Hegde wrote:
>> Mario,
>>
.../...
>>> + 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().
Yeah. It makes sense.
-Vasant