Re: [PATCH v2 11/31] x86/virt/tdx: Make TDX Module initialize Extensions

Huang, Kai
2026-04-01T11:42:44Z

On Tue, 2026-03-31 at 22:58 +0800, Xu Yilun wrote:
> > > + /*
> > > + * ext_required == 0 means no need to call TDH.EXT.INIT, the Extensions
> > > + * are already working.
> >
> > How does this scenario happen exactly? And why not check it above at the
> > beginning? Before the allocation, so it doesn't need to free.
> >
> > Is there a scenario where the memory needs to be given, but the extension is
> > already inited?
>
> mm.. you are right. It leads to something absurd.
>
> I checked with TDX Module team again. The correct understanding is:
>
>  - TDX_FEATURES0_EXT bit shows Extensions is supported.
>  - optional feature bits are selected on TDH_SYS_CONFIG
>  - If one of the optional feature (e.g. TDX CONNECT) requires Extention,
>    memory_pool_required_pages > 0 && ext_required == 1. Otherwise no
>    need to initialize Extension.
>
> So yes, I should check memory_pool_required_pages && ext_required at the
> beginning.

My understanding is different:

Per spec, the 'EXT_REQUIRED' global metadata just means "Return true if the
TDH.EXT.INIT is required to be called", so I think, architecturally, it's
possible that one particular feature only requires additional memory pool
but doesn't explicitly need to call TDH.EXT.INIT. Or some feature may not
require any additional memory pool but needs TDH.EXT.INIT.  Or require both
(such as TDX Connect I presume).

We can safely assume 2) and 3) are not required if no feature is configured
in 1) (backward compatibility). But when there is, I think we can just:

1) If 'MEMORY_POOL_REQUIRED_PAGES' is not zero, do TDH.EXT.MEM.ADD
2) If 'EXT_REQUIRED' is true, do TDH.EXT.INIT