Dan Williams wrote: > Aneesh Kumar K.V wrote: > > Dan Williams <dan.j.williams@xxxxxxxxx> writes: > > > > > From: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx> > > ... > > > > > @@ -558,11 +675,11 @@ int pci_tsm_bind(struct pci_dev *pdev, struct kvm *kvm, u64 tdi_id) > > > if (!pdev->tsm) > > > return -EINVAL; > > > > > > - struct pci_dev *pf0_dev __free(pci_dev_put) = tsm_pf0_get(pdev); > > > - if (!pf0_dev) > > > + struct pci_dev *dsm_dev __free(pci_dev_put) = dsm_dev_get(pdev); > > > + if (!dsm_dev) > > > return -EINVAL; > > > > > > - struct mutex *ops_lock __free(tdi_ops_unlock) = tdi_ops_lock(pf0_dev); > > > + struct mutex *ops_lock __free(tdi_ops_unlock) = tdi_ops_lock(dsm_dev); > > > if (IS_ERR(ops_lock)) > > > return PTR_ERR(ops_lock); > > > > > > @@ -573,10 +690,13 @@ int pci_tsm_bind(struct pci_dev *pdev, struct kvm *kvm, u64 tdi_id) > > > return -EBUSY; > > > } > > > > > > - tdi = tsm_ops->bind(pdev, pf0_dev, kvm, tdi_id); > > > + tdi = tsm_ops->bind(pdev, dsm_dev, kvm, tdi_id); > > > if (!tdi) > > > return -ENXIO; > > > > > > + tdi->pdev = pdev; > > > + tdi->dsm_dev = dsm_dev; > > > + tdi->kvm = kvm; > > > pdev->tsm->tdi = tdi; > > > > > > > should that be no_free_ptr(dsm_dev)? Also unbind needs to drop that > > device reference? > > Hmmm, are there any scenarios where @tdi can outlive @dsm_dev? > > The end of life of @dsm_dev includes pci_tsm_destroy() which should > invalidate all outstanding @tdi contexts. So with the move to add @dsm to 'struct pci_tsm' this mess goes away. That said, it should indeed always be the case that a registered PCI device always pins its Device Security Manager. In other words there are no scenarios where the registered lifetime of a PCI device can outlive the DSM because the DSM is always an ancestor.