[RFC PATCH 30/30] coco/tdx_tsm: Manage TDX Module enforced operation sequences for Unbind
Xu Yilun
yilun.xu at linux.intel.com
Thu May 29 05:35:13 UTC 2025
Implement TDX Connect enforced sequences for TSM unbind. The enforced
sequences are:
1. STOP TDI via TDISP message STOP_INTERFACE
2. Private MMIO unmap from Secure EPT
3. Trusted Device Context Table cleanup for the TDI
4. TDI ownership reclaim and metadata free
Step 2 is the responsibility of KVM, step 3 is for IOMMU driver. So
TDX TSM driver needs to invoke TSM handlers for external collaboration.
Signed-off-by: Xu Yilun <yilun.xu at linux.intel.com>
---
drivers/virt/coco/host/tdx_tsm.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/virt/coco/host/tdx_tsm.c b/drivers/virt/coco/host/tdx_tsm.c
index beb65f45b478..66d6019812ca 100644
--- a/drivers/virt/coco/host/tdx_tsm.c
+++ b/drivers/virt/coco/host/tdx_tsm.c
@@ -87,6 +87,15 @@ static struct pci_tdi *tdx_tsm_bind(struct pci_dev *pdev,
{
int ret;
+ if (!pdev->trusted_dma_owner ||
+ !pdev->driver->tsm_handler ||
+ !pdev->driver->tsm_handler->disable_mmio ||
+ !pdev->driver->tsm_handler->recover_mmio ||
+ !pdev->driver->tsm_handler->disable_trusted_dma) {
+ pci_err(pdev, "%s no driver or driver not support bind\n", __func__);
+ return NULL;
+ }
+
struct tdx_tdi *ttdi __free(kfree) =
kzalloc(sizeof(*ttdi), GFP_KERNEL);
if (!ttdi)
@@ -137,15 +146,15 @@ static struct pci_tdi *tdx_tsm_bind(struct pci_dev *pdev,
static void tdx_tsm_unbind(struct pci_tdi *tdi)
{
struct tdx_tdi *ttdi = to_tdx_tdi(tdi);
+ struct pci_dev *pdev = tdi->pdev;
- /*
- * TODO: In fact devif cannot be freed before TDI's private MMIOs and
- * private DMA are unmapped. Will handle this restriction later.
- */
tdx_tdi_request(ttdi, TDX_TDI_REQ_STOP);
+ pdev->driver->tsm_handler->disable_mmio(pdev);
+ pdev->driver->tsm_handler->disable_trusted_dma(pdev);
tdx_tdi_mmiomt_free(ttdi);
tdx_tdi_devif_free(ttdi);
tdx_tdi_devifmt_free(ttdi);
+ pdev->driver->tsm_handler->recover_mmio(pdev);
pci_dev_put(ttdi->tdi.dsm_dev);
kfree(ttdi);
}
--
2.25.1
More information about the dri-devel
mailing list