Re: [RFC PATCH 00/15] PCI/TSM: coco/tdx-guest: Implement TDX-Connect PCIe TDISP (phase2)

From: Xu Yilun

Date: Mon Nov 30 2026 - 05:00:39 EST


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

I would not say "guest doesn't care the mapping ...", guest absolutely
cares whether a GPA is correctly mapped to the expected MMIO...

> 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

... and yes TDX module helps guest to make the validation via TDG.TDI.MMIO.ACCEPT

> converted between shared/private back and forth runtime. During the 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.

The definition of TDX_PAGE_ALREADY_ACCEPTED is still not 100% clear to
me, does it mean:

1. A GPA is already accepted, regardless of where the GPA is mapped to.

Or

2. A GPA is already accepted && the GPA-to-MMIO mapping is also correct.

If it is the later, seems good to drop the error.

But AI tells me the module code implements the former, that seems a problem
we can't ignore.

Thanks

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