Dan Williams <dan.j.williams@xxxxxxxxx> writes: ... > +/** > + * pci_tsm_bind() - Bind @pdev as a TDI for @kvm > + * @pdev: PCI device function to bind > + * @kvm: Private memory attach context > + * @tdi_id: Identifier (virtual BDF) for the TDI as referenced by the TSM and DSM > + * > + * Returns 0 on success, or a negative error code on failure. > + * > + * Context: Caller is responsible for constraining the bind lifetime to the > + * registered state of the device. For example, pci_tsm_bind() / > + * pci_tsm_unbind() limited to the VFIO driver bound state of the device. > + */ > +int pci_tsm_bind(struct pci_dev *pdev, struct kvm *kvm, u32 tdi_id) > +{ > + const struct pci_tsm_ops *ops; > + struct pci_tsm_pf0 *tsm_pf0; > + struct pci_tdi *tdi; > + > + if (!kvm) > + return -EINVAL; > + > + guard(rwsem_read)(&pci_tsm_rwsem); > + > + if (!pdev->tsm) > + return -EINVAL; > + > + ops = pdev->tsm->ops; > + > + if (!is_link_tsm(ops->owner)) > + return -ENXIO; > + > + tsm_pf0 = to_pci_tsm_pf0(pdev->tsm); > + guard(mutex)(&tsm_pf0->lock); > + > + /* Resolve races to bind a TDI */ > + if (pdev->tsm->tdi) { > + if (pdev->tsm->tdi->kvm == kvm) > + return 0; > + else > + return -EBUSY; > + } > + > + tdi = ops->bind(pdev, kvm, tdi_id); > + if (IS_ERR(tdi)) > + return PTR_ERR(tdi); > + > + pdev->tsm->tdi = tdi; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(pci_tsm_bind); > + Are we missing assigning pdev and kvm in the above function? modified drivers/pci/tsm.c @@ -356,6 +356,8 @@ int pci_tsm_bind(struct pci_dev *pdev, struct kvm *kvm, u32 tdi_id) if (IS_ERR(tdi)) return PTR_ERR(tdi); + tdi->pdev = pdev; + tdi->kvm = kvm; pdev->tsm->tdi = tdi; return 0; -aneesh