[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250529053513.1592088-31-yilun.xu@linux.intel.com>
Date: Thu, 29 May 2025 13:35:13 +0800
From: Xu Yilun <yilun.xu@...ux.intel.com>
To: kvm@...r.kernel.org,
sumit.semwal@...aro.org,
christian.koenig@....com,
pbonzini@...hat.com,
seanjc@...gle.com,
alex.williamson@...hat.com,
jgg@...dia.com,
dan.j.williams@...el.com,
aik@....com,
linux-coco@...ts.linux.dev
Cc: dri-devel@...ts.freedesktop.org,
linux-media@...r.kernel.org,
linaro-mm-sig@...ts.linaro.org,
vivek.kasireddy@...el.com,
yilun.xu@...el.com,
yilun.xu@...ux.intel.com,
linux-kernel@...r.kernel.org,
lukas@...ner.de,
yan.y.zhao@...el.com,
daniel.vetter@...ll.ch,
leon@...nel.org,
baolu.lu@...ux.intel.com,
zhenzhong.duan@...el.com,
tao1.su@...el.com,
linux-pci@...r.kernel.org,
zhiw@...dia.com,
simona.vetter@...ll.ch,
shameerali.kolothum.thodi@...wei.com,
aneesh.kumar@...nel.org,
iommu@...ts.linux.dev,
kevin.tian@...el.com
Subject: [RFC PATCH 30/30] coco/tdx_tsm: Manage TDX Module enforced operation sequences for Unbind
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@...ux.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
Powered by blists - more mailing lists