Re: [RFC PATCH 10/15] virt: tdx-guest: Set up and accept private MMIO ranges
From: Jason Gunthorpe
Date: Thu Nov 19 2026 - 08:59:32 EST
On Thu, Nov 19, 2026 at 07:24:13PM +0800, Xiaoyao Li wrote:
> 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.
The host should having locking to prevent this kind of return code
right?
> >> 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?
Yes, Leon's trust level series should be part of this, ultimately you
can't change to lock unless the trist level is disabled/isolated and
you shouldn't be able to change away from that while the device is not
in unlocked or run.
I haven't seen anyone work on this detail yet though
Jason