mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Gao <chao.gao@intel.com>
To: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev,
	kvm@vger.kernel.org
Cc: rick.p.edgecombe@intel.com, kevin.tian@intel.com,
	yilun.xu@intel.com, chao.p.peng@intel.com,
	baolu.lu@linux.intel.com, chao.gao@intel.com,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Kiryl Shutsemau <kas@kernel.org>
Subject: [RFC PATCH 4/7] coco/tdx-host: Pass a device info buffer to tdh_spdm_connect()
Date: Mon, 16 Nov 2026 03:10:22 -0800	[thread overview]
Message-ID: <20261116111037.3478844-5-chao.gao@intel.com> (raw)
In-Reply-To: <20261116111037.3478844-1-chao.gao@intel.com>

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


  parent reply	other threads:[~2026-11-16 11:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE Chao Gao
2026-11-16 11:10 ` Chao Gao [this message]
2026-11-16 11:10 ` [RFC PATCH 5/7] coco/tdx-host: Configure an IDE stream Chao Gao
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 ` [RFC PATCH 7/7] x86/virt/tdx: Enable PCIe link encryption Chao Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116111037.3478844-5-chao.gao@intel.com \
    --to=chao.gao@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=chao.p.peng@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kas@kernel.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --cc=yilun.xu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®