@@ -255,8 +255,16 @@ static void iommufd_vdevice_disable_trusted_dma(struct iommufd_vdevice *vdev)
vdev->trusted_dma_enabled = false;
}
+static void pci_driver_disable_trusted_dma(struct pci_dev *pdev)
+{
+ struct iommufd_vdevice *vdev = pdev->trusted_dma_owner;
+
+ iommufd_vdevice_disable_trusted_dma(vdev);
+}
+
int iommufd_vdevice_tsm_bind(struct iommufd_vdevice *vdev)
{
+ struct pci_dev *pdev = to_pci_dev(vdev->dev);
struct kvm *kvm;
int rc;
@@ -272,6 +280,9 @@ int iommufd_vdevice_tsm_bind(struct iommufd_vdevice *vdev)
goto out_unlock;
}
+ pdev->trusted_dma_owner = vdev;
+ pdev->driver->tsm_handler->disable_trusted_dma = pci_driver_disable_trusted_dma;
+
rc = iommufd_vdevice_enable_trusted_dma(vdev);
if (rc)
goto out_unlock;
@@ -292,12 +303,16 @@ int iommufd_vdevice_tsm_bind(struct iommufd_vdevice *vdev)
void iommufd_vdevice_tsm_unbind(struct iommufd_vdevice *vdev)
{
+ struct pci_dev *pdev = to_pci_dev(vdev->dev);
+
mutex_lock(&vdev->tsm_lock);
if (!vdev->tsm_bound)
goto out_unlock;
pci_tsm_unbind(to_pci_dev(vdev->dev));
iommufd_vdevice_disable_trusted_dma(vdev);
+ pdev->trusted_dma_owner = NULL;
+ pdev->driver->tsm_handler->disable_trusted_dma = NULL;
vdev->tsm_bound = false;
out_unlock:
IOMMUFD implements disable_trusted_dma() handler to clean up trusted DMA configuration when device is to be unbound. For now these handlers are mainly for Intel TDX Connect, but should have no impact since other platform TSM drivers don't call these handlers. Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com> --- drivers/iommu/iommufd/viommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)