mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Gao <chao.gao@intel.com>
To: x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org,
	linux-kernel@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,
	Kiryl Shutsemau <kas@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: [RFC PATCH 3/7] coco/tdx-host: Exchange SPDM messages through DOE
Date: Mon, 16 Nov 2026 03:10:21 -0800	[thread overview]
Message-ID: <20261116111037.3478844-4-chao.gao@intel.com> (raw)
In-Reply-To: <20261116111037.3478844-1-chao.gao@intel.com>

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


  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 ` Chao Gao [this message]
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 ` [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-4-chao.gao@intel.com \
    --to=chao.gao@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chao.p.peng@intel.com \
    --cc=dave.hansen@linux.intel.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=rick.p.edgecombe@intel.com \
    --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®