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 6/7] coco/tdx-host: Program IDE keys and enable the IDE stream
Date: Mon, 16 Nov 2026 03:10:24 -0800	[thread overview]
Message-ID: <20261116111037.3478844-7-chao.gao@intel.com> (raw)
In-Reply-To: <20261116111037.3478844-1-chao.gao@intel.com>

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


  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 ` [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 ` Chao Gao [this message]
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-7-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®