Re: [RFC PATCH 1/7] coco/tdx-host: Create metadata for an SPDM session

From: Chao Gao

Date: Sun Nov 29 2026 - 21:50:32 EST


On Sat, Nov 21, 2026 at 10:05:50AM +0800, Edgecombe, Rick P wrote:
>On Mon, 2026-11-16 at 03:10 -0800, Chao Gao wrote:
>> The TDX module talks to the device over a Security Protocol and Data
>> Model (SPDM) session. It needs host memory for each session's metadata,
>> and reports the number of pages required in its global metadata.
>
>Since we usually talk about metadata and mean the global metadata, we will
>probably need to explain what session metadata is. Is it just data?

Yes. It is used to keep the TDX module's own state for one SPDM
session, for example, the session keys.

>>
>> When setting up an SPDM session, allocate the memory and hand it to the
>> TDX module with TDH.SPDM.CREATE. Keep the returned session ID for later
>> SEAMCALLs.
>>
>
>This is getting to be a pretty familiar concept. TDX needs per-something scoped
>memory. Give it to the TDX module per some seamcall. Can we make it sounds
>especially ordinary and then just call out any thing that is different?

How about:

To set up link encryption, the TDX module talks to the device over
a Security Protocol and Data Model (SPDM) session.

An SPDM session is an object like a TD or a vCPU. They are managed
by the TDX module in the same way. Each has SEAMCALLs to create and
delete it, and the TDX module keeps its state for the object in
memory provided by the host.

Allocate the memory when setting up a session and give it to the
TDX module. Get it back when tearing the session down.

Creating a session returns a session ID, which later SEAMCALLs use
to identify the session. Store it.

>> When tearing the session down, reclaim the memory with
>> TDH.SPDM.DELETE. If that fails, leak the memory, as the TDX module may
>> still be using it.
>
>When would it fail?

It shouldn't in practice. Per the spec, it fails if the input is wrong,
if the session is still in use (by another SEAMCALL or by an IDE
stream that has not been torn down), or if the TDX module extension
hit a fatal error. Any of them would be unexpected. They mean a bug in
the kernel or in the TDX module, or an earlier failure to tear down
the IDE stream.

I would just say in the changelog that TDH.SPDM.DELETE should not
fail, and WARN_ON() and leak the memory if it does.

>> +#define TDISP_FUNC_ID_SEG_VALID BIT(24)
>> +
>> +static inline u32 tdisp_func_id(struct pci_dev *pdev)
>> +{
>> + u32 func_id;
>> +
>> + func_id = FIELD_PREP(TDISP_FUNC_ID_SEGMENT, pci_domain_nr(pdev->bus));
>> + if (func_id)
>> + func_id |= TDISP_FUNC_ID_SEG_VALID;
>> + func_id |= FIELD_PREP(TDISP_FUNC_ID,
>> + PCI_DEVID(pdev->bus->number, pdev->devfn));
>> +
>> + return func_id;
>> +}
>
>Is this TDISP specific encoding or a TDX-TDISP specific encoding? I think TDISP.
>There isn't a more general place to put it?

TDISP defines it. There is no TDISP header for such definitions yet.
AMD passes the segment and the BDF to its firmware separately. So it
looks like TDX is the first user of this encoding. I will add a
pci-tdisp.h for it.

>> + return -ENXIO;
>> +
>> + nr_pages = tdx_sysinfo->tdx_connect.spdm_mt_page_count;
>> +
>> + spdm_mt = alloc_pages_exact(nr_pages * PAGE_SIZE,
>> + GFP_KERNEL | __GFP_ZERO);
>
>Why zero?

It is not needed. Will drop it.

>> +static int tdx_spdm_session_setup(struct tdx_tsm_link *tlink)
>> +{
>> + return tdx_spdm_create(tlink);
>
>Hmm, its not clear from this patch why we would need so many levels of wrapper
>for the setup/teardown seamcall. But it grows in later patches. But it looks
>weird in this patch and will probably throw off the tip review.

Indeed. I will drop the wrappers from this patch and add them in the
later patches (if necessary).

>> }
>>
>> @@ -66,6 +165,7 @@ static struct pci_tsm *tdx_tsm_link_pf0_probe(struct tsm_dev *tsm_dev,
>> if (rc)
>> return NULL;
>>
>> + tlink->func_id = tdisp_func_id(pdev);
>
>Why is this here instead of tdx_spdm_create()?

I would drop the cached value. The ID can always be derived from the
pci_dev, so tdx_spdm_create() can compute it when needed.