Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
From: Edgecombe, Rick P
Date: Tue Nov 24 2026 - 16:11:24 EST
On Tue, 2026-11-24 at 20:59 +0800, Chao Gao wrote:
> On Tue, Nov 24, 2026 at 07:23:09AM +0800, Edgecombe, Rick P wrote:
> > On Mon, 2026-11-16 at 03:10 -0800, Chao Gao wrote:
> > > Setting up PCIe link encryption requires a secure channel to the device
> > > to exchange keys. This channel is an SPDM session over the device's PCI
> > > DOE mailbox.
> >
> > Probably SPDM and DOE mailbox need some 10,000ft summary.
>
> Does this sound better?
>
> SPDM is an industry-standard protocol for establishing trust between
> components. For TDX trusted I/O, the TDX module uses it to
> authenticate the device, collect its measurements and exchange IDE
> keys with it.
Yea.
>
> DOE is a mailbox in the device's configuration space, through which
> software exchanges messages with the device. DOE is only a transport
> and can carry different protocols. SPDM is one of them.
Can we explain that it is a PCIe thing too?
>
> > > Whenever the TDX module has a message for the device, the SEAMCALL
> > > returns with a dedicated status code. The host sends the message to the
> > > device and calls the SEAMCALL again with the device's response, until
> > > the SEAMCALL completes.
> >
> > SEAMCALL completes? Could mean the full extension operation or a single seamcall
> > execution.
>
> I meant the whole operation, i.e. setting up or tearing down the SPDM
> session. Will reword to make this clear.
Lets make it clear then.
>
> > > Call both SEAMCALLs in such a loop. The DOE transfer itself is a stub
> > > for now.
> >
> > I'd put something higher up explaining this is laying the ground work, rather
> > than announcing the gaps at the end.
>
> OK. Will add one sentence right after the background to say that this
> patch lays the groundwork.
>
> > > Pass the messages through two pages per device, one for each direction.
> > > One pair is enough because PCI/TSM serializes operations on a device.
> >
> > This probably needs more explanation.
>
> Several functions of a device may want to talk to the TDX module at
> the same time, and each of them may need SPDM message exchanges. But
> PCI/TSM serializes all operations on a device, so the pages are
> allocated once per device and not once per function.
I mean there is a buffer for request and a separate buffer for the response.
Once the request is sent, why can't the same buffer be used to read back the
response? This may be a lack of understanding by me of DOE.
>
> @Yilun, let me know if this understanding is wrong.
>
> > > +#define SPDM_CAP_HBEAT BIT(13)
> > > +#define SPDM_CAP_KEY_UPD BIT(14)
> > > +
> > > +struct spdm_config_info_t {
> > > + u32 vmm_spdm_cap;
> > > + u8 spdm_session_policy;
> > > + u8 certificate_slot_mask;
> > > + u8 raw_bitstream_requested;
> > > + u8 reserved[4089];
> > > +} __packed;
> >
> > This looks like more SPDM specific stuff in TDX. Do really know other vendors
> > need it? We should at least group it in a header such that it is clear which
> > things are SPDM spec and which are TDX.
>
> This structure is not from the SPDM spec. It is an ABI structure
> defined by the TDX module, and it is passed to TDH.SPDM.CONNECT.
Ah ok, let's name it tdx something then.
>
> But yes, there is some SPDM-specific stuff in this series. I will try
> to separate it from the TDX stuff.
>
> > > + struct page *in_msg;
> > > + struct page *out_msg;
> >
> > SNP and TDX both have the DOE mailbox shuffling done by the host, right? So why
> > doesn't TSM allocate and provide these buffers?
> >
> > Oh looking at the code I'm now very confused. The request for SNP is in private
> > memory? The SNP commit has very little info to explain what is going on there.
>
> TDX and SNP have different requirements for the buffers. TDX needs no
> special handling, and both pages are normal host memory. As far as I
> can tell from the code, SNP makes its request buffer a firmware-owned
> page. So it is not guest private memory, but it is not a normal host
> page either. I guess that is part of the reason why each TSM driver
> allocates its own buffers.
Yea that is how it looked to me too.
>
> > > + spdm_conf->certificate_slot_mask = 0xff;
> >
> > Can we not have the magic number? I guess it means any?
>
> Sure, will remove the magic number. 0xff means getting the
> certificates in all slots (0-7) of the device.
>
> As a heads-up, this code will go away anyway when we switch to the new
> CTLV attestation framework.
>
> > > + do {
> > > + mutex_lock(&tdx_spdm_lock);
> >
> > The fact that TSM protects us from the buffers getting clobbered by another
> > request, but we still need the mutex only around the call is a bit hidden. I'd
> > think it at least needs a comment. But since the tdx_spdm_lock is really a TDX
> > module specific limitation, why not put it inside the SEAMCALL wrappers? It
> > seems more related to core TDX module setup type things.
>
> I like this idea. The concurrency limit is on the SEAMCALLs
> themselves, not on the SPDM setup/teardown flow, so the lock fits
> better in the SEAMCALL wrappers.
>
> > > + ret = -ENOMEM;
> > > + in_msg_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
> > > + if (!in_msg_page)
> > > + return ret;
> > > +
> > > + out_msg_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
> > > + if (!out_msg_page)
> > > + goto out_free_in_msg;
> >
> > Maybe dumb question, but why do we need two buffers for this? After we post the
> > request can't we just read it back the response to the same buffer? It doesn't
> > seem DOE code is setup for that though.
>
> pci_doe() takes separate buffers for the request and the response, and
> so does TDH.SPDM.CONNECT.
>
> > > +out_spdm_delete:
> > > + tdx_spdm_delete(tlink);
> >
> > We might some basics explanation of the SPDM operations are. create, disconnect,
> > delete, etc. What about adding some comments across the patches that make it
> > clear when and where each needs to be called?
>
> Yes. Will add a high-level description of the SPDM operations to the
> changelog, and comments above the functions where needed.