Re: [RFC PATCH 06/15] virt: tdx-guest: Support TDI bind and unbind operations
From: Xu Yilun
Date: Thu Nov 12 2026 - 08:07:24 EST
On Wed, Nov 11, 2026 at 09:44:42AM +0000, Tian, Kevin wrote:
> > From: Jason Gunthorpe <jgg@xxxxxxxxxx>
> > Sent: Wednesday, November 11, 2026 8:16 AM
> >
> > On Tue, Nov 10, 2026 at 10:25:07PM +0000, Edgecombe, Rick P wrote:
> > > On Tue, 2026-11-10 at 15:57 -0400, Jason Gunthorpe wrote:
> > > > On Tue, Nov 10, 2026 at 06:55:41PM +0000, Edgecombe, Rick P wrote:
> > > >
> > > > > Additionally, we should probably see if Jason has any opinion on the
> > types of
> > > > > errors that guest TSM would like to handle.
> > > >
> > > > Not at this point :\ And perhaps not at all.
> > > >
> > > > Most of this stuff will end up routing through userspace so it has to
> > > > be compressed into a errno.'
> > > >
> > > > The various VMM to guest specs like GHCI are going to define their own
> > > > contracts, and it is up to Intel to ensure that the full route from
> > > > this code -> attestation subsystem -> uapi -> vmm -> GHCI
> > > >
> > > > Preserves whatever semantics have been defined in the spec.
> > > >
> > > > I don't know the answer to the EBUSY question, other than
> > > > TSM/attestation will return that to userspace. Can your VMM and GHCI
> > > > sort it out?
>
> GHCI doesn't define a EBUSY error code. So it's more a TD internal policy.
>
> A status byte in the GHCI data buffer indicates whether the requested
> operation is completed by the VMM (successfully or with error). It's
> unreasonable to poll it indefinitely so the polling will be capped by a
> timeout. Then a 2nd request comes and observes previous request
> still in progress, then -EBUSY is returned.
>
> Such failures (timeout or busy) before attestation passes are just
> returned to userspace, as Jason suggested. it's fine.
>
> The interesting case is about such failures after attest e.g. unlock
> which is supposed to be a void operation. Maybe we don't need do
> anything special in tsm core - the secure firmware maintains the
> state machine so future lock will fail if the current state is not
> unlocked.
>
> Anyway the success or error code from GHCI is just a hint and
> untrusted.
>
> > >
> > > Kevin and Yilun are analyzing what kind of errors we should expect the VMM
> > to
> > > handle. But some of the cases Zhenzhong listed seem like they could be
> > > situations trusted IO guests could encounter generally. Like the example
> > > "[device] firmware hangs during lock/unlock". In that case unification in TSM
> > > could be nice.
>
> As long as we rely on the secure firmware to manage the TDI state machine
> properly, it doesn't matter whether an uncompleted lock/unlock is caused
> by device firmware hang, or any intermediate software layer serving the
> GHCI call.
>
> Generally for errors which confine to an assigned device, the guest just
> keeps running. In the end the related driver stack in the guest will capture
> the device error and quarantine the device in its own way.
>
> So the TD just needs to handle errors according to the GHCI spec:
>
> [GHCI general]
> TDG.VP.VMCALL_INVALID_OPERAND
> TDG.VP.VMCALL_SUBFUNC_UNSUPPORTED
>
> [TDCM specific]
> TDX_MODULE_ERROR
This error handling belongs to the host, guest can't understand.
> TDXIO_DEVICE_ERROR
This is actually DOE error according to GHCI spec.
> SPDM_MESSAGE_ERROR
> IDE_KM_MESSAGE_ERROR
The above 3 errors indicate the link is broken. Guest could handle them
by unplugging the device. But there are always link broken events at any
time, host should handle them, guest can expect a notification from host
to do the unplugging. That's another topic.
So for TSM operations, guest kernel just keep the TDISP state unchanged
and report error to user.
BTW: UNLOCK is not needed when link is broken. So always good to let
UNLOCK succeed.
> TDISP_MESSAGE_ERROR
> INVALID_STATE
These 2 are about TDISP, guest can keep the state machine unchanged, and
report error to user. According to TDISP spec, UNLOCK can't fail on
these 2 errors.
>
> For general errors let's follow the convention already established.
>
> for TDCM specific ones they are not useful then let's just return a
> single errno (e.g. -EIO) for all of them to userspace.
For LOCK/RUN/GET_DEV_INFO/GET_TDI_REPORT, I agree.
For UNLOCK, guest kernel could always return success. We are always safe
to move the device to untrusted mode.
>
> > >
> > > For errors that indicate uncooperative or buggy host, we elsewhere warn in
> > the
> > > TDX wrappers. But in coco, not handling an error in the caller can be an
> > avenue
> > > to attack the guest. So I guess we would commonly need to handle these
The secure firmware should guarantee the attack can't impact TSM
security. For DDOS attack, the guest could always move the device to
untrusted mode.
> > errors in
> > > the callers.
> >
> > Any failure to attest should just propogate to guest userspace and
> > userspace wil fail the attestation and not enable the device. This is
> > fine.
> >
> > All failure classes, including the cases where the guest is checking
> > digests/etc to confirm the host has done the right thing can work like
> > this.
>
> Agree
>
> >
> > > Zhenzhong had previously suggested a bool to set a device as bugged for the
> > > purpose of trying to continue guest execution as well as possible in the face
> > of
> > > host issues.
> >
> > It does not seem necessary to me, userspace is responsible. Since no
> > device evidence could possibly have been logged the VM would fail
> > attestation anyhow.
> >
>
> Yeah - as said even for errors after attest passes we could rely on secure
> firmware to do the right thing. Userspace requests unlock and downgrade
> the trust level to DISABLED. Failures will be caught in next attempt if
> unlock doesn't complete successfully.
>
> We don't need the guest kernel to explicitly mark the buggy state. :)