RE: [RFC PATCH 00/15] PCI/TSM: coco/tdx-guest: Implement TDX-Connect PCIe TDISP (phase2)
From: Tian, Kevin
Date: Fri Nov 27 2026 - 03:15:30 EST
> From: Li, Xiaoyao <xiaoyao.li@xxxxxxxxx>
> Sent: Thursday, November 26, 2026 4:10 PM
>
> On 11/26/2026 1:47 AM, Edgecombe, Rick P wrote:
> > On Wed, 2026-11-25 at 16:32 +0800, Xiaoyao Li wrote:
> >> On 11/25/2026 3:41 AM, Edgecombe, Rick P wrote:
> >>> On Tue, 2026-11-24 at 14:01 +0800, Xiaoyao Li wrote:
> >>>> 1. The requirement of R8-R15 are reserved to 0 on TDG.DMAR.ACCEPT.
> >>>>
> >>>> This is the first leaf in TDCALL/SEAMCALL that explicitly requires some
> >>>> unused registers to be 0. Without justification of why it must to be
> >>>> such,
> >>>> we are going to propose to remove this requirement and it helps drop
> >>>> the
> >>>> PATCH 13.
TDG.VM.RD/WR and TDG.VP.RD/WR require RCX must be 0, so it's not
the first example.
[...]
> >>> So I'm thinking that old seamcalls were maybe incorrect and this new
> way is
> >>> correct. Yes we would need a new patch, but what if it was a simplication
> >>> patch
> >>> that got rid of all the seamcall variants and just always saved/restored?
> >>> Consider those premature optimization. Any problems?
> >>
> >> I agree an always unified saved/restored helper is a good thing if the
> >> additional overhead is not a concern.
> >
> > I think saving and restoring general purpose registers across a seamcall
> would
> > not be a big overhead given the amount of other work happening during a
> > seamcall. Probably small enough that we could not even have to measure it
> to
> > make the case for the patch. Any counter points?
>
> No. It looks doable to me.
>
> IIUC, you want us to set aside the decision of whether to remove the
> requirement
> of "R8-R15 are reserved to 0 on TDG.DMAR.ACCEPT". But to explore the
> direction
> of unifying the SEAMCALL/TDCALL helper to always save and restore the
> registers.
> If the unification is accepted, then whether "R8-R15 are reserved to 0 on
> TDG.DMAR.ACCEPT" won't matter much. Is my understand correct?
>
> <snip>
sounds reasonable.
> >>>> 4. TDX_PAGE_ALREADY_ACCEPTED is listed as the possible return code
> for
> >>>> TDG.TDI.MMIO.ACCEPT while the description of
> TDG.TDI.MMIO.ACCEPT reads:
> >>>>
> >>>> If the page is already MMIO_MAPPED, skip the page.
> >>>>
> >>>> They conflict with each other and lead to confusion.
> >>>
> >>> I'd think if the page size is incorrect it should return
> >>> TDX_MMIO_ACCEPT_SIZE_MISMATCH. If it is already accepted it should
> return
> >>> TDX_PAGE_ALREADY_ACCEPTED. In the case of mismatched size but
> already
> >>> accepted
> >>> page, ideally it would return TDX_PAGE_ALREADY_ACCEPTED, but it
> would be ok
> >>> if
> >>> it returns TDX_MMIO_ACCEPT_SIZE_MISMATCH.
> >>
> >> For private memory accept, if the mapping is not accepted by the guest yet:
> >>
> >> - when accept level > mapped level, SIZE_MISMATCH is returned so that
> guest
> >> can
> >> try accepting at a lower level.
> >>
> >> TDX_MMIO_ACCEPT_SIZE_MISMATCH is also returned for MMIO in such
> case. They
> >> are consistent.
> >>
> >> - when accept level < mapped level, EPT violation happens so that host
> can
> >> demote the mapping.
> >>
> >> There is no behavior defined for such case. But I think the reasonable
> >> option
> >> is also to EPT violation to the host to request the host maps at lower
> >> level.
> >> Forcing the guest to a higher level doesn't sound reasonable because the
> >> guest might not want the whole range of 2M MMIO is accessible by the
> >> driver.
> >>
> >> Regarding ALREADY_ACCEPT, we need it for private memory because a
> successful
> >> acceptance of private memory will clear the content to 0. TDX module
> don't
> >> know
> >> the intent of the guest, so it makes sense to return an error code to tell
> >> guest
> >> the page is already accepted without clearing it. If guest wants to clear the
> >> page, it can do it itself.
> >>
> >> But for MMIO, there is no such clearing semantic. Skip on the already-
> accepted
> >> MMIO page and return success seems to have no problem. Besides,
> private memory
> >> accept is operating on a single (huge) page but the MMIO accept is
> operating
> >> on
> >> a range. Return ALREADY_ACCEPT would increase the complexity on the
> output to
> >> tell the current status but without any real benefit.
> >
> > In the past discussion on private memory accept, someone made the point
> that re-
> > accepting memory should be fixed in the caller because it could be a
> weakness
> > used to attack the guest. If the kernel is confused, the host could zero
> memory
> > for the guest as part of some attack, or the new caller of accept could be
> > surprised by un-zeroed memory. This came up when the memory hot
> replug bug that
> > was eventually fixed in qemu partly to avoid allowing survival of re-
> accepting
> > memory in the guest. (and caught by the already accepted error code). We
> > discussed if the guest could handle the error by simply re-zeroing the
> memory
> > after a double accept. But then the debate was whether this would cover
> up bugs.
> >
> > I think a similar case could be made for MMIO, which is probably the
> purpose of
> > this error?
>
> Re-accept of memory has the effect to reset the memory content 0. But re-
> accept
> of MMIO doesn't do any harm, as I see it.
dumb question - why would the guest want to re-accept a memory, in
different sizes? is there a concrete example?
>
> > The guest could get confused about which MMIO address is mapped at a
> > particular GPA?
>
> I'm not sure. Guest doesn't care the mapping between MMIO and GPA. The
> TSM and
> secure firmware will help validate that the host VMM has mapped the GPA to
> the
> correct MMIO resource of the corresponding haredware device. And MMIO
> cannot be
> converted between shared/private back and forth runtime. During the
is it true? when the device transitions from locked to unlocked it then goes
from private to shared?
> lifetime,
> guest kernel only needs to accept the private MMIO once after the device is
> locked and accepted.
>
> > There must be some trusting intended as part of the operation or
> > why even have the MMIO accept in the guest in the first place.
>
> We have two reasons:
> 1. the same for the page accept. Accepting the page/MMIO by the guest
> prevents
> host from mapping a new page/MMIO to the GPA without guest's awareness.
>
> 2. TDX module will validate that the host maps the correct MMIO resource to
> the
> GPA.
>
> > So I think if we don't need the error, why even need the MMIO accept call
> at
> > all? But we probably want both.
>
> The ALREADY_ACCEPT error code and MMIO accept are two things. We care
> if the
> MMIO is accepted or not, but we don't care how many times the MMIO is
> accepted.
>
> > And I also don't see a major simplicity benefit to dropping error. What is
> the
> > savings?
>
> It makes the guest code simpler that the guest doesn't need to implement
> the
> skipping itself.
simpler compared to treating ALREADY_ACCEPT as success?