Re: [RFC PATCH 10/15] virt: tdx-guest: Set up and accept private MMIO ranges

From: Edgecombe, Rick P

Date: Thu Nov 19 2026 - 18:22:24 EST


On Thu, 2026-11-19 at 09:59 -0400, Jason Gunthorpe wrote:
> 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.

What are the ones with the guest? We have some existing issues with normal
accept. I'd prefer not to pile on.

> >
> > 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.

Oh, hmm. Binbin was going to look at the host priority bit TDX arch as a general
thing. Can you show this example to him?

>
> The host should having locking to prevent this kind of return code
> right?

One of the continual challenges on TDX is that every lock inside TDX is a try-
lock. When it hits any contention on any lock it aborts and returns these BUSY
errors. The caller can then retry. For extra "fun" the guest and the host calls
can contend the same locks.

So far between x86 and KVM we have been striving to navigate the contention. As
in don't try N times and give up, and also don't let some other component block
you forever. Instead we break through using various schemes or TDX module
implementation tweaks.

>
> > > > 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