Re: [PATCH v3 5/9] iommu/vt-d: Block GCMD and ECMD while acquired by the TDX module

From: Baolu Lu

Date: Wed Dec 02 2026 - 03:29:27 EST


On 12/2/2026 12:57 PM, Tian, Kevin wrote:
From: Baolu Lu<baolu.lu@xxxxxxxxxxxxxxx>
Sent: Thursday, November 26, 2026 10:11 AM

On 11/25/2026 11:49 AM, Tian, Kevin wrote:
From: Lu Baolu<baolu.lu@xxxxxxxxxxxxxxx>
Sent: Thursday, November 12, 2026 12:31 PM

+ * context (e.g. perf pmu::start/stop), so don't sleep; just reject
+ * the request.
+ */
+ if (iommu->tdxc_acquired) {
+ ret = -EBUSY;
+ goto err;
+ }
+
iommu_pmu_stop() doesn't check the return value of this. It's a void
function. So returning error here still breaks the perf feature.

we may need a way to disable iommu perf completely in the acquire
function.
Good catch. Returning an error there leaves events that look like
they're running but never count, or that can't be stopped.

I'll make perf events and TDX mode mutually exclusive instead:

- The iommu pmu counts its live events under register_lock.
- event_init() fails with -EBUSY while the IOMMU is acquired.
- acquire() fails with -EBUSY while any event exists.

Something like the following(compiled but not tested). Does this work
for you?
we could simply unregister iommu pmu at acquisition time? that makes
the entire capability disappeared when tdx is acquired, clearer than
presenting a capability w/o any usable counters...

Good idea. It's simpler, and it also means an open perf session can no
longer block TDX acquisition.

perf_pmu_unregister() now detaches live events instead of failing, so
dmar_tdx_acquire() can tear the pmu down unconditionally:

ret = dmar_tdx_reserve_did(iommu);
if (ret)
return ret;

/*
* Perf issues enhanced commands from callbacks that can't fail, and
* TDX mode blocks them.
*/
iommu_pmu_unregister(iommu);
free_iommu_pmu(iommu);

dmar_tdx_set_acquired(iommu, true);

Thanks,
baolu