* [RFC PATCH 1/7] coco/tdx-host: Create metadata for an SPDM session
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
@ 2026-11-16 11:10 ` Chao Gao
2026-11-21 2:05 ` Edgecombe, Rick P
2026-11-16 11:10 ` [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device Chao Gao
` (6 subsequent siblings)
7 siblings, 1 reply; 29+ messages in thread
From: Chao Gao @ 2026-11-16 11:10 UTC (permalink / raw)
To: linux-kernel, linux-coco, kvm
Cc: rick.p.edgecombe, kevin.tian, yilun.xu, chao.p.peng, baolu.lu,
chao.gao, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau
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.
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. 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.
Based on work by Yilun and Zhenzhong.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
arch/x86/include/asm/tdx_global_metadata.h | 1 +
arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 6 ++
drivers/virt/coco/tdx-host/main.c | 104 +++++++++++++++++++-
3 files changed, 109 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/tdx_global_metadata.h b/arch/x86/include/asm/tdx_global_metadata.h
index e5e54159ad36..537e872eeb0e 100644
--- a/arch/x86/include/asm/tdx_global_metadata.h
+++ b/arch/x86/include/asm/tdx_global_metadata.h
@@ -52,6 +52,7 @@ struct tdx_sys_info_ext {
};
struct tdx_sys_info_connect {
+ u16 spdm_mt_page_count;
u16 iommu_mt_page_count;
};
diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
index 9b46f34cb469..f20e029f240b 100644
--- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
+++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
@@ -144,6 +144,12 @@ static __init int get_tdx_sys_info_connect(struct tdx_sys_info_connect *sysinfo_
int ret;
u64 val;
+ ret = read_sys_metadata_field(0x3000000100000002, &val);
+ if (ret)
+ return ret;
+
+ sysinfo_connect->spdm_mt_page_count = val;
+
ret = read_sys_metadata_field(0x3000000100000003, &val);
if (ret)
return ret;
diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
index a815dbe5127a..919e77ae2326 100644
--- a/drivers/virt/coco/tdx-host/main.c
+++ b/drivers/virt/coco/tdx-host/main.c
@@ -5,6 +5,7 @@
* Copyright (C) 2025 Intel Corporation
*/
+#include <linux/bitfield.h>
#include <linux/device/faux.h>
#include <linux/firmware.h>
#include <linux/module.h>
@@ -26,8 +27,30 @@ static const struct x86_cpu_id tdx_host_ids[] = {
};
MODULE_DEVICE_TABLE(x86cpu, tdx_host_ids);
+#define TDISP_FUNC_ID GENMASK(15, 0)
+#define TDISP_FUNC_ID_SEGMENT GENMASK(23, 16)
+#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;
+}
+
struct tdx_tsm_link {
struct pci_tsm_pf0 pci;
+ u32 func_id;
+
+ u64 spdm_id;
+ unsigned int spdm_mt_nr_pages;
+ void *spdm_mt;
};
static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
@@ -35,21 +58,97 @@ static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
return container_of(tsm, struct tdx_tsm_link, pci.base_tsm);
}
+static int tdx_spdm_create(struct tdx_tsm_link *tlink)
+{
+ const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
+ struct tdx_hpa_list_info info;
+ unsigned int nr_pages;
+ u64 spdm_id, sret;
+ void *spdm_mt;
+ int ret;
+
+ if (!tdx_sysinfo)
+ 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);
+ if (!spdm_mt)
+ return -ENOMEM;
+
+ ret = tdx_hpa_list_info_setup(&info, spdm_mt, nr_pages);
+ if (ret)
+ goto out_free_spdm_mt;
+
+ sret = tdh_spdm_create(tlink->func_id, &info, &spdm_id);
+
+ tdx_hpa_list_info_free(&info);
+
+ if (sret) {
+ ret = -EIO;
+ goto out_free_spdm_mt;
+ }
+
+ tlink->spdm_id = spdm_id;
+ tlink->spdm_mt = spdm_mt;
+ tlink->spdm_mt_nr_pages = nr_pages;
+ return 0;
+
+out_free_spdm_mt:
+ free_pages_exact(spdm_mt, nr_pages * PAGE_SIZE);
+ return ret;
+}
+
+static void tdx_spdm_delete(struct tdx_tsm_link *tlink)
+{
+ struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
+ u64 sret;
+
+ sret = tdh_spdm_delete(tlink->spdm_id);
+ if (sret) {
+ /* leak the metadata pages */
+ pci_err(pdev, "fail to delete spdm 0x%llx\n", sret);
+ return;
+ }
+
+ free_pages_exact(tlink->spdm_mt, tlink->spdm_mt_nr_pages * PAGE_SIZE);
+}
+
+static int tdx_spdm_session_setup(struct tdx_tsm_link *tlink)
+{
+ return tdx_spdm_create(tlink);
+}
+
+static void tdx_spdm_session_teardown(struct tdx_tsm_link *tlink)
+{
+ tdx_spdm_delete(tlink);
+}
+
static int tdx_tsm_link_connect(struct pci_dev *pdev)
{
+ struct tdx_tsm_link *tlink = to_tdx_tsm_link(pdev->tsm);
int ret;
ret = tdx_iommu_get(pdev);
if (ret)
return ret;
- /* TDISP connect is not implemented yet. */
+ ret = tdx_spdm_session_setup(tlink);
+ if (ret)
+ goto out_iommu_put;
+ return 0;
+
+out_iommu_put:
tdx_iommu_put(pdev);
- return -ENXIO;
+ return ret;
}
static void tdx_tsm_link_disconnect(struct pci_dev *pdev)
{
+ struct tdx_tsm_link *tlink = to_tdx_tsm_link(pdev->tsm);
+
+ tdx_spdm_session_teardown(tlink);
tdx_iommu_put(pdev);
}
@@ -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);
return &no_free_ptr(tlink)->pci.base_tsm;
}
--
2.52.0
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 1/7] coco/tdx-host: Create metadata for an SPDM session
2026-11-16 11:10 ` [RFC PATCH 1/7] coco/tdx-host: Create metadata for an SPDM session Chao Gao
@ 2026-11-21 2:05 ` Edgecombe, Rick P
2026-11-30 2:50 ` Chao Gao
0 siblings, 1 reply; 29+ messages in thread
From: Edgecombe, Rick P @ 2026-11-21 2:05 UTC (permalink / raw)
To: kvm, linux-coco, linux-kernel, Gao, Chao
Cc: Xu, Yilun, dave.hansen, baolu.lu, Peng, Chao P, bp, mingo, x86,
tglx, Tian, Kevin, hpa, kas
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?
>
> 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?
> 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?
>
> Based on work by Yilun and Zhenzhong.
>
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
> arch/x86/include/asm/tdx_global_metadata.h | 1 +
> arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 6 ++
> drivers/virt/coco/tdx-host/main.c | 104 +++++++++++++++++++-
> 3 files changed, 109 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/tdx_global_metadata.h b/arch/x86/include/asm/tdx_global_metadata.h
> index e5e54159ad36..537e872eeb0e 100644
> --- a/arch/x86/include/asm/tdx_global_metadata.h
> +++ b/arch/x86/include/asm/tdx_global_metadata.h
> @@ -52,6 +52,7 @@ struct tdx_sys_info_ext {
> };
>
> struct tdx_sys_info_connect {
> + u16 spdm_mt_page_count;
> u16 iommu_mt_page_count;
> };
>
> diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
> index 9b46f34cb469..f20e029f240b 100644
> --- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
> +++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
> @@ -144,6 +144,12 @@ static __init int get_tdx_sys_info_connect(struct tdx_sys_info_connect *sysinfo_
> int ret;
> u64 val;
>
> + ret = read_sys_metadata_field(0x3000000100000002, &val);
> + if (ret)
> + return ret;
> +
> + sysinfo_connect->spdm_mt_page_count = val;
> +
We'll hopefully see this hunk get updated once the metadata cleanup series
lands.
> ret = read_sys_metadata_field(0x3000000100000003, &val);
> if (ret)
> return ret;
> diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
> index a815dbe5127a..919e77ae2326 100644
> --- a/drivers/virt/coco/tdx-host/main.c
> +++ b/drivers/virt/coco/tdx-host/main.c
> @@ -5,6 +5,7 @@
> * Copyright (C) 2025 Intel Corporation
> */
>
> +#include <linux/bitfield.h>
> #include <linux/device/faux.h>
> #include <linux/firmware.h>
> #include <linux/module.h>
> @@ -26,8 +27,30 @@ static const struct x86_cpu_id tdx_host_ids[] = {
> };
> MODULE_DEVICE_TABLE(x86cpu, tdx_host_ids);
>
> +#define TDISP_FUNC_ID GENMASK(15, 0)
> +#define TDISP_FUNC_ID_SEGMENT GENMASK(23, 16)
> +#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?
> +
> struct tdx_tsm_link {
> struct pci_tsm_pf0 pci;
> + u32 func_id;
> +
> + u64 spdm_id;
> + unsigned int spdm_mt_nr_pages;
> + void *spdm_mt;
> };
>
> static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
> @@ -35,21 +58,97 @@ static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
> return container_of(tsm, struct tdx_tsm_link, pci.base_tsm);
> }
>
> +static int tdx_spdm_create(struct tdx_tsm_link *tlink)
> +{
> + const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
> + struct tdx_hpa_list_info info;
> + unsigned int nr_pages;
> + u64 spdm_id, sret;
> + void *spdm_mt;
> + int ret;
> +
> + if (!tdx_sysinfo)
> + 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?
> + if (!spdm_mt)
> + return -ENOMEM;
> +
> + ret = tdx_hpa_list_info_setup(&info, spdm_mt, nr_pages);
> + if (ret)
> + goto out_free_spdm_mt;
> +
> + sret = tdh_spdm_create(tlink->func_id, &info, &spdm_id);
> +
> + tdx_hpa_list_info_free(&info);
> +
> + if (sret) {
> + ret = -EIO;
> + goto out_free_spdm_mt;
> + }
> +
> + tlink->spdm_id = spdm_id;
> + tlink->spdm_mt = spdm_mt;
> + tlink->spdm_mt_nr_pages = nr_pages;
> + return 0;
> +
> +out_free_spdm_mt:
> + free_pages_exact(spdm_mt, nr_pages * PAGE_SIZE);
> + return ret;
> +}
> +
> +static void tdx_spdm_delete(struct tdx_tsm_link *tlink)
> +{
> + struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
> + u64 sret;
> +
> + sret = tdh_spdm_delete(tlink->spdm_id);
> + if (sret) {
> + /* leak the metadata pages */
> + pci_err(pdev, "fail to delete spdm 0x%llx\n", sret);
> + return;
> + }
> +
> + free_pages_exact(tlink->spdm_mt, tlink->spdm_mt_nr_pages * PAGE_SIZE);
> +}
> +
> +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.
> +}
> +
> +static void tdx_spdm_session_teardown(struct tdx_tsm_link *tlink)
> +{
> + tdx_spdm_delete(tlink);
> +}
> +
> static int tdx_tsm_link_connect(struct pci_dev *pdev)
> {
> + struct tdx_tsm_link *tlink = to_tdx_tsm_link(pdev->tsm);
> int ret;
>
> ret = tdx_iommu_get(pdev);
> if (ret)
> return ret;
>
> - /* TDISP connect is not implemented yet. */
> + ret = tdx_spdm_session_setup(tlink);
> + if (ret)
> + goto out_iommu_put;
> + return 0;
> +
> +out_iommu_put:
> tdx_iommu_put(pdev);
> - return -ENXIO;
> + return ret;
> }
>
> static void tdx_tsm_link_disconnect(struct pci_dev *pdev)
> {
> + struct tdx_tsm_link *tlink = to_tdx_tsm_link(pdev->tsm);
> +
> + tdx_spdm_session_teardown(tlink);
> tdx_iommu_put(pdev);
> }
>
> @@ -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()?
> return &no_free_ptr(tlink)->pci.base_tsm;
> }
>
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 1/7] coco/tdx-host: Create metadata for an SPDM session
2026-11-21 2:05 ` Edgecombe, Rick P
@ 2026-11-30 2:50 ` Chao Gao
0 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-30 2:50 UTC (permalink / raw)
To: Edgecombe, Rick P
Cc: kvm, linux-coco, linux-kernel, Xu, Yilun, dave.hansen, baolu.lu,
Peng, Chao P, bp, mingo, x86, tglx, Tian, Kevin, hpa, kas
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.
^ permalink raw reply [flat|nested] 29+ messages in thread
* [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
2026-11-16 11:10 ` [RFC PATCH 1/7] coco/tdx-host: Create metadata for an SPDM session Chao Gao
@ 2026-11-16 11:10 ` Chao Gao
2026-11-23 23:23 ` Edgecombe, Rick P
2026-11-16 11:10 ` [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE Chao Gao
` (5 subsequent siblings)
7 siblings, 1 reply; 29+ messages in thread
From: Chao Gao @ 2026-11-16 11:10 UTC (permalink / raw)
To: linux-kernel, linux-coco, kvm
Cc: rick.p.edgecombe, kevin.tian, yilun.xu, chao.p.peng, baolu.lu,
chao.gao, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau
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.
The TDX module cannot access the DOE mailbox but needs to exchange SPDM
messages with the device, so the host relays SPDM messages between the
two.
TDH.SPDM.CONNECT establishes the session and TDH.SPDM.DISCONNECT tears
it down. Both may need several message exchanges with the device.
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.
Call both SEAMCALLs in such a loop. The DOE transfer itself is a stub
for now.
Pass the messages through two pages per device, one for each direction.
One pair is enough because PCI/TSM serializes operations on a device.
The TDX module limits how many TDH.SPDM.CONNECT and TDH.SPDM.DISCONNECT
calls can run at the same time. The limit is implementation-specific,
and a call over the limit fails with TDX_OPERAND_BUSY. For simplicity,
serialize them across all devices with a mutex.
Based on work by Yilun.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
arch/x86/include/asm/shared/tdx_errno.h | 1 +
drivers/virt/coco/tdx-host/main.c | 131 +++++++++++++++++++++++-
2 files changed, 130 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/shared/tdx_errno.h b/arch/x86/include/asm/shared/tdx_errno.h
index ee411b360e20..6581cec7e097 100644
--- a/arch/x86/include/asm/shared/tdx_errno.h
+++ b/arch/x86/include/asm/shared/tdx_errno.h
@@ -27,6 +27,7 @@
#define TDX_EPT_WALK_FAILED 0xC0000B0000000000ULL
#define TDX_EPT_ENTRY_STATE_INCORRECT 0xC0000B0D00000000ULL
#define TDX_METADATA_FIELD_NOT_READABLE 0xC0000C0200000000ULL
+#define TDX_SPDM_REQUEST 0x00000F5700000000ULL
/*
* TDX module operand ID, appears in 31:0 part of error code as
diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
index 919e77ae2326..32755d70dac5 100644
--- a/drivers/virt/coco/tdx-host/main.c
+++ b/drivers/virt/coco/tdx-host/main.c
@@ -44,11 +44,26 @@ static inline u32 tdisp_func_id(struct pci_dev *pdev)
return func_id;
}
+#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;
+
+static_assert(sizeof(struct spdm_config_info_t) == 4096);
+
struct tdx_tsm_link {
struct pci_tsm_pf0 pci;
u32 func_id;
u64 spdm_id;
+ struct page *in_msg;
+ struct page *out_msg;
unsigned int spdm_mt_nr_pages;
void *spdm_mt;
};
@@ -58,9 +73,89 @@ static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
return container_of(tsm, struct tdx_tsm_link, pci.base_tsm);
}
+static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
+{
+ /* TODO: implement the PCI DOE transfer */
+ return 0;
+}
+
+/*
+ * When serving SEAMCALLs, the TDX module extensions work like service thread
+ * pools. The number of service threads is limited per service type (or
+ * "per extension" in terms of TDX). When the host issues a request via
+ * SEAMCALL but the TDX module can't find an available thread, it returns
+ * TDX_OPERAND_BUSY. Currently the thread number limit for the TDISP extension
+ * is 1. So a mutex could work to prevent SEAMCALL busy returns.
+ */
+static DEFINE_MUTEX(tdx_spdm_lock);
+
+static int tdx_spdm_xfer_handler(struct tdx_tsm_link *tlink, u64 sret,
+ u64 out_msg_sz)
+{
+ int ret;
+
+ if (sret == TDX_SPDM_REQUEST) {
+ ret = tdx_spdm_msg_exchange(tlink);
+ if (ret < 0)
+ return ret;
+
+ return -EAGAIN;
+ }
+
+ if (sret == TDX_SUCCESS)
+ return 0;
+
+ return -EIO;
+}
+
+static int tdx_spdm_session_connect(struct tdx_tsm_link *tlink)
+{
+ struct spdm_config_info_t *spdm_conf;
+ u64 sret, out_msg_sz;
+ int ret;
+
+ /* create & fill SPDM configuration buffer - a single page */
+ spdm_conf = kzalloc_obj(*spdm_conf);
+ if (!spdm_conf)
+ return -ENOMEM;
+
+ spdm_conf->certificate_slot_mask = 0xff;
+
+ do {
+ mutex_lock(&tdx_spdm_lock);
+ sret = tdh_spdm_connect(tlink->spdm_id,
+ virt_to_page(spdm_conf),
+ tlink->in_msg, tlink->out_msg,
+ NULL, &out_msg_sz);
+ mutex_unlock(&tdx_spdm_lock);
+ ret = tdx_spdm_xfer_handler(tlink, sret, out_msg_sz);
+ } while (ret == -EAGAIN);
+
+ kfree(spdm_conf);
+
+ return ret;
+}
+
+static void tdx_spdm_session_disconnect(struct tdx_tsm_link *tlink)
+{
+ u64 sret, out_msg_sz;
+ int ret;
+
+ do {
+ mutex_lock(&tdx_spdm_lock);
+ sret = tdh_spdm_disconnect(tlink->spdm_id, tlink->in_msg,
+ tlink->out_msg, &out_msg_sz);
+ mutex_unlock(&tdx_spdm_lock);
+ ret = tdx_spdm_xfer_handler(tlink, sret, out_msg_sz);
+ } while (ret == -EAGAIN);
+
+ WARN_ON(ret);
+}
+
static int tdx_spdm_create(struct tdx_tsm_link *tlink)
{
const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
+ struct page *in_msg_page, *out_msg_page;
struct tdx_hpa_list_info info;
unsigned int nr_pages;
u64 spdm_id, sret;
@@ -70,12 +165,21 @@ static int tdx_spdm_create(struct tdx_tsm_link *tlink)
if (!tdx_sysinfo)
return -ENXIO;
+ 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;
+
nr_pages = tdx_sysinfo->tdx_connect.spdm_mt_page_count;
spdm_mt = alloc_pages_exact(nr_pages * PAGE_SIZE,
GFP_KERNEL | __GFP_ZERO);
if (!spdm_mt)
- return -ENOMEM;
+ goto out_free_out_msg;
ret = tdx_hpa_list_info_setup(&info, spdm_mt, nr_pages);
if (ret)
@@ -92,11 +196,17 @@ static int tdx_spdm_create(struct tdx_tsm_link *tlink)
tlink->spdm_id = spdm_id;
tlink->spdm_mt = spdm_mt;
+ tlink->in_msg = in_msg_page;
+ tlink->out_msg = out_msg_page;
tlink->spdm_mt_nr_pages = nr_pages;
return 0;
out_free_spdm_mt:
free_pages_exact(spdm_mt, nr_pages * PAGE_SIZE);
+out_free_out_msg:
+ __free_page(out_msg_page);
+out_free_in_msg:
+ __free_page(in_msg_page);
return ret;
}
@@ -112,16 +222,33 @@ static void tdx_spdm_delete(struct tdx_tsm_link *tlink)
return;
}
+ __free_page(tlink->in_msg);
+ __free_page(tlink->out_msg);
free_pages_exact(tlink->spdm_mt, tlink->spdm_mt_nr_pages * PAGE_SIZE);
}
static int tdx_spdm_session_setup(struct tdx_tsm_link *tlink)
{
- return tdx_spdm_create(tlink);
+ int ret;
+
+ ret = tdx_spdm_create(tlink);
+ if (ret)
+ return ret;
+
+ ret = tdx_spdm_session_connect(tlink);
+ if (ret)
+ goto out_spdm_delete;
+
+ return 0;
+
+out_spdm_delete:
+ tdx_spdm_delete(tlink);
+ return ret;
}
static void tdx_spdm_session_teardown(struct tdx_tsm_link *tlink)
{
+ tdx_spdm_session_disconnect(tlink);
tdx_spdm_delete(tlink);
}
--
2.52.0
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-16 11:10 ` [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device Chao Gao
@ 2026-11-23 23:23 ` Edgecombe, Rick P
2026-11-24 12:59 ` Chao Gao
0 siblings, 1 reply; 29+ messages in thread
From: Edgecombe, Rick P @ 2026-11-23 23:23 UTC (permalink / raw)
To: kvm, linux-coco, linux-kernel, Gao, Chao
Cc: Xu, Yilun, dave.hansen, baolu.lu, Peng, Chao P, bp, mingo, x86,
tglx, Tian, Kevin, hpa, kas
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.
>
> The TDX module cannot access the DOE mailbox but needs to exchange SPDM
> messages with the device, so the host relays SPDM messages between the
> two.
>
> TDH.SPDM.CONNECT establishes the session and TDH.SPDM.DISCONNECT tears
> it down. Both may need several message exchanges with the device.
> 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.
>
> 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.
>
> 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.
>
> The TDX module limits how many TDH.SPDM.CONNECT and TDH.SPDM.DISCONNECT
> calls can run at the same time. The limit is implementation-specific,
> and a call over the limit fails with TDX_OPERAND_BUSY. For simplicity,
> serialize them across all devices with a mutex.
>
> Based on work by Yilun.
>
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
> arch/x86/include/asm/shared/tdx_errno.h | 1 +
> drivers/virt/coco/tdx-host/main.c | 131 +++++++++++++++++++++++-
> 2 files changed, 130 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/shared/tdx_errno.h b/arch/x86/include/asm/shared/tdx_errno.h
> index ee411b360e20..6581cec7e097 100644
> --- a/arch/x86/include/asm/shared/tdx_errno.h
> +++ b/arch/x86/include/asm/shared/tdx_errno.h
> @@ -27,6 +27,7 @@
> #define TDX_EPT_WALK_FAILED 0xC0000B0000000000ULL
> #define TDX_EPT_ENTRY_STATE_INCORRECT 0xC0000B0D00000000ULL
> #define TDX_METADATA_FIELD_NOT_READABLE 0xC0000C0200000000ULL
> +#define TDX_SPDM_REQUEST 0x00000F5700000000ULL
>
> /*
> * TDX module operand ID, appears in 31:0 part of error code as
> diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
> index 919e77ae2326..32755d70dac5 100644
> --- a/drivers/virt/coco/tdx-host/main.c
> +++ b/drivers/virt/coco/tdx-host/main.c
> @@ -44,11 +44,26 @@ static inline u32 tdisp_func_id(struct pci_dev *pdev)
> return func_id;
> }
>
> +#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.
> +
> +static_assert(sizeof(struct spdm_config_info_t) == 4096);
> +
> struct tdx_tsm_link {
> struct pci_tsm_pf0 pci;
> u32 func_id;
>
> u64 spdm_id;
> + 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.
> unsigned int spdm_mt_nr_pages;
> void *spdm_mt;
> };
> @@ -58,9 +73,89 @@ static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
> return container_of(tsm, struct tdx_tsm_link, pci.base_tsm);
> }
>
> +static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
> +{
> + /* TODO: implement the PCI DOE transfer */
> + return 0;
> +}
> +
> +/*
> + * When serving SEAMCALLs, the TDX module extensions work like service thread
> + * pools. The number of service threads is limited per service type (or
> + * "per extension" in terms of TDX). When the host issues a request via
> + * SEAMCALL but the TDX module can't find an available thread, it returns
> + * TDX_OPERAND_BUSY. Currently the thread number limit for the TDISP extension
> + * is 1. So a mutex could work to prevent SEAMCALL busy returns.
> + */
> +static DEFINE_MUTEX(tdx_spdm_lock);
Yea I think this is a good solution to start. We can support enumerating
multiple sessions in follow on work.
> +
> +static int tdx_spdm_xfer_handler(struct tdx_tsm_link *tlink, u64 sret,
> + u64 out_msg_sz)
> +{
> + int ret;
> +
> + if (sret == TDX_SPDM_REQUEST) {
> + ret = tdx_spdm_msg_exchange(tlink);
> + if (ret < 0)
> + return ret;
> +
> + return -EAGAIN;
> + }
> +
> + if (sret == TDX_SUCCESS)
> + return 0;
> +
> + return -EIO;
> +}
> +
> +static int tdx_spdm_session_connect(struct tdx_tsm_link *tlink)
> +{
> + struct spdm_config_info_t *spdm_conf;
> + u64 sret, out_msg_sz;
> + int ret;
> +
> + /* create & fill SPDM configuration buffer - a single page */
> + spdm_conf = kzalloc_obj(*spdm_conf);
> + if (!spdm_conf)
> + return -ENOMEM;
> +
> + spdm_conf->certificate_slot_mask = 0xff;
Can we not have the magic number? I guess it means any?
> +
> + do {
> + mutex_lock(&tdx_spdm_lock);
> + sret = tdh_spdm_connect(tlink->spdm_id,
> + virt_to_page(spdm_conf),
> + tlink->in_msg, tlink->out_msg,
> + NULL, &out_msg_sz);
> + mutex_unlock(&tdx_spdm_lock);
> + ret = tdx_spdm_xfer_handler(tlink, sret, out_msg_sz);
> + } while (ret == -EAGAIN);
> +
> + kfree(spdm_conf);
> +
> + return ret;
> +}
> +
> +static void tdx_spdm_session_disconnect(struct tdx_tsm_link *tlink)
> +{
> + u64 sret, out_msg_sz;
> + int ret;
> +
> + 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.
> + sret = tdh_spdm_disconnect(tlink->spdm_id, tlink->in_msg,
> + tlink->out_msg, &out_msg_sz);
> + mutex_unlock(&tdx_spdm_lock);
> + ret = tdx_spdm_xfer_handler(tlink, sret, out_msg_sz);
> + } while (ret == -EAGAIN);
> +
> + WARN_ON(ret);
> +}
> +
> static int tdx_spdm_create(struct tdx_tsm_link *tlink)
> {
> const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
> + struct page *in_msg_page, *out_msg_page;
> struct tdx_hpa_list_info info;
> unsigned int nr_pages;
> u64 spdm_id, sret;
> @@ -70,12 +165,21 @@ static int tdx_spdm_create(struct tdx_tsm_link *tlink)
> if (!tdx_sysinfo)
> return -ENXIO;
>
> + 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.
> nr_pages = tdx_sysinfo->tdx_connect.spdm_mt_page_count;
>
> spdm_mt = alloc_pages_exact(nr_pages * PAGE_SIZE,
> GFP_KERNEL | __GFP_ZERO);
> if (!spdm_mt)
> - return -ENOMEM;
> + goto out_free_out_msg;
>
> ret = tdx_hpa_list_info_setup(&info, spdm_mt, nr_pages);
> if (ret)
> @@ -92,11 +196,17 @@ static int tdx_spdm_create(struct tdx_tsm_link *tlink)
>
> tlink->spdm_id = spdm_id;
> tlink->spdm_mt = spdm_mt;
> + tlink->in_msg = in_msg_page;
> + tlink->out_msg = out_msg_page;
> tlink->spdm_mt_nr_pages = nr_pages;
> return 0;
>
> out_free_spdm_mt:
> free_pages_exact(spdm_mt, nr_pages * PAGE_SIZE);
> +out_free_out_msg:
> + __free_page(out_msg_page);
> +out_free_in_msg:
> + __free_page(in_msg_page);
> return ret;
> }
>
> @@ -112,16 +222,33 @@ static void tdx_spdm_delete(struct tdx_tsm_link *tlink)
> return;
> }
>
> + __free_page(tlink->in_msg);
> + __free_page(tlink->out_msg);
> free_pages_exact(tlink->spdm_mt, tlink->spdm_mt_nr_pages * PAGE_SIZE);
> }
>
> static int tdx_spdm_session_setup(struct tdx_tsm_link *tlink)
> {
> - return tdx_spdm_create(tlink);
> + int ret;
> +
> + ret = tdx_spdm_create(tlink);
> + if (ret)
> + return ret;
> +
> + ret = tdx_spdm_session_connect(tlink);
> + if (ret)
> + goto out_spdm_delete;
> +
> + return 0;
> +
> +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?
> + return ret;
> }
>
> static void tdx_spdm_session_teardown(struct tdx_tsm_link *tlink)
> {
> + tdx_spdm_session_disconnect(tlink);
> tdx_spdm_delete(tlink);
> }
>
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-23 23:23 ` Edgecombe, Rick P
@ 2026-11-24 12:59 ` Chao Gao
2026-11-24 21:11 ` Edgecombe, Rick P
2026-11-28 9:35 ` Xu Yilun
0 siblings, 2 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-24 12:59 UTC (permalink / raw)
To: Edgecombe, Rick P
Cc: kvm, linux-coco, linux-kernel, Xu, Yilun, dave.hansen, baolu.lu,
Peng, Chao P, bp, mingo, x86, tglx, Tian, Kevin, hpa, kas
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.
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.
>> 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.
>> 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.
@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.
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.
>> + 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.
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-24 12:59 ` Chao Gao
@ 2026-11-24 21:11 ` Edgecombe, Rick P
2026-11-28 9:25 ` Xu Yilun
2026-11-28 9:35 ` Xu Yilun
1 sibling, 1 reply; 29+ messages in thread
From: Edgecombe, Rick P @ 2026-11-24 21:11 UTC (permalink / raw)
To: Gao, Chao
Cc: hpa, Xu, Yilun, bp, baolu.lu, Peng, Chao P, dave.hansen,
linux-kernel, mingo, x86, kvm, linux-coco, Tian, Kevin, tglx,
kas
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.
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-24 21:11 ` Edgecombe, Rick P
@ 2026-11-28 9:25 ` Xu Yilun
2026-11-30 11:40 ` Chao Gao
0 siblings, 1 reply; 29+ messages in thread
From: Xu Yilun @ 2026-11-28 9:25 UTC (permalink / raw)
To: Edgecombe, Rick P
Cc: Gao, Chao, hpa, Xu, Yilun, bp, baolu.lu, Peng, Chao P,
dave.hansen, linux-kernel, mingo, x86, kvm, linux-coco, Tian,
Kevin, tglx, kas
> > > > 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.
Correct. But we don't have to mention "per function" serialization for
now, this is for secure passthrough of the TDI. For link encryption, the
connect/disconnect operations only targets the device (physical function 0).
Though this is not the answer to Rick's concern...
>
> 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.
I believe it is possible. The DOE protocol defines serialized
request/response flow. And the pci_doe() code does so, the entire
request payload must be sent before receiving any response payload.
I didn't try on real TDX module if tdh_spdm_connect/disconnect/mng can
work with one buffer, but don't see reason why it can't.
>
> >
> > @Yilun, let me know if this understanding is wrong.
> >
[...]
> > > > + 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);
> > >
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-28 9:25 ` Xu Yilun
@ 2026-11-30 11:40 ` Chao Gao
0 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-30 11:40 UTC (permalink / raw)
To: Xu Yilun
Cc: Edgecombe, Rick P, hpa, Xu, Yilun, bp, baolu.lu, Peng, Chao P,
dave.hansen, linux-kernel, mingo, x86, kvm, linux-coco, Tian,
Kevin, tglx, kas
On Sat, Nov 28, 2026 at 05:25:14PM +0800, Xu Yilun wrote:
>> > > > 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.
>
>Though this is not the answer to Rick's concern...
Right, I misread Rick's comment as asking why one pair is enough.
>> 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.
>
>I believe it is possible. The DOE protocol defines serialized
>request/response flow. And the pci_doe() code does so, the entire
>request payload must be sent before receiving any response payload.
>
>I didn't try on real TDX module if tdh_spdm_connect/disconnect/mng can
>work with one buffer, but don't see reason why it can't.
Using the same buffer may work, but I do not think it is worth doing
now. Both pci_doe() and the TDX module's SPDM SEAMCALLs take separate
request and response buffers, and neither says that the two may
overlap. The saving would only be one page per device. And the AMD
implementation and the upcoming Arm series [1] use two buffers as well.
[1]: https://lore.kernel.org/all/20260910140509.868402-4-aneesh.kumar@kernel.org/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-24 12:59 ` Chao Gao
2026-11-24 21:11 ` Edgecombe, Rick P
@ 2026-11-28 9:35 ` Xu Yilun
2026-11-30 12:20 ` Chao Gao
1 sibling, 1 reply; 29+ messages in thread
From: Xu Yilun @ 2026-11-28 9:35 UTC (permalink / raw)
To: Chao Gao
Cc: Edgecombe, Rick P, kvm, linux-coco, linux-kernel, Xu, Yilun,
dave.hansen, baolu.lu, Peng, Chao P, bp, mingo, x86, tglx, Tian,
Kevin, hpa, kas
> >> +#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.
>
> But yes, there is some SPDM-specific stuff in this series. I will try
> to separate it from the TDX stuff.
[...]
> >> + 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.
So it seems we don't need any spdm_config_info_t definition for now.
Should we keep the definition or just to provide a zero page to avoid
unnecessary explanations here?
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device
2026-11-28 9:35 ` Xu Yilun
@ 2026-11-30 12:20 ` Chao Gao
0 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-30 12:20 UTC (permalink / raw)
To: Xu Yilun
Cc: Edgecombe, Rick P, kvm, linux-coco, linux-kernel, Xu, Yilun,
dave.hansen, baolu.lu, Peng, Chao P, bp, mingo, x86, tglx, Tian,
Kevin, hpa, kas
On Sat, Nov 28, 2026 at 05:35:44PM +0800, Xu Yilun wrote:
>> >> + 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.
>
>So it seems we don't need any spdm_config_info_t definition for now.
>Should we keep the definition or just to provide a zero page to avoid
>unnecessary explanations here?
The certificate_slot_mask should be 0x1 so that we can get the
certificate in slot 0, right?
If so, I would keep the definition and pass 0x1.
^ permalink raw reply [flat|nested] 29+ messages in thread
* [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
2026-11-16 11:10 ` [RFC PATCH 1/7] coco/tdx-host: Create metadata for an SPDM session Chao Gao
2026-11-16 11:10 ` [RFC PATCH 2/7] coco/tdx-host: Establish an SPDM session with the device Chao Gao
@ 2026-11-16 11:10 ` Chao Gao
2026-11-24 0:02 ` Edgecombe, Rick P
2026-11-28 9:47 ` Xu Yilun
2026-11-16 11:10 ` [RFC PATCH 4/7] coco/tdx-host: Pass a device info buffer to tdh_spdm_connect() Chao Gao
` (4 subsequent siblings)
7 siblings, 2 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-16 11:10 UTC (permalink / raw)
To: x86, linux-coco, kvm, linux-kernel
Cc: rick.p.edgecombe, kevin.tian, yilun.xu, chao.p.peng, baolu.lu,
chao.gao, Kiryl Shutsemau, Dave Hansen
The TDX module cannot access a device's DOE mailbox, so the kernel
relays SPDM messages between the TDX module and the device. The TDX
module produces and consumes whole DOE data objects, header included,
but pci_tsm_doe_transfer() takes only the payload and builds the header
itself.
Define struct pci_doe_header and struct pci_doe_msg to describe a DOE
data object. Strip the header from each request before passing the
payload to pci_tsm_doe_transfer(), and rebuild the header around the
device's response before handing it back to the TDX module.
An alternative is to add a PCI DOE API that takes whole data objects.
This would avoid the conversion, but the TDX-TSM driver would be its
only user.
Based on work by Yilun.
AI suggested defining the DOE header and object structures in place of
the bit operations, and dropping the endian conversions.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
drivers/virt/coco/tdx-host/main.c | 49 ++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
index 32755d70dac5..86299658ae45 100644
--- a/drivers/virt/coco/tdx-host/main.c
+++ b/drivers/virt/coco/tdx-host/main.c
@@ -11,6 +11,7 @@
#include <linux/module.h>
#include <linux/sysfs.h>
#include <linux/pci.h>
+#include <linux/pci-doe.h>
#include <linux/pci-tsm.h>
#include <linux/tsm.h>
@@ -73,9 +74,55 @@ static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
return container_of(tsm, struct tdx_tsm_link, pci.base_tsm);
}
+struct pci_doe_header {
+ u16 vendor;
+ u8 type;
+ u8 rsvd0;
+ u32 length: 18; /* in DWORDs */
+ u32 rsvd1: 14;
+} __packed;
+
+struct pci_doe_msg {
+ struct pci_doe_header header;
+ u8 payload[];
+} __packed;
+
+/*
+ * The TDX module produces and consumes complete DOE data objects, but
+ * pci_doe() takes only the payload and builds the header itself. Strip
+ * the header from the request and rebuild it for the response.
+ */
static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
{
- /* TODO: implement the PCI DOE transfer */
+ struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
+ struct pci_doe_msg *req = page_address(tlink->out_msg);
+ struct pci_doe_msg *resp = page_address(tlink->in_msg);
+
+ size_t req_sz = req->header.length * sizeof(u32);
+ size_t resp_sz = PAGE_SIZE;
+
+ size_t req_payload_sz = req_sz - sizeof(struct pci_doe_header);
+ size_t resp_payload_sz = resp_sz - sizeof(struct pci_doe_header);
+
+ void *resp_payload_addr = resp->payload;
+ void *req_payload_addr = req->payload;
+
+ u8 type = req->header.type;
+
+ int ret;
+
+ ret = pci_tsm_doe_transfer(pdev, type,
+ req_payload_addr, req_payload_sz,
+ resp_payload_addr, resp_payload_sz);
+ if (ret < 0) {
+ pci_err(pdev, "spdm msg exchange fail %d\n", ret);
+ return ret;
+ }
+
+ resp->header.vendor = PCI_VENDOR_ID_PCI_SIG;
+ resp->header.type = type;
+ resp->header.length = (ret + sizeof(struct pci_doe_header)) / sizeof(u32);
+
return 0;
}
--
2.52.0
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-16 11:10 ` [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE Chao Gao
@ 2026-11-24 0:02 ` Edgecombe, Rick P
2026-11-24 11:57 ` Chao Gao
2026-11-28 9:47 ` Xu Yilun
1 sibling, 1 reply; 29+ messages in thread
From: Edgecombe, Rick P @ 2026-11-24 0:02 UTC (permalink / raw)
To: kvm, linux-coco, linux-kernel, Gao, Chao, x86
Cc: Tian, Kevin, Xu, Yilun, Peng, Chao P, kas, baolu.lu, dave.hansen
On Mon, 2026-11-16 at 03:10 -0800, Chao Gao wrote:
> +struct pci_doe_header {
> + u16 vendor;
> + u8 type;
> + u8 rsvd0;
> + u32 length: 18; /* in DWORDs */
> + u32 rsvd1: 14;
> +} __packed;
> +
> +struct pci_doe_msg {
> + struct pci_doe_header header;
> + u8 payload[];
> +} __packed;
You mentioned DOE rebuilds the header. It looks like it doesn't have structs
like these because it uses FIELD_PREP with masks. So then we just have duplicate
definitions of the format. Ugh.
> +
> +/*
> + * The TDX module produces and consumes complete DOE data objects, but
> + * pci_doe() takes only the payload and builds the header itself. Strip
> + * the header from the request and rebuild it for the response.
> + */
> static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
> {
> - /* TODO: implement the PCI DOE transfer */
> + struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
> + struct pci_doe_msg *req = page_address(tlink->out_msg);
> + struct pci_doe_msg *resp = page_address(tlink->in_msg);
> +
> + size_t req_sz = req->header.length * sizeof(u32);
> + size_t resp_sz = PAGE_SIZE;
> +
> + size_t req_payload_sz = req_sz - sizeof(struct pci_doe_header);
> + size_t resp_payload_sz = resp_sz - sizeof(struct pci_doe_header);
> +
> + void *resp_payload_addr = resp->payload;
> + void *req_payload_addr = req->payload;
> +
> + u8 type = req->header.type;
> +
> + int ret;
Yea, this is just really unfortunate like you pointed in the coverletter. We
unwrap the header using all of this gunk to pass it through and then rebuild the
header on the other side.
resp_payload_addr, and req_payload_addr seem unnecessary. It's not any shorter
in the function over casing to (void *).
> +
> + ret = pci_tsm_doe_transfer(pdev, type,
> + req_payload_addr, req_payload_sz,
> + resp_payload_addr, resp_payload_sz);
> + if (ret < 0) {
> + pci_err(pdev, "spdm msg exchange fail %d\n", ret);
> + return ret;
> + }
> +
> + resp->header.vendor = PCI_VENDOR_ID_PCI_SIG;
> + resp->header.type = type;
> + resp->header.length = (ret + sizeof(struct pci_doe_header)) / sizeof(u32);
> +
> return 0;
> }
>
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-24 0:02 ` Edgecombe, Rick P
@ 2026-11-24 11:57 ` Chao Gao
2026-11-24 22:02 ` Edgecombe, Rick P
0 siblings, 1 reply; 29+ messages in thread
From: Chao Gao @ 2026-11-24 11:57 UTC (permalink / raw)
To: Edgecombe, Rick P
Cc: kvm, linux-coco, linux-kernel, x86, Tian, Kevin, Xu, Yilun, Peng,
Chao P, kas, baolu.lu, dave.hansen
On Tue, Nov 24, 2026 at 08:02:08AM +0800, Edgecombe, Rick P wrote:
>On Mon, 2026-11-16 at 03:10 -0800, Chao Gao wrote:
>> +struct pci_doe_header {
>> + u16 vendor;
>> + u8 type;
>> + u8 rsvd0;
>> + u32 length: 18; /* in DWORDs */
>> + u32 rsvd1: 14;
>> +} __packed;
>> +
>> +struct pci_doe_msg {
>> + struct pci_doe_header header;
>> + u8 payload[];
>> +} __packed;
>
>You mentioned DOE rebuilds the header. It looks like it doesn't have structs
>like these because it uses FIELD_PREP with masks. So then we just have duplicate
>definitions of the format. Ugh.
Yes. The earlier version [1] used the masks, and I found all the
le32_to_cpu() and FIELD_PREP() hard to read. I would prefer to keep
the structs as long as this code stays in the TDX-TSM driver.
>Yea, this is just really unfortunate like you pointed in the coverletter. We
>unwrap the header using all of this gunk to pass it through and then rebuild the
>header on the other side.
I am now leaning towards moving this code into PCI/DOE, even though
TDX would be its only user. Stripping and rebuilding the header is DOE
format handling, and the PCI/DOE core already has the definitions and
the code for it. A TSM driver should not need a second copy, no matter
how many users there are. That would also remove the duplicate
definitions above.
>> + void *resp_payload_addr = resp->payload;
>> + void *req_payload_addr = req->payload;
>
>resp_payload_addr, and req_payload_addr seem unnecessary. It's not any shorter
>in the function over casing to (void *).
Sure, will do.
[1]: https://lore.kernel.org/all/20260327160132.2946114-25-yilun.xu@linux.intel.com/
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-24 11:57 ` Chao Gao
@ 2026-11-24 22:02 ` Edgecombe, Rick P
2026-11-25 12:12 ` Chao Gao
0 siblings, 1 reply; 29+ messages in thread
From: Edgecombe, Rick P @ 2026-11-24 22:02 UTC (permalink / raw)
To: Gao, Chao
Cc: Xu, Yilun, x86, kas, Peng, Chao P, dave.hansen, linux-kernel,
kvm, Tian, Kevin, linux-coco, baolu.lu
On Tue, 2026-11-24 at 19:57 +0800, Chao Gao wrote:
> > You mentioned DOE rebuilds the header. It looks like it doesn't have structs
> > like these because it uses FIELD_PREP with masks. So then we just have
> > duplicate
> > definitions of the format. Ugh.
>
> Yes. The earlier version [1] used the masks, and I found all the
> le32_to_cpu() and FIELD_PREP() hard to read. I would prefer to keep
> the structs as long as this code stays in the TDX-TSM driver.
>
> > Yea, this is just really unfortunate like you pointed in the coverletter. We
> > unwrap the header using all of this gunk to pass it through and then rebuild
> > the
> > header on the other side.
>
> I am now leaning towards moving this code into PCI/DOE, even though
> TDX would be its only user. Stripping and rebuilding the header is DOE
> format handling, and the PCI/DOE core already has the definitions and
> the code for it. A TSM driver should not need a second copy, no matter
> how many users there are. That would also remove the duplicate
> definitions above.
Can you elaborate on your proposal? What exactly moves to DOE and how does it
interop with the other DOE callers?
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-24 22:02 ` Edgecombe, Rick P
@ 2026-11-25 12:12 ` Chao Gao
2026-11-25 17:48 ` Edgecombe, Rick P
0 siblings, 1 reply; 29+ messages in thread
From: Chao Gao @ 2026-11-25 12:12 UTC (permalink / raw)
To: Edgecombe, Rick P
Cc: Xu, Yilun, x86, kas, Peng, Chao P, dave.hansen, linux-kernel,
kvm, Tian, Kevin, linux-coco, baolu.lu
On Wed, Nov 25, 2026 at 06:02:02AM +0800, Edgecombe, Rick P wrote:
>On Tue, 2026-11-24 at 19:57 +0800, Chao Gao wrote:
>> I am now leaning towards moving this code into PCI/DOE, even though
>> TDX would be its only user. Stripping and rebuilding the header is DOE
>> format handling, and the PCI/DOE core already has the definitions and
>> the code for it. A TSM driver should not need a second copy, no matter
>> how many users there are. That would also remove the duplicate
>> definitions above.
>
>Can you elaborate on your proposal? What exactly moves to DOE and how does it
>interop with the other DOE callers?
The header stripping and rebuilding moves to drivers/pci/doe.c, as a new
helper (e.g., pci_doe_raw()). struct pci_doe_header and struct
pci_doe_msg defined in this patch go away. This avoids a second definition
of the DOE format.
pci_doe_raw() is a wrapper around pci_doe(). The other callers still
use pci_doe() and are not affected.
I explored the idea with AI. It generated:
int pci_doe_raw(struct pci_doe_mb *doe_mb, const void *request,
size_t request_sz, void *response, size_t response_sz)
{
const __le32 *req_hdr = request;
__le32 *resp_hdr = response;
size_t hdr_sz = 2 * sizeof(__le32);
size_t length;
u32 hdr1;
int rc;
if (request_sz < hdr_sz || response_sz < hdr_sz)
return -EINVAL;
hdr1 = le32_to_cpu(req_hdr[0]);
length = FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_2_LENGTH,
le32_to_cpu(req_hdr[1]));
/* A value of 0x0 indicates max data object length */
if (!length)
length = PCI_DOE_MAX_LENGTH;
if (length < 2 || length * sizeof(__le32) > request_sz)
return -EINVAL;
rc = pci_doe(doe_mb, FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_VID, hdr1),
FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_TYPE, hdr1),
request + hdr_sz, length * sizeof(__le32) - hdr_sz,
response + hdr_sz, response_sz - hdr_sz);
if (rc < 0)
return rc;
/* pci_doe() has verified that the response has the same VID and Type */
length = 2 + DIV_ROUND_UP(rc, sizeof(__le32));
resp_hdr[0] = cpu_to_le32(hdr1 & (PCI_DOE_DATA_OBJECT_HEADER_1_VID |
PCI_DOE_DATA_OBJECT_HEADER_1_TYPE));
resp_hdr[1] = cpu_to_le32(FIELD_PREP(PCI_DOE_DATA_OBJECT_HEADER_2_LENGTH,
length % PCI_DOE_MAX_LENGTH));
return rc + hdr_sz;
}
tdx_spdm_msg_exchange() becomes:
static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
{
struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
int ret;
ret = pci_doe_raw(tlink->pci.doe_mb,
page_address(tlink->out_msg), PAGE_SIZE,
page_address(tlink->in_msg), PAGE_SIZE);
if (ret < 0) {
pci_err(pdev, "spdm msg exchange fail %d\n", ret);
return ret;
}
return 0;
}
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-25 12:12 ` Chao Gao
@ 2026-11-25 17:48 ` Edgecombe, Rick P
2026-11-28 12:42 ` Xu Yilun
0 siblings, 1 reply; 29+ messages in thread
From: Edgecombe, Rick P @ 2026-11-25 17:48 UTC (permalink / raw)
To: Gao, Chao
Cc: Xu, Yilun, dave.hansen, kas, Peng, Chao P, x86, linux-kernel,
kvm, Tian, Kevin, linux-coco, baolu.lu
On Wed, 2026-11-25 at 20:12 +0800, Chao Gao wrote:
> static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
> {
> struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
> int ret;
>
> ret = pci_doe_raw(tlink->pci.doe_mb,
> page_address(tlink->out_msg), PAGE_SIZE,
> page_address(tlink->in_msg), PAGE_SIZE);
> if (ret < 0) {
> pci_err(pdev, "spdm msg exchange fail %d\n", ret);
> return ret;
> }
>
> return 0;
> }
If the DOE people are ok with this, it does seem much better to me on our side.
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-25 17:48 ` Edgecombe, Rick P
@ 2026-11-28 12:42 ` Xu Yilun
0 siblings, 0 replies; 29+ messages in thread
From: Xu Yilun @ 2026-11-28 12:42 UTC (permalink / raw)
To: Edgecombe, Rick P
Cc: Gao, Chao, Xu, Yilun, dave.hansen, kas, Peng, Chao P, x86,
linux-kernel, kvm, Tian, Kevin, linux-coco, baolu.lu
On Wed, Nov 25, 2026 at 05:48:36PM +0000, Edgecombe, Rick P wrote:
> On Wed, 2026-11-25 at 20:12 +0800, Chao Gao wrote:
> > static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
> > {
> > struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
> > int ret;
> >
> > ret = pci_doe_raw(tlink->pci.doe_mb,
> > page_address(tlink->out_msg), PAGE_SIZE,
> > page_address(tlink->in_msg), PAGE_SIZE);
> > if (ret < 0) {
> > pci_err(pdev, "spdm msg exchange fail %d\n", ret);
> > return ret;
> > }
> >
> > return 0;
> > }
>
> If the DOE people are ok with this, it does seem much better to me on our side.
I'm not the DOE people but I have some concern about this raw
transfering interface. The kernel manages the DOE layer, the PCI DOE
capability and the discovery protocol.. The firmware has no access
these info. It is questionable that the firmware constructs the DOE
packet without knowing all the info. Even today the firmware can
blindly fill the packet right, no guarantee it still can as the
discovery protocol version advances.
I lean to not having TDX module create the DOE header. Let the kernel
do it.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-16 11:10 ` [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE Chao Gao
2026-11-24 0:02 ` Edgecombe, Rick P
@ 2026-11-28 9:47 ` Xu Yilun
2026-11-30 12:53 ` Chao Gao
1 sibling, 1 reply; 29+ messages in thread
From: Xu Yilun @ 2026-11-28 9:47 UTC (permalink / raw)
To: Chao Gao
Cc: x86, linux-coco, kvm, linux-kernel, rick.p.edgecombe, kevin.tian,
yilun.xu, chao.p.peng, baolu.lu, Kiryl Shutsemau, Dave Hansen
> static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
I remember there is a comment in internal review that suggests we use
struct pci_dev *pdev for this function, to explicit this is purly about
PCI, nothing to do with TSM firmware. I accept it at that time and still
feel good today. How do you think?
> {
> - /* TODO: implement the PCI DOE transfer */
> + struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
> + struct pci_doe_msg *req = page_address(tlink->out_msg);
> + struct pci_doe_msg *resp = page_address(tlink->in_msg);
> +
> + size_t req_sz = req->header.length * sizeof(u32);
> + size_t resp_sz = PAGE_SIZE;
> +
> + size_t req_payload_sz = req_sz - sizeof(struct pci_doe_header);
> + size_t resp_payload_sz = resp_sz - sizeof(struct pci_doe_header);
> +
> + void *resp_payload_addr = resp->payload;
> + void *req_payload_addr = req->payload;
> +
> + u8 type = req->header.type;
> +
> + int ret;
> +
> + ret = pci_tsm_doe_transfer(pdev, type,
> + req_payload_addr, req_payload_sz,
> + resp_payload_addr, resp_payload_sz);
> + if (ret < 0) {
> + pci_err(pdev, "spdm msg exchange fail %d\n", ret);
> + return ret;
> + }
> +
> + resp->header.vendor = PCI_VENDOR_ID_PCI_SIG;
> + resp->header.type = type;
> + resp->header.length = (ret + sizeof(struct pci_doe_header)) / sizeof(u32);
> +
> return 0;
> }
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
2026-11-28 9:47 ` Xu Yilun
@ 2026-11-30 12:53 ` Chao Gao
0 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-30 12:53 UTC (permalink / raw)
To: Xu Yilun
Cc: x86, linux-coco, kvm, linux-kernel, rick.p.edgecombe, kevin.tian,
yilun.xu, chao.p.peng, baolu.lu, Kiryl Shutsemau, Dave Hansen
On Sat, Nov 28, 2026 at 05:47:46PM +0800, Xu Yilun wrote:
>> static int tdx_spdm_msg_exchange(struct tdx_tsm_link *tlink)
>
>I remember there is a comment in internal review that suggests we use
>struct pci_dev *pdev for this function, to explicit this is purly about
>PCI, nothing to do with TSM firmware. I accept it at that time and still
>feel good today. How do you think?
I would keep the tlink for this static function. The pdev and both
message buffers come from it, so with a pdev parameter the caller has
to pull every argument out of the tlink. The function relays the TDX
module's messages, so it cannot be made completely unrelated to the
TSM firmware. If other code without a tlink needs to call it later,
making it generic then is fine.
^ permalink raw reply [flat|nested] 29+ messages in thread
* [RFC PATCH 4/7] coco/tdx-host: Pass a device info buffer to tdh_spdm_connect()
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
` (2 preceding siblings ...)
2026-11-16 11:10 ` [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE Chao Gao
@ 2026-11-16 11:10 ` Chao Gao
2026-11-16 11:10 ` [RFC PATCH 5/7] coco/tdx-host: Configure an IDE stream Chao Gao
` (3 subsequent siblings)
7 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-16 11:10 UTC (permalink / raw)
To: linux-kernel, linux-coco, kvm
Cc: rick.p.edgecombe, kevin.tian, yilun.xu, chao.p.peng, baolu.lu,
chao.gao, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau
TDH.SPDM.CONNECT requires a host-provided buffer, into which the TDX
module writes information about the device.
TDs will use the information to attest the device, which is not
supported yet. The kernel doesn't use it for now, so treat it as opaque
data.
Take the buffer size from the TDX global metadata, and keep the buffer
for the lifetime of the SPDM session.
Based on work by Yilun.
[This patch will be reworked when the series moves to the CTLV
attestation flow.]
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
arch/x86/include/asm/tdx_global_metadata.h | 1 +
arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 6 +++++
drivers/virt/coco/tdx-host/main.c | 27 +++++++++++++++++++--
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/tdx_global_metadata.h b/arch/x86/include/asm/tdx_global_metadata.h
index 537e872eeb0e..30f3ca006e88 100644
--- a/arch/x86/include/asm/tdx_global_metadata.h
+++ b/arch/x86/include/asm/tdx_global_metadata.h
@@ -54,6 +54,7 @@ struct tdx_sys_info_ext {
struct tdx_sys_info_connect {
u16 spdm_mt_page_count;
u16 iommu_mt_page_count;
+ u16 spdm_max_dev_info_pages;
};
struct tdx_sys_info {
diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
index f20e029f240b..cf747b0dc945 100644
--- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
+++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
@@ -156,6 +156,12 @@ static __init int get_tdx_sys_info_connect(struct tdx_sys_info_connect *sysinfo_
sysinfo_connect->iommu_mt_page_count = val;
+ ret = read_sys_metadata_field(0x3000000100000007, &val);
+ if (ret)
+ return ret;
+
+ sysinfo_connect->spdm_max_dev_info_pages = val;
+
return 0;
}
diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
index 86299658ae45..da56178eac2e 100644
--- a/drivers/virt/coco/tdx-host/main.c
+++ b/drivers/virt/coco/tdx-host/main.c
@@ -67,6 +67,8 @@ struct tdx_tsm_link {
struct page *out_msg;
unsigned int spdm_mt_nr_pages;
void *spdm_mt;
+ unsigned int dev_info_nr_pages;
+ void *dev_info;
};
static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
@@ -158,6 +160,7 @@ static int tdx_spdm_xfer_handler(struct tdx_tsm_link *tlink, u64 sret,
static int tdx_spdm_session_connect(struct tdx_tsm_link *tlink)
{
struct spdm_config_info_t *spdm_conf;
+ struct tdx_hpa_list_info info;
u64 sret, out_msg_sz;
int ret;
@@ -168,16 +171,23 @@ static int tdx_spdm_session_connect(struct tdx_tsm_link *tlink)
spdm_conf->certificate_slot_mask = 0xff;
+ ret = tdx_hpa_list_info_setup(&info, tlink->dev_info, tlink->dev_info_nr_pages);
+ if (ret)
+ goto out_free_spdm_conf;
+
do {
mutex_lock(&tdx_spdm_lock);
sret = tdh_spdm_connect(tlink->spdm_id,
virt_to_page(spdm_conf),
tlink->in_msg, tlink->out_msg,
- NULL, &out_msg_sz);
+ &info, &out_msg_sz);
mutex_unlock(&tdx_spdm_lock);
ret = tdx_spdm_xfer_handler(tlink, sret, out_msg_sz);
} while (ret == -EAGAIN);
+ tdx_hpa_list_info_free(&info);
+
+out_free_spdm_conf:
kfree(spdm_conf);
return ret;
@@ -203,9 +213,11 @@ static int tdx_spdm_create(struct tdx_tsm_link *tlink)
{
const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
struct page *in_msg_page, *out_msg_page;
+ unsigned int dev_info_nr_pages;
struct tdx_hpa_list_info info;
unsigned int nr_pages;
u64 spdm_id, sret;
+ void *dev_info;
void *spdm_mt;
int ret;
@@ -222,11 +234,17 @@ static int tdx_spdm_create(struct tdx_tsm_link *tlink)
goto out_free_in_msg;
nr_pages = tdx_sysinfo->tdx_connect.spdm_mt_page_count;
+ dev_info_nr_pages = tdx_sysinfo->tdx_connect.spdm_max_dev_info_pages;
+
+ dev_info = alloc_pages_exact(dev_info_nr_pages * PAGE_SIZE,
+ GFP_KERNEL | __GFP_ZERO);
+ if (!dev_info)
+ goto out_free_out_msg;
spdm_mt = alloc_pages_exact(nr_pages * PAGE_SIZE,
GFP_KERNEL | __GFP_ZERO);
if (!spdm_mt)
- goto out_free_out_msg;
+ goto out_free_dev_info;
ret = tdx_hpa_list_info_setup(&info, spdm_mt, nr_pages);
if (ret)
@@ -246,10 +264,14 @@ static int tdx_spdm_create(struct tdx_tsm_link *tlink)
tlink->in_msg = in_msg_page;
tlink->out_msg = out_msg_page;
tlink->spdm_mt_nr_pages = nr_pages;
+ tlink->dev_info = dev_info;
+ tlink->dev_info_nr_pages = dev_info_nr_pages;
return 0;
out_free_spdm_mt:
free_pages_exact(spdm_mt, nr_pages * PAGE_SIZE);
+out_free_dev_info:
+ free_pages_exact(dev_info, dev_info_nr_pages * PAGE_SIZE);
out_free_out_msg:
__free_page(out_msg_page);
out_free_in_msg:
@@ -272,6 +294,7 @@ static void tdx_spdm_delete(struct tdx_tsm_link *tlink)
__free_page(tlink->in_msg);
__free_page(tlink->out_msg);
free_pages_exact(tlink->spdm_mt, tlink->spdm_mt_nr_pages * PAGE_SIZE);
+ free_pages_exact(tlink->dev_info, tlink->dev_info_nr_pages * PAGE_SIZE);
}
static int tdx_spdm_session_setup(struct tdx_tsm_link *tlink)
--
2.52.0
^ permalink raw reply [flat|nested] 29+ messages in thread* [RFC PATCH 5/7] coco/tdx-host: Configure an IDE stream
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
` (3 preceding siblings ...)
2026-11-16 11:10 ` [RFC PATCH 4/7] coco/tdx-host: Pass a device info buffer to tdh_spdm_connect() Chao Gao
@ 2026-11-16 11:10 ` Chao Gao
2026-11-28 13:17 ` Xu Yilun
2026-11-16 11:10 ` [RFC PATCH 6/7] coco/tdx-host: Program IDE keys and enable the " Chao Gao
` (2 subsequent siblings)
7 siblings, 1 reply; 29+ messages in thread
From: Chao Gao @ 2026-11-16 11:10 UTC (permalink / raw)
To: linux-pci, linux-kernel, x86, linux-coco, kvm
Cc: rick.p.edgecombe, kevin.tian, yilun.xu, chao.p.peng, baolu.lu,
chao.gao, Bjorn Helgaas, Kiryl Shutsemau, Dave Hansen
Establishing a PCIe Integrity and Data Encryption (IDE) stream has two
parts. The stream is first provisioned in the config space of both
Partner Ports (the root port and the device), and the keys are then
programmed via IDE Key Management (IDE_KM).
Commit 1e4d2ff3ae45 ("PCI/IDE: Add IDE establishment helpers") added
the pci_ide_stream_*() helpers for provisioning. They split it into
fine-grained allocate, register and setup steps to accommodate
differences between SEV-TIO and TDX Connect, such as who programs the
root port and who allocates the stream ID.
Provision the stream with these helpers. IDE_KM and enabling the stream
are left to later changes.
The TDX module owns the root port's IDE registers and provides
TDH.IDE.STREAM.CREATE for the host to program them. Configure the root
port with the SEAMCALL, passing the register values as parameters, and
write only the device's IDE registers from the host.
An IDE stream can be associated with address ranges, so that traffic
to different ranges, such as those of different devices, goes through
different streams with different keys. A stream can be associated with
multiple ranges, but TDX supports only one. Keep the prefetchable range
and drop the non-prefetchable one. Export pci_ide_stream_to_regs() to
generate the root port's register values from the adjusted settings.
TDH.IDE.STREAM.CREATE also returns the stream ID that the TDX module
assigns. Configure the device with the same ID.
Based on work by Yilun.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
drivers/pci/ide.c | 5 +-
drivers/virt/coco/tdx-host/main.c | 147 ++++++++++++++++++++++++++++++
include/linux/pci-ide.h | 2 +
3 files changed, 152 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/ide.c b/drivers/pci/ide.c
index beb67b8fb5c5..aced5ef923a9 100644
--- a/drivers/pci/ide.c
+++ b/drivers/pci/ide.c
@@ -550,8 +550,8 @@ static void mem_assoc_to_regs(struct pci_bus_region *region,
* @ide: registered IDE settings descriptor
* @regs: output register values
*/
-static void pci_ide_stream_to_regs(struct pci_dev *pdev, struct pci_ide *ide,
- struct pci_ide_regs *regs)
+void pci_ide_stream_to_regs(struct pci_dev *pdev, struct pci_ide *ide,
+ struct pci_ide_regs *regs)
{
struct pci_ide_partner *settings = pci_ide_to_settings(pdev, ide);
int assoc_idx = 0;
@@ -580,6 +580,7 @@ static void pci_ide_stream_to_regs(struct pci_dev *pdev, struct pci_ide *ide,
regs->nr_addr = assoc_idx;
}
+EXPORT_SYMBOL_GPL(pci_ide_stream_to_regs);
/**
* pci_ide_stream_setup() - program settings to Selective IDE Stream registers
diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
index da56178eac2e..63209a712c28 100644
--- a/drivers/virt/coco/tdx-host/main.c
+++ b/drivers/virt/coco/tdx-host/main.c
@@ -12,6 +12,7 @@
#include <linux/sysfs.h>
#include <linux/pci.h>
#include <linux/pci-doe.h>
+#include <linux/pci-ide.h>
#include <linux/pci-tsm.h>
#include <linux/tsm.h>
@@ -69,6 +70,10 @@ struct tdx_tsm_link {
void *spdm_mt;
unsigned int dev_info_nr_pages;
void *dev_info;
+
+ struct pci_ide *ide;
+ struct page *stream_mt;
+ unsigned int stream_id;
};
static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
@@ -322,6 +327,140 @@ static void tdx_spdm_session_teardown(struct tdx_tsm_link *tlink)
tdx_spdm_delete(tlink);
}
+static void sel_stream_block_regs(struct pci_dev *pdev, struct pci_ide *ide,
+ struct pci_ide_regs *regs)
+{
+ struct pci_dev *rp = pcie_find_root_port(pdev);
+ struct pci_ide_partner *setting = pci_ide_to_settings(rp, ide);
+
+ /* only support address association for prefetchable memory */
+ setting->mem_assoc = (struct pci_bus_region) { 0, -1 };
+ pci_ide_stream_to_regs(rp, ide, regs);
+}
+
+#define STREAM_INFO_RP_DEVFN GENMASK_ULL(7, 0)
+#define STREAM_INFO_TYPE BIT_ULL(8)
+#define STREAM_INFO_TYPE_LINK 0
+#define STREAM_INFO_TYPE_SEL 1
+
+static int tdx_ide_stream_create(struct tdx_tsm_link *tlink,
+ struct pci_ide *ide)
+{
+ u64 stream_info, stream_ctrl, stream_id;
+ struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
+ struct pci_dev *rp = pcie_find_root_port(pdev);
+ struct pci_ide_regs regs;
+ struct page *stream_mt;
+ u64 sret;
+ int ret;
+
+ stream_mt = alloc_page(GFP_KERNEL | __GFP_ZERO);
+ if (!stream_mt)
+ return -ENOMEM;
+
+ stream_info = FIELD_PREP(STREAM_INFO_RP_DEVFN, rp->devfn);
+ stream_info |= FIELD_PREP(STREAM_INFO_TYPE, STREAM_INFO_TYPE_SEL);
+ /* Keep optional stream features disabled for now. */
+ stream_ctrl = 0;
+
+ sel_stream_block_regs(pdev, ide, ®s);
+ if (regs.nr_addr != 1) {
+ ret = -EFAULT;
+ goto out_free_stream_mt;
+ }
+
+ sret = tdh_ide_stream_create(stream_info, tlink->spdm_id,
+ stream_mt, stream_ctrl,
+ regs.rid1, regs.rid2, regs.addr[0].assoc1,
+ regs.addr[0].assoc2, regs.addr[0].assoc3,
+ &stream_id);
+ if (sret) {
+ ret = -EIO;
+ goto out_free_stream_mt;
+ }
+
+ tlink->stream_id = stream_id;
+ tlink->stream_mt = stream_mt;
+
+ return 0;
+
+out_free_stream_mt:
+ __free_page(stream_mt);
+
+ return ret;
+}
+
+static void tdx_ide_stream_delete(struct tdx_tsm_link *tlink)
+{
+ struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
+ u64 sret;
+
+ sret = tdh_ide_stream_block(tlink->spdm_id, tlink->stream_id);
+ if (sret) {
+ /* leak the metadata pages */
+ pci_err(pdev, "ide stream block fail 0x%llx\n", sret);
+ return;
+ }
+
+ sret = tdh_ide_stream_delete(tlink->spdm_id, tlink->stream_id);
+ if (sret) {
+ pci_err(pdev, "ide stream delete fail 0x%llx\n", sret);
+ return;
+ }
+
+ __free_page(tlink->stream_mt);
+}
+
+static int tdx_ide_stream_setup(struct tdx_tsm_link *tlink)
+{
+ struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
+ struct pci_ide *ide;
+ int ret;
+
+ ide = pci_ide_stream_alloc(pdev);
+ if (!ide)
+ return -ENOMEM;
+
+ /* Configure IDE capability for RP & get stream_id */
+ ret = tdx_ide_stream_create(tlink, ide);
+ if (ret)
+ goto out_pci_ide_stream_free;
+
+ ide->stream_id = tlink->stream_id;
+ ret = pci_ide_stream_register(ide);
+ if (ret)
+ goto out_tdx_ide_stream_delete;
+
+ /*
+ * Configure stream settings for the device. TDISP requires one
+ * stream to be the default stream, and the PCI core does not set
+ * one, so make the only stream the default.
+ */
+ ide->partner[PCI_IDE_EP].default_stream = 1;
+ pci_ide_stream_setup(pdev, ide);
+
+ tlink->ide = ide;
+
+ return 0;
+
+out_tdx_ide_stream_delete:
+ tdx_ide_stream_delete(tlink);
+out_pci_ide_stream_free:
+ pci_ide_stream_free(ide);
+
+ return ret;
+}
+
+static void tdx_ide_stream_teardown(struct tdx_tsm_link *tlink)
+{
+ struct pci_ide *ide = tlink->ide;
+
+ pci_ide_stream_teardown(ide->pdev, ide);
+ pci_ide_stream_unregister(ide);
+ tdx_ide_stream_delete(tlink);
+ pci_ide_stream_free(ide);
+}
+
static int tdx_tsm_link_connect(struct pci_dev *pdev)
{
struct tdx_tsm_link *tlink = to_tdx_tsm_link(pdev->tsm);
@@ -334,8 +473,15 @@ static int tdx_tsm_link_connect(struct pci_dev *pdev)
ret = tdx_spdm_session_setup(tlink);
if (ret)
goto out_iommu_put;
+
+ ret = tdx_ide_stream_setup(tlink);
+ if (ret)
+ goto out_spdm_teardown;
+
return 0;
+out_spdm_teardown:
+ tdx_spdm_session_teardown(tlink);
out_iommu_put:
tdx_iommu_put(pdev);
return ret;
@@ -345,6 +491,7 @@ static void tdx_tsm_link_disconnect(struct pci_dev *pdev)
{
struct tdx_tsm_link *tlink = to_tdx_tsm_link(pdev->tsm);
+ tdx_ide_stream_teardown(tlink);
tdx_spdm_session_teardown(tlink);
tdx_iommu_put(pdev);
}
diff --git a/include/linux/pci-ide.h b/include/linux/pci-ide.h
index ae07d9f699c0..f8074865d2cd 100644
--- a/include/linux/pci-ide.h
+++ b/include/linux/pci-ide.h
@@ -104,6 +104,8 @@ struct pci_ide {
void pci_ide_set_nr_streams(struct pci_host_bridge *hb, u16 nr);
struct pci_ide_partner *pci_ide_to_settings(struct pci_dev *pdev,
struct pci_ide *ide);
+void pci_ide_stream_to_regs(struct pci_dev *pdev, struct pci_ide *ide,
+ struct pci_ide_regs *regs);
struct pci_ide *pci_ide_stream_alloc(struct pci_dev *pdev);
void pci_ide_stream_free(struct pci_ide *ide);
int pci_ide_stream_register(struct pci_ide *ide);
--
2.52.0
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 5/7] coco/tdx-host: Configure an IDE stream
2026-11-16 11:10 ` [RFC PATCH 5/7] coco/tdx-host: Configure an IDE stream Chao Gao
@ 2026-11-28 13:17 ` Xu Yilun
2026-11-30 13:00 ` Chao Gao
0 siblings, 1 reply; 29+ messages in thread
From: Xu Yilun @ 2026-11-28 13:17 UTC (permalink / raw)
To: Chao Gao
Cc: linux-pci, linux-kernel, x86, linux-coco, kvm, rick.p.edgecombe,
kevin.tian, yilun.xu, chao.p.peng, baolu.lu, Bjorn Helgaas,
Kiryl Shutsemau, Dave Hansen
> +static int tdx_ide_stream_setup(struct tdx_tsm_link *tlink)
> +{
> + struct pci_dev *pdev = tlink->pci.base_tsm.pdev;
> + struct pci_ide *ide;
> + int ret;
> +
> + ide = pci_ide_stream_alloc(pdev);
> + if (!ide)
> + return -ENOMEM;
> +
> + /* Configure IDE capability for RP & get stream_id */
> + ret = tdx_ide_stream_create(tlink, ide);
> + if (ret)
> + goto out_pci_ide_stream_free;
> +
> + ide->stream_id = tlink->stream_id;
Nits:
Maybe we don't save stream_id in tlink, it can later be accessed by
tlink->ide->stream_id.
And the function could be like:
ret = tdx_ide_stream_create(tlink, ide, &stream_id);
which aligns better with the comment "get stream_id".
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 5/7] coco/tdx-host: Configure an IDE stream
2026-11-28 13:17 ` Xu Yilun
@ 2026-11-30 13:00 ` Chao Gao
0 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-30 13:00 UTC (permalink / raw)
To: Xu Yilun
Cc: linux-pci, linux-kernel, x86, linux-coco, kvm, rick.p.edgecombe,
kevin.tian, yilun.xu, chao.p.peng, baolu.lu, Bjorn Helgaas,
Kiryl Shutsemau, Dave Hansen
On Sat, Nov 28, 2026 at 09:17:11PM +0800, Xu Yilun wrote:
>> + /* Configure IDE capability for RP & get stream_id */
>> + ret = tdx_ide_stream_create(tlink, ide);
>> + if (ret)
>> + goto out_pci_ide_stream_free;
>> +
>> + ide->stream_id = tlink->stream_id;
>
>Nits:
>
>Maybe we don't save stream_id in tlink, it can later be accessed by
>tlink->ide->stream_id.
>
>And the function could be like:
>
> ret = tdx_ide_stream_create(tlink, ide, &stream_id);
>
>which aligns better with the comment "get stream_id".
Looks good to me. Caching the stream_id in tlink needs a justification,
and I don't see a good one.
As I said in [1], I plan to drop func_id as well, because it can be
derived from the pci_dev at runtime.
[1]: https://lore.kernel.org/all/awzkWJ3aM6buVQm1@intel.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* [RFC PATCH 6/7] coco/tdx-host: Program IDE keys and enable the IDE stream
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
` (4 preceding siblings ...)
2026-11-16 11:10 ` [RFC PATCH 5/7] coco/tdx-host: Configure an IDE stream Chao Gao
@ 2026-11-16 11:10 ` Chao Gao
2026-11-16 11:10 ` [RFC PATCH 7/7] x86/virt/tdx: Enable PCIe link encryption Chao Gao
2026-11-21 1:35 ` [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Edgecombe, Rick P
7 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-16 11:10 UTC (permalink / raw)
To: x86, linux-coco, kvm, linux-kernel
Cc: rick.p.edgecombe, kevin.tian, yilun.xu, chao.p.peng, baolu.lu,
chao.gao, Kiryl Shutsemau, Dave Hansen
With the IDE stream provisioned on root ports and the device, the stream
keys are next programmed via IDE_KM, and then the stream is enabled. The
trusted firmware (TSM) programs the keys into the root port, and sends
them to the device as IDE_KM messages over the SPDM session.
On TDX, TDH.IDE.STREAM.KM does both, and also enables the stream on the
root port. Like TDH.SPDM.CONNECT, it returns to the host whenever it
has an IDE_KM message for the device. Call it in the same loop that
relays the messages through the DOE mailbox.
Unlike TDH.SPDM.CONNECT, TDH.IDE.STREAM.KM is not subject to the TDX
module's concurrency limit, so don't serialize it with the mutex.
After the stream gets enabled on the root port, enable the stream on
the device from the host.
Teardown reverses these steps.
Based on work by Yilun.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
drivers/virt/coco/tdx-host/main.c | 48 +++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/drivers/virt/coco/tdx-host/main.c b/drivers/virt/coco/tdx-host/main.c
index 63209a712c28..040ceea45f8d 100644
--- a/drivers/virt/coco/tdx-host/main.c
+++ b/drivers/virt/coco/tdx-host/main.c
@@ -327,6 +327,37 @@ static void tdx_spdm_session_teardown(struct tdx_tsm_link *tlink)
tdx_spdm_delete(tlink);
}
+enum tdx_ide_stream_km_op {
+ TDX_IDE_STREAM_KM_SETUP = 0,
+ TDX_IDE_STREAM_KM_STOP = 2,
+};
+
+static int tdx_ide_stream_km(struct tdx_tsm_link *tlink,
+ enum tdx_ide_stream_km_op op)
+{
+ u64 sret, out_msg_sz;
+ int ret;
+
+ do {
+ sret = tdh_ide_stream_km(tlink->spdm_id, tlink->stream_id, op,
+ tlink->in_msg, tlink->out_msg,
+ &out_msg_sz);
+ ret = tdx_spdm_xfer_handler(tlink, sret, out_msg_sz);
+ } while (ret == -EAGAIN);
+
+ return ret;
+}
+
+static int tdx_ide_stream_key_program(struct tdx_tsm_link *tlink)
+{
+ return tdx_ide_stream_km(tlink, TDX_IDE_STREAM_KM_SETUP);
+}
+
+static void tdx_ide_stream_key_stop(struct tdx_tsm_link *tlink)
+{
+ tdx_ide_stream_km(tlink, TDX_IDE_STREAM_KM_STOP);
+}
+
static void sel_stream_block_regs(struct pci_dev *pdev, struct pci_ide *ide,
struct pci_ide_regs *regs)
{
@@ -439,10 +470,25 @@ static int tdx_ide_stream_setup(struct tdx_tsm_link *tlink)
ide->partner[PCI_IDE_EP].default_stream = 1;
pci_ide_stream_setup(pdev, ide);
+ /* Key Programming for RP & target device, enable IDE stream for RP */
+ ret = tdx_ide_stream_key_program(tlink);
+ if (ret)
+ goto out_pci_ide_stream_teardown;
+
+ /* Enable IDE stream for target device */
+ ret = pci_ide_stream_enable(pdev, ide);
+ if (ret)
+ goto out_tdx_ide_stream_key_stop;
+
tlink->ide = ide;
return 0;
+out_tdx_ide_stream_key_stop:
+ tdx_ide_stream_key_stop(tlink);
+out_pci_ide_stream_teardown:
+ pci_ide_stream_teardown(pdev, ide);
+ pci_ide_stream_unregister(ide);
out_tdx_ide_stream_delete:
tdx_ide_stream_delete(tlink);
out_pci_ide_stream_free:
@@ -455,6 +501,8 @@ static void tdx_ide_stream_teardown(struct tdx_tsm_link *tlink)
{
struct pci_ide *ide = tlink->ide;
+ pci_ide_stream_disable(ide->pdev, ide);
+ tdx_ide_stream_key_stop(tlink);
pci_ide_stream_teardown(ide->pdev, ide);
pci_ide_stream_unregister(ide);
tdx_ide_stream_delete(tlink);
--
2.52.0
^ permalink raw reply [flat|nested] 29+ messages in thread* [RFC PATCH 7/7] x86/virt/tdx: Enable PCIe link encryption
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
` (5 preceding siblings ...)
2026-11-16 11:10 ` [RFC PATCH 6/7] coco/tdx-host: Program IDE keys and enable the " Chao Gao
@ 2026-11-16 11:10 ` Chao Gao
2026-11-21 1:35 ` [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Edgecombe, Rick P
7 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-16 11:10 UTC (permalink / raw)
To: linux-kernel, linux-coco, kvm
Cc: rick.p.edgecombe, kevin.tian, yilun.xu, chao.p.peng, baolu.lu,
chao.gao, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Kiryl Shutsemau
The basic SPDM session and IDE functionalities are all implemented,
configure the TDX Module to enable the TDISP feature and in turn enable
PCIe link encryption.
Based on work by Yilun.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
arch/x86/include/asm/tdx.h | 2 +-
arch/x86/virt/vmx/tdx/tdx.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index add83e7b9c36..c051f2ae82e6 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -147,7 +147,7 @@ static inline bool tdx_supports_tdisp(const struct tdx_sys_info *sysinfo)
if (!(sysinfo->features.tdx_features0 & TDX_FEATURES0_TDXCONNECT))
return false;
- return false; /* To be enabled when kernel is ready */
+ return true;
}
int tdx_guest_keyid_alloc(void);
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index d661de8230cf..9e87484283b8 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -1043,7 +1043,7 @@ struct tdmr_info_pa_array {
};
/* List all kernel-supported add-on features0 bits here */
-#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0)
+#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (TDX_FEATURES0_TDXCONNECT)
static __init u64 get_tdx_usable_addon_features0(void)
{
--
2.52.0
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O
2026-11-16 11:10 [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Chao Gao
` (6 preceding siblings ...)
2026-11-16 11:10 ` [RFC PATCH 7/7] x86/virt/tdx: Enable PCIe link encryption Chao Gao
@ 2026-11-21 1:35 ` Edgecombe, Rick P
2026-11-30 11:11 ` Chao Gao
7 siblings, 1 reply; 29+ messages in thread
From: Edgecombe, Rick P @ 2026-11-21 1:35 UTC (permalink / raw)
To: kvm, linux-coco, linux-kernel, Gao, Chao, x86, linux-pci
Cc: Xu, Yilun, dave.hansen, baolu.lu, Peng, Chao P, bp, kas, mingo,
hpa, tglx, Tian, Kevin, bhelgaas
On Mon, 2026-11-16 at 03:10 -0800, Chao Gao wrote:
> == Points for discussion ==
>
> 1. Raw DOE frames (See patch 3)
>
> The TDX module produces and consumes whole DOE objects, header included,
> but the PCI DOE API takes payloads only. The TDX-TSM driver therefore
> strips and rebuilds the DOE header itself. The code is small, but it
> puts DOE format details in a TSM driver, while the DOE core already
> handles them. A PCI DOE API that takes whole objects would keep them in
> the core, but the TDX-TSM driver would be its only user. Is such an API
> worth adding, or can we live with the DOE format handling in the
> TDX-TSM driver?
Why can't the TDX module return what we need? I guess AMD's firmware must
already return just the payload. Any idea what ARM will do?
>
> 2. Default IDE Stream (See patch 5)
>
> TDISP requires each device to have one default IDE stream [8]. The PCI
> core does not set Default Stream, so each TSM driver sets it itself, by
> looking up the device's IDE settings with pci_ide_to_settings() and
> setting default_stream. AMD's driver already does this, and the TDX-TSM
> driver does the same. Since the requirement is shared, the PCI core
> could instead set Default Stream on the device's TC0 stream, which is
> what TDISP expects. Should this move into the PCI core now, or can it be
> a later cleanup?
Not very sure on this point. Do you think the TSM drivers would never want to
pick a different default stream? If they did is there a point to moving it?
Might be better to wait to see how it shakes out.
>
> == Limitations ==
>
> The TDX module configures the root port's IDE settings and accepts
> only one address range for the stream. The root port therefore encrypts
> only traffic to the device's prefetchable MMIO range, and a device with
> no prefetchable range cannot be connected. We are evaluating whether
> this can be lifted.
Can you describe how it impacts the initial support here? Is it about enabling
more devices, or simplifying the initial code?
>
> Link encryption needs the root complex to enter a TDX mode, in which
> only the TDX module can configure the root port's IDE settings. The
> kernel opts in to this mode with TDH.IOMMU.SETUP. As its name suggests,
> this SEAMCALL also puts the IOMMU into TDX mode, which changes the
> IOMMU's behavior. Unfortunately, the two cannot be enabled separately,
> even though link encryption does not need IOMMU TDX mode.
Hmm, usually TDX is not easy to enable on a system. So users are not likely to
accidentally hit the existing limitations. So I'm thinking we just do the same
here. Document the limits and not add a switch. But the limits should be cleanly
handled and understood. Which is a WIP.
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O
2026-11-21 1:35 ` [RFC PATCH 0/7] TDX: Enable PCIe link encryption for trusted I/O Edgecombe, Rick P
@ 2026-11-30 11:11 ` Chao Gao
0 siblings, 0 replies; 29+ messages in thread
From: Chao Gao @ 2026-11-30 11:11 UTC (permalink / raw)
To: Edgecombe, Rick P
Cc: kvm, linux-coco, linux-kernel, x86, linux-pci, Xu, Yilun,
dave.hansen, baolu.lu, Peng, Chao P, bp, kas, mingo, hpa, tglx,
Tian, Kevin, bhelgaas
On Sat, Nov 21, 2026 at 09:35:10AM +0800, Edgecombe, Rick P wrote:
>On Mon, 2026-11-16 at 03:10 -0800, Chao Gao wrote:
>> 1. Raw DOE frames (See patch 3)
>>
>> The TDX module produces and consumes whole DOE objects, header included,
>> but the PCI DOE API takes payloads only. The TDX-TSM driver therefore
>> strips and rebuilds the DOE header itself. The code is small, but it
>> puts DOE format details in a TSM driver, while the DOE core already
>> handles them. A PCI DOE API that takes whole objects would keep them in
>> the core, but the TDX-TSM driver would be its only user. Is such an API
>> worth adding, or can we live with the DOE format handling in the
>> TDX-TSM driver?
>
>Why can't the TDX module return what we need? I guess AMD's firmware must
>already return just the payload. Any idea what ARM will do?
The kernel needs the type and the length of a DOE payload to send it
to the device, and each vendor passes them in its own way. AMD's
firmware puts a header of its own in front of the payload, which its
driver parses and strips before calling pci_doe(). Arm's firmware
returns them as two separate fields [1]. The TDX module uses the DOE
header.
The TDX module could do the same as Arm's firmware, which is likely
the easiest for the kernel. The kernel would get the type and the
length and pass them straight to pci_doe(). I am just not sure that
the code it saves is worth an ABI change.
>> 2. Default IDE Stream (See patch 5)
>>
>> TDISP requires each device to have one default IDE stream [8]. The PCI
>> core does not set Default Stream, so each TSM driver sets it itself, by
>> looking up the device's IDE settings with pci_ide_to_settings() and
>> setting default_stream. AMD's driver already does this, and the TDX-TSM
>> driver does the same. Since the requirement is shared, the PCI core
>> could instead set Default Stream on the device's TC0 stream, which is
>> what TDISP expects. Should this move into the PCI core now, or can it be
>> a later cleanup?
>
>Not very sure on this point. Do you think the TSM drivers would never want to
>pick a different default stream? If they did is there a point to moving it?
>Might be better to wait to see how it shakes out.
There is not much for a TSM driver to pick. TDISP wants exactly one
default stream, and it has to be the stream for TC0 (traffic class 0).
The PCIe spec (r7.0, sec 11.3.8, LOCK_INTERFACE_REQUEST) says the
device must fail the request if:
- The default Stream does not match the Stream_ID indicated
- Multiple IDE configuration registers in the device have been
configured as the default stream
- The default Stream is associated with a TC other than TC0
No TSM driver sets up more than one stream for a device today, so that
stream is always the default one.
What bothers me is that the reason is not obvious from the code, and
each driver explains it differently. AMD's driver has no comment on
it, and the Arm patches [2] and an earlier version of the TDX patches
[3] describe it as a quirk of some test devices.
If the PCI core cannot set the default stream for TSM drivers, a
helper in drivers/pci/tsm.c that marks a given stream as the default
would also do. The TSM driver still picks the stream, and the
explanation lives in one place.
>> The TDX module configures the root port's IDE settings and accepts
>> only one address range for the stream. The root port therefore encrypts
>> only traffic to the device's prefetchable MMIO range, and a device with
>> no prefetchable range cannot be connected. We are evaluating whether
>> this can be lifted.
>
>Can you describe how it impacts the initial support here? Is it about enabling
>more devices, or simplifying the initial code?
Simplifying the code. The TDX-TSM driver has to take the address
ranges that the PCI core prepared and drop all but one before passing
them to the TDX module. If the limit is lifted, that trimming and the
explanation it needs go away.
>> Link encryption needs the root complex to enter a TDX mode, in which
>> only the TDX module can configure the root port's IDE settings. The
>> kernel opts in to this mode with TDH.IOMMU.SETUP. As its name suggests,
>> this SEAMCALL also puts the IOMMU into TDX mode, which changes the
>> IOMMU's behavior. Unfortunately, the two cannot be enabled separately,
>> even though link encryption does not need IOMMU TDX mode.
>
>Hmm, usually TDX is not easy to enable on a system. So users are not likely to
>accidentally hit the existing limitations. So I'm thinking we just do the same
>here. Document the limits and not add a switch. But the limits should be cleanly
>handled and understood. Which is a WIP.
Agreed.
[1]: https://lore.kernel.org/all/20260910140509.868402-4-aneesh.kumar@kernel.org/
[2]: https://lore.kernel.org/all/20260910140509.868402-2-aneesh.kumar@kernel.org/
[3]: https://lore.kernel.org/all/20260327160132.2946114-31-yilun.xu@linux.intel.com/
^ permalink raw reply [flat|nested] 29+ messages in thread