Re: [RFC PATCH 10/15] virt: tdx-guest: Set up and accept private MMIO ranges
From: Xiaoyao Li
Date: Thu Nov 19 2026 - 06:24:33 EST
On 11/3/2026 6:38 AM, Edgecombe, Rick P wrote:
> On Thu, 2026-10-29 at 09:56 +0000, Duan, Zhenzhong wrote:
>> After thinking about this further, a second .run() attempt cannot recover
>> from partial MMIO acceptance with the current implementation. It starts
>> accepting ranges from the beginning, so it will encounter a re-acceptance
>> error on the first range successfully accepted by the previous attempt,
>> before reaching the range that originally failed.
>
> How does MMIO acceptance fail? Whose fault is it?
According to the Completion Status Codes defined for TDG.TDI.MMIO.ACCEPT in TDX
Connect ABI spec, it can fail due to various reason. I think most of them are
the fault of the host, and a few are guest fault.
The most interesting one is the TDX_OPERAND_BUSY due to contention on some
locks. E.g., when host is operating on the TDI, it fails to acquire the TDIMT lock.
For most of the lock contention, we can simply return error to userspace. The
interesting one is the contention on the GPA. If host is setting up the sept
mapping for the same gpa, do we want to retry in the guest kernel? or exit to
userspace with -EAGAIN to tell the .run() can be invoked again? or -EBUSY/other
error code?
>>
>> When .run() fails, the device is not accepted for driver attachment, so
>> there should be no driver MMIO accesses. Therefore, removing the
>> guest-side MMIO resource entries and freeing the descriptors in
>> tdx_tdi_mmio_teardown() should be safe. However, this cleanup does not
>> undo the MMIO acceptance already performed by the TDX module.
>>
>> There is no TDG.MMIO.UNACCEPT ABI to roll back those successful
>> acceptances. Recovery therefore requires unlocking the device through
>> the UNBIND hypercall, which asks the host to tear down the associated
>> MMIO mappings, before locking and accepting the device again.
The UNBIND is invoked by userspace. What if userspace doesn't do it? Do we need
to harden it that driver attachment will always fail when the TDI is locked but
not accepted?